// 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 );
}
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 :
}
//================================================================
-// 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();
}
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 :
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();
}
{
if( myIsTransformationPointPreview )
{
- if( myTransformationPointMode != None )
+ if( myTransformationPointType != None )
theCursor = *getTransformationPointCursor();
}
else
{
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;
}
void HYDROGUI_PrsImage::unselect()
{
HYDROGUI_Prs::unselect();
- myPrsImageFrame->updateVisibility();
+ if( !myIsTransformationPointPreview )
+ myPrsImageFrame->updateVisibility();
}
//================================================================
void HYDROGUI_PrsImage::setSelected( bool theState )
{
HYDROGUI_Prs::setSelected( theState );
- myPrsImageFrame->updateVisibility();
+ if( !myIsTransformationPointPreview )
+ myPrsImageFrame->updateVisibility();
}
//================================================================
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;
}
}
- 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 );
}
}