#include <GraphicsView_ViewPort.h>
#include <QCursor>
+#include <QApplication>
//=======================================================================
// 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 )
+ myIsByTwoPoints( true ),
+ myTransformationPointType( None )
{
- myHighlightCursor = new QCursor( Qt::PointingHandCursor );
myTransformationPointCursor = new QCursor( Qt::CrossCursor );
}
//=======================================================================
HYDROGUI_PrsImage::~HYDROGUI_PrsImage()
{
- if( myHighlightCursor )
- {
- delete myHighlightCursor;
- myHighlightCursor = 0;
- }
-
if( myTransformationPointCursor )
{
delete myTransformationPointCursor;
// Function : setImage
// Purpose :
//================================================================
-void HYDROGUI_PrsImage::setImage( const QImage& theImage )
+void HYDROGUI_PrsImage::setImage( const QImage& theImage, const bool theCompute )
{
myImage = theImage;
+ if ( theCompute ) {
+ compute();
+ computeTransformationPoints( true );
+ }
}
//================================================================
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();
}
//================================================================
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<HYDROGUI_PrsImage*>( anIter.next() ) )
- {
- double aZValueRef = aPrs->zValue();
- aZValue = qMax( aZValue, aZValueRef );
- }
- }
- setZValue( aZValue + 1 );
}
//================================================================
//================================================================
void HYDROGUI_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort )
{
- GraphicsView_Object::removeFrom( theViewPort );
+ HYDROGUI_Prs::removeFrom( theViewPort );
theViewPort->removeItem( myPrsImageFrame );
}
{
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;
}
- bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect );
+ bool anIsSelected = HYDROGUI_Prs::select( theX, theY, theRect );
myPrsImageFrame->updateVisibility();
return anIsSelected;
}
//================================================================
void HYDROGUI_PrsImage::unselect()
{
- GraphicsView_Object::unselect();
- myPrsImageFrame->updateVisibility();
+ HYDROGUI_Prs::unselect();
+ if( !myIsTransformationPointPreview )
+ myPrsImageFrame->updateVisibility();
}
//================================================================
//================================================================
void HYDROGUI_PrsImage::setSelected( bool theState )
{
- GraphicsView_Object::setSelected( theState );
- myPrsImageFrame->updateVisibility();
+ HYDROGUI_Prs::setSelected( theState );
+ if( !myIsTransformationPointPreview )
+ myPrsImageFrame->updateVisibility();
}
//================================================================
// Function : computeTransformationPoints
// Purpose :
//================================================================
-void HYDROGUI_PrsImage::computeTransformationPoints()
+void HYDROGUI_PrsImage::computeTransformationPoints( const bool theObligatoryInit )
{
- if( myTransformationPointMap.isEmpty() )
{
- int aWidth = myImage.width();
- int aHeight = myImage.height();
-
for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
{
- TransformationPoint aTransformationPoint;
-
- QPoint aPoint;
- QString aCaption;
- QColor aColor = Qt::black;
- switch( aPointType )
- {
- case PointA:
- aPoint = QPoint( 0, 0 );
- aCaption = "A";
- aColor = Qt::darkRed;
- break;
- case PointB:
- aPoint = QPoint( aWidth, 0 );
- aCaption = "B";
- aColor = Qt::darkGreen;
- break;
- case PointC:
- aPoint = QPoint( 0, aHeight );
- aCaption = "C";
- aColor = Qt::darkBlue;
- break;
- }
-
- aTransformationPoint.Point = aPoint;
- aTransformationPoint.Caption = aCaption;
-
- aTransformationPoint.PointItem = new QGraphicsEllipseItem( this );
- aTransformationPoint.PointItem->setVisible( false );
- aTransformationPoint.PointItem->setPen( QPen( aColor ) );
- aTransformationPoint.PointItem->setBrush( QBrush( aColor ) );
-
- aTransformationPoint.CaptionItem = new QGraphicsSimpleTextItem( aCaption, this );
- aTransformationPoint.CaptionItem->setVisible( false );
- aTransformationPoint.CaptionItem->setPen( QPen( aColor ) );
- aTransformationPoint.CaptionItem->setBrush( QBrush( aColor ) );
-
- myTransformationPointMap[ aPointType ] = aTransformationPoint;
+ if( myTransformationPointMap.isEmpty() || theObligatoryInit )
+ initTrsfPoints( aPointType );
+ // Show/hide the point if necessary
+ updateTrsfPoint( aPointType );
+
}
}
+}
+
+QGraphicsItemGroup* HYDROGUI_PrsImage::createPointItem( const QString& theCaption,
+ const QColor& theColor )
+{
+ QGraphicsEllipseItem* aPointItem = new QGraphicsEllipseItem( this );
+ aPointItem->setPen( QPen( theColor ) );
+ aPointItem->setBrush( QBrush( theColor ) );
+
+ double aRadius = 3;
+ QRectF aRect( -QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
+ aPointItem->setRect( aRect );
+ aPointItem->setPos( QPointF( 0, 0 ) );
+
+ QGraphicsSimpleTextItem* aCaptionItem = aCaptionItem = new QGraphicsSimpleTextItem( theCaption, this );
+ aCaptionItem->setPen( QPen( theColor ) );
+ aCaptionItem->setBrush( QBrush( theColor ) );
+ QFont aFont = aCaptionItem->font();
+ aFont.setPointSize( qApp->font().pointSize() );
+ aCaptionItem->setFont( aFont );
+ aCaptionItem->setPos( QPointF( -aRadius * 2, aRadius * 2 ) );
+
+ QGraphicsItemGroup* aGroupItem = new QGraphicsItemGroup( this );
+ aGroupItem->addToGroup( aPointItem );
+ aGroupItem->addToGroup( aCaptionItem );
+ aGroupItem->setVisible( false );
+ aGroupItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
+
+ return aGroupItem;
+}
- bool anIsVisible = myIsTransformationPointPreview;
- for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
+//================================================================
+// Function : initTrsfPoints
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::initTrsfPoints( const int thePointType )
+{
+ QPoint aPoint;
+ QString aCaption;
+ QColor aColor = Qt::black;
+
+ int aWidth = myImage.width();
+ int aHeight = myImage.height();
+ switch( thePointType )
{
- TransformationPoint& aTransformationPoint = myTransformationPointMap[ aPointType ];
+ case PointA:
+ aPoint = QPoint( 0, 0 );
+ aCaption = "A";
+ aColor = Qt::darkRed;
+ break;
+ case PointB:
+ aPoint = QPoint( aWidth, 0 );
+ aCaption = "B";
+ aColor = Qt::darkGreen;
+ break;
+ case PointC:
+ aPoint = QPoint( 0, aHeight );
+ aCaption = "C";
+ aColor = Qt::darkBlue;
+ break;
+ }
+
+ TransformationPoint aTransformationPoint;
+ if ( myTransformationPointMap.contains( thePointType ) )
+ aTransformationPoint = myTransformationPointMap[thePointType];
+
+ aTransformationPoint.Point = aPoint;
+ aTransformationPoint.Caption = aCaption;
+ if ( !aTransformationPoint.GroupItem )
+ aTransformationPoint.GroupItem = createPointItem( aCaption, aColor );
+ aTransformationPoint.GroupItem->setPos( aPoint );
+
+ myTransformationPointMap[ thePointType ] = aTransformationPoint;
+}
+
+//================================================================
+// 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( anIsVisible );
+ const QPointF& aPoint = aTransformationPoint.Point;
+ aTransformationPoint.GroupItem->setPos( aPoint );
+ aTransformationPoint.GroupItem->setVisible( anIsPointVisible );
+}
- QPointF aCaptionShift( -aRadius * 2, aRadius * 2 );
- aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift );
- aTransformationPoint.CaptionItem->setVisible( anIsVisible );
+//================================================================
+// Function : getIsByTwoPoints
+// Purpose :
+//================================================================
+bool HYDROGUI_PrsImage::getIsByTwoPoints() const
+{
+ return myIsByTwoPoints;
+}
+
+//================================================================
+// 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 );
}
}