X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_PrsImage.cxx;h=172f5f72b41b7b4a2edb7eac4b3f10631d03cef4;hb=de7cf9bb0a7a41d6487013c87f4a54d0664cd303;hp=fa75c25eb15109310cd352268622361bad9d132e;hpb=d74afc6389ed4e656c9451ac01b4065470746fd8;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index fa75c25e..172f5f72 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -32,14 +32,14 @@ // name : HYDROGUI_PrsImage // Purpose : Constructor //======================================================================= -HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject ) +HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject ) : HYDROGUI_Prs( theObject ), myPixmapItem( 0 ), + myCaptionItem( 0 ), myPrsImageFrame( 0 ), myIsTransformationPointPreview( false ), - myTransformationPointMode( None ) + myTransformationPointType( None ) { - myHighlightCursor = new QCursor( Qt::PointingHandCursor ); myTransformationPointCursor = new QCursor( Qt::CrossCursor ); } @@ -49,12 +49,6 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject //======================================================================= HYDROGUI_PrsImage::~HYDROGUI_PrsImage() { - if( myHighlightCursor ) - { - delete myHighlightCursor; - myHighlightCursor = 0; - } - if( myTransformationPointCursor ) { delete myTransformationPointCursor; @@ -80,6 +74,30 @@ QImage HYDROGUI_PrsImage::getImage() const return myImage; } +//================================================================ +// Function : setCaption +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::setCaption( const QString& theCaption ) +{ + if( myCaptionItem ) + { + myCaptionItem->setText( theCaption ); + myCaptionItem->setVisible( !theCaption.isEmpty() ); + } +} + +//================================================================ +// Function : getCaption +// Purpose : +//================================================================ +QString HYDROGUI_PrsImage::getCaption() const +{ + if( myCaptionItem ) + return myCaptionItem->text(); + return QString(); +} + //================================================================ // Function : setIsTransformationPointPreview // Purpose : @@ -99,16 +117,44 @@ bool HYDROGUI_PrsImage::getIsTransformationPointPreview() const } //================================================================ -// Function : setTransformationPointMode +// Function : setTransformationPointType // Purpose : //================================================================ -void HYDROGUI_PrsImage::setTransformationPointMode( const int theMode ) +void HYDROGUI_PrsImage::setTransformationPointType( const int thePointType ) { - myTransformationPointMode = theMode; - if( theMode != None ) + myTransformationPointType = thePointType; + if( thePointType != None ) computeTransformationPoints(); } +//================================================================ +// Function : setTransformationPointMap +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::setTransformationPointMap( const TransformationPointMap& theMap ) +{ + myTransformationPointMap = theMap; + if( !theMap.isEmpty() ) + computeTransformationPoints(); +} + +//================================================================ +// Function : updateTransformationPoint +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::updateTransformationPoint( const int thePointType, + const bool theIsY, + const int theValue ) +{ + if( myTransformationPointMap.find( thePointType ) != myTransformationPointMap.end() ) + { + TransformationPoint& aTransformationPoint = myTransformationPointMap[ thePointType ]; + QPoint& aPoint = aTransformationPoint.Point; + theIsY ? aPoint.setY( theValue ) : aPoint.setX( theValue ); + computeTransformationPoints(); + } +} + //================================================================ // Function : boundingRect // Purpose : @@ -129,12 +175,27 @@ void HYDROGUI_PrsImage::compute() myPixmapItem = new QGraphicsPixmapItem( this ); addToGroup( myPixmapItem ); } + if( !myCaptionItem ) + { + myCaptionItem = new QGraphicsSimpleTextItem( this ); + + QFont aFont = myCaptionItem->font(); + aFont.setPointSize( 14 ); + myCaptionItem->setFont( aFont ); + + addToGroup( myCaptionItem ); + } if( !myPrsImageFrame ) { myPrsImageFrame = new HYDROGUI_PrsImageFrame( this ); addToGroup( myPrsImageFrame ); } + myPixmapItem->setPixmap( QPixmap::fromImage( myImage ) ); + + myCaptionItem->setPos( 0, -30 ); + myCaptionItem->setVisible( false ); + myPrsImageFrame->compute(); } @@ -144,20 +205,8 @@ void HYDROGUI_PrsImage::compute() //================================================================ void HYDROGUI_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) { - GraphicsView_Object::addTo( theViewPort ); + HYDROGUI_Prs::addTo( theViewPort ); theViewPort->addItem( myPrsImageFrame ); - - double aZValue = 0; - GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() ); - while( anIter.hasNext() ) - { - if( HYDROGUI_PrsImage* aPrs = dynamic_cast( anIter.next() ) ) - { - double aZValueRef = aPrs->zValue(); - aZValue = qMax( aZValue, aZValueRef ); - } - } - setZValue( aZValue + 1 ); } //================================================================ @@ -166,7 +215,7 @@ void HYDROGUI_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) //================================================================ void HYDROGUI_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort ) { - GraphicsView_Object::removeFrom( theViewPort ); + HYDROGUI_Prs::removeFrom( theViewPort ); theViewPort->removeItem( myPrsImageFrame ); } @@ -182,7 +231,7 @@ bool HYDROGUI_PrsImage::checkHighlight( double theX, double theY, QCursor& theCu { if( myIsTransformationPointPreview ) { - if( myTransformationPointMode != None ) + if( myTransformationPointType != None ) theCursor = *getTransformationPointCursor(); } else @@ -200,16 +249,18 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect { if( myIsTransformationPointPreview ) { - if( myTransformationPointMode == None || !theRect.isEmpty() ) + if( myTransformationPointType == None || !theRect.isEmpty() ) return false; - TransformationPoint& aTransformationPoint = myTransformationPointMap[ myTransformationPointMode ]; - aTransformationPoint.Point = QPoint( (int)theX, (int)theY ); + QPoint aPos = pos().toPoint(); + + TransformationPoint& aTransformationPoint = myTransformationPointMap[ myTransformationPointType ]; + aTransformationPoint.Point = QPoint( (int)theX, (int)theY ) - aPos; computeTransformationPoints(); return true; } - bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect ); + bool anIsSelected = HYDROGUI_Prs::select( theX, theY, theRect ); myPrsImageFrame->updateVisibility(); return anIsSelected; } @@ -220,8 +271,9 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect //================================================================ void HYDROGUI_PrsImage::unselect() { - GraphicsView_Object::unselect(); - myPrsImageFrame->updateVisibility(); + HYDROGUI_Prs::unselect(); + if( !myIsTransformationPointPreview ) + myPrsImageFrame->updateVisibility(); } //================================================================ @@ -230,8 +282,9 @@ void HYDROGUI_PrsImage::unselect() //================================================================ void HYDROGUI_PrsImage::setSelected( bool theState ) { - GraphicsView_Object::setSelected( theState ); - myPrsImageFrame->updateVisibility(); + HYDROGUI_Prs::setSelected( theState ); + if( !myIsTransformationPointPreview ) + myPrsImageFrame->updateVisibility(); } //================================================================ @@ -245,6 +298,7 @@ void HYDROGUI_PrsImage::computeTransformationPoints() int aWidth = myImage.width(); int aHeight = myImage.height(); + // Create presentations for transformation points A, B and C for( int aPointType = PointA; aPointType <= PointC; aPointType++ ) { TransformationPoint aTransformationPoint; @@ -288,19 +342,54 @@ void HYDROGUI_PrsImage::computeTransformationPoints() } } - bool anIsVisible = myIsTransformationPointPreview; for( int aPointType = PointA; aPointType <= PointC; aPointType++ ) { - TransformationPoint& aTransformationPoint = myTransformationPointMap[ aPointType ]; + // Show/hide the point if necessary + updateTrsfPoint( aPointType ); + } +} - double aRadius = 5; - const QPointF& aPoint = aTransformationPoint.Point; - QRectF aRect( aPoint - QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) ); - aTransformationPoint.PointItem->setRect( aRect ); - aTransformationPoint.PointItem->setVisible( anIsVisible ); +//================================================================ +// Function : updateTrsfPoint +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::updateTrsfPoint( const int thePointType ) +{ + // If image is transformed only by two points then the point C is invisible + bool anIsPointVisible = myIsTransformationPointPreview && ( + ( !myIsByTwoPoints ) || ( myIsByTwoPoints && ( thePointType != PointC ) ) ); + TransformationPoint& aTransformationPoint = myTransformationPointMap[ thePointType ]; + + double aRadius = 5; + const QPointF& aPoint = aTransformationPoint.Point; + QRectF aRect( aPoint - QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) ); + aTransformationPoint.PointItem->setRect( aRect ); + aTransformationPoint.PointItem->setVisible( anIsPointVisible ); + + QPointF aCaptionShift( -aRadius * 2, aRadius * 2 ); + aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift ); + aTransformationPoint.CaptionItem->setVisible( anIsPointVisible ); +} + +//================================================================ +// Function : getIsByTwoPoints +// Purpose : +//================================================================ +bool HYDROGUI_PrsImage::getIsByTwoPoints() const +{ + return myIsByTwoPoints; +} - QPointF aCaptionShift( -aRadius * 2, aRadius * 2 ); - aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift ); - aTransformationPoint.CaptionItem->setVisible( anIsVisible ); +//================================================================ +// Function : setIsByTwoPoints +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::setIsByTwoPoints( const bool theIsByTwoPoints ) +{ + myIsByTwoPoints = theIsByTwoPoints; + if ( myTransformationPointMap.contains( PointC ) ) + { + // Show/hide the point C if necessary + updateTrsfPoint( PointC ); } }