X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_PrsImage.cxx;h=985dc27d45a7f22a178519b96209eff757958d4a;hb=81c9f5cdf82909d0aebd2c491c50fa7516cc80b7;hp=fde013574161227fb50a732413aafa8f889ebd67;hpb=4d264a61b05e9124d2d7bd1d8b8c3f08df9311b2;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index fde01357..985dc27d 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -39,6 +39,7 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject myCaptionItem( 0 ), myPrsImageFrame( 0 ), myIsTransformationPointPreview( false ), + myIsByTwoPoints( true ), myTransformationPointType( None ) { myTransformationPointCursor = new QCursor( Qt::CrossCursor ); @@ -61,9 +62,13 @@ HYDROGUI_PrsImage::~HYDROGUI_PrsImage() // 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 ); + } } //================================================================ @@ -292,76 +297,91 @@ void HYDROGUI_PrsImage::setSelected( bool theState ) // 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(); - - // Create presentations for transformation points A, B and C 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; - - QGraphicsEllipseItem* aPointItem = new QGraphicsEllipseItem( this ); - aPointItem->setPen( QPen( aColor ) ); - aPointItem->setBrush( QBrush( aColor ) ); - - 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( aCaption, this ); - aCaptionItem->setPen( QPen( aColor ) ); - aCaptionItem->setBrush( QBrush( aColor ) ); - QFont aFont = aCaptionItem->font(); - aFont.setPointSize( qApp->font().pointSize() ); - aCaptionItem->setFont( aFont ); - aCaptionItem->setPos( QPointF( -aRadius * 2, aRadius * 2 ) ); - - aTransformationPoint.GroupItem = new QGraphicsItemGroup( this ); - aTransformationPoint.GroupItem->addToGroup( aPointItem ); - aTransformationPoint.GroupItem->addToGroup( aCaptionItem ); - aTransformationPoint.GroupItem->setVisible( false ); - aTransformationPoint.GroupItem->setFlag( QGraphicsItem::ItemIgnoresTransformations ); - aTransformationPoint.GroupItem->setPos( aPoint ); - - 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; +} + +//================================================================ +// Function : initTrsfPoints +// Purpose : +//================================================================ +void HYDROGUI_PrsImage::initTrsfPoints( const int thePointType ) +{ + QPoint aPoint; + QString aCaption; + QColor aColor = Qt::black; - for( int aPointType = PointA; aPointType <= PointC; aPointType++ ) + int aWidth = myImage.width(); + int aHeight = myImage.height(); + switch( thePointType ) { - // Show/hide the point if necessary - updateTrsfPoint( 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; } //================================================================