X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_PrsImage.cxx;h=250d4c859555c219b757dcf15fb2dc0a9fb3f511;hb=844c6abc897469c996e8df5a1569c3aeaa08c446;hp=4e8471e129b59eb97c172e05427742576a711f86;hpb=f8418d6cb7ab14ad2563bf2aa8fa70b4451c9173;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index 4e8471e1..250d4c85 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -32,12 +32,13 @@ // 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 ) { myTransformationPointCursor = new QCursor( Qt::CrossCursor ); } @@ -73,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 : @@ -92,13 +117,13 @@ 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(); } @@ -113,6 +138,23 @@ void HYDROGUI_PrsImage::setTransformationPointMap( const TransformationPointMap& 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 : @@ -133,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(); } @@ -174,7 +231,7 @@ bool HYDROGUI_PrsImage::checkHighlight( double theX, double theY, QCursor& theCu { if( myIsTransformationPointPreview ) { - if( myTransformationPointMode != None ) + if( myTransformationPointType != None ) theCursor = *getTransformationPointCursor(); } else @@ -192,11 +249,13 @@ 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; } @@ -213,7 +272,8 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect void HYDROGUI_PrsImage::unselect() { HYDROGUI_Prs::unselect(); - myPrsImageFrame->updateVisibility(); + if( !myIsTransformationPointPreview ) + myPrsImageFrame->updateVisibility(); } //================================================================ @@ -223,7 +283,8 @@ void HYDROGUI_PrsImage::unselect() void HYDROGUI_PrsImage::setSelected( bool theState ) { HYDROGUI_Prs::setSelected( theState ); - myPrsImageFrame->updateVisibility(); + if( !myIsTransformationPointPreview ) + myPrsImageFrame->updateVisibility(); } //================================================================ @@ -281,18 +342,46 @@ void HYDROGUI_PrsImage::computeTransformationPoints() } bool anIsVisible = myIsTransformationPointPreview; + bool anIsPointVisible; for( int aPointType = PointA; aPointType <= PointC; aPointType++ ) { + // If image is transformed only by two points then the point C is invisible + anIsPointVisible = anIsVisible && ( + ( !myIsByTwoPoints ) || ( myIsByTwoPoints && ( aPointType != PointC ) ) ); TransformationPoint& aTransformationPoint = myTransformationPointMap[ 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 ); + aTransformationPoint.PointItem->setVisible( anIsPointVisible ); QPointF aCaptionShift( -aRadius * 2, aRadius * 2 ); aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift ); - aTransformationPoint.CaptionItem->setVisible( anIsVisible ); + aTransformationPoint.CaptionItem->setVisible( anIsPointVisible ); + } +} + +//================================================================ +// Function : IsByTwoPoints +// Purpose : +//================================================================ +bool HYDROGUI_PrsImage::getIsByTwoPoints() const +{ + return myIsByTwoPoints; +} + +//================================================================ +// Function : SetIsByTwoPoints +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::setIsByTwoPoints( const bool theIsByTwoPoints ) +{ + myIsByTwoPoints = theIsByTwoPoints; + if ( myTransformationPointMap.contains( PointC ) ) + { + TransformationPoint& aTransformationPoint = myTransformationPointMap[ PointC ]; + aTransformationPoint.PointItem->setVisible( myIsTransformationPointPreview && theIsByTwoPoints ); + aTransformationPoint.CaptionItem->setVisible( myIsTransformationPointPreview && theIsByTwoPoints ); } }