From f71bdb61ff2c4e16bceea50671ebe354a160f63e Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 4 Jul 2013 07:39:34 +0000 Subject: [PATCH] Raw development for ImageViewer. --- src/GraphicsView/GraphicsView_Object.cxx | 43 ---- src/GraphicsView/GraphicsView_Object.h | 5 - src/GraphicsView/GraphicsView_PrsImage.cxx | 187 +++++++++--------- src/GraphicsView/GraphicsView_PrsImage.h | 17 +- .../GraphicsView_PrsImageFrame.cxx | 99 ++++++---- src/GraphicsView/GraphicsView_PrsImageFrame.h | 8 +- src/GraphicsView/GraphicsView_Scene.cxx | 15 +- src/GraphicsView/GraphicsView_ViewPort.cxx | 1 + src/GraphicsView/GraphicsView_Viewer.cxx | 33 ++-- src/GraphicsView/GraphicsView_Viewer.h | 2 +- 10 files changed, 190 insertions(+), 220 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index 9c91904df..9338b9373 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -183,46 +183,3 @@ void GraphicsView_Object::setViewTransform( const QTransform& theTransform ) { myViewTransform = theTransform; } - -//================================================================ -// Function : centerPoint -// Purpose : -//================================================================ -QPointF GraphicsView_Object::centerPoint() -{ - QRectF aRect = getRect(); - double aCenterX = aRect.width() / 2.; - double aCenterY = aRect.height() / 2.; - return QPointF( aCenterX, aCenterY ); -} - -//================================================================ -// Function : setRotationAroundCenter -// Purpose : -//================================================================ -void GraphicsView_Object::setRotationAroundCenter( QGraphicsItem* theItem, double theAngle ) -{ - if( !theItem ) - return; - - QRectF aRect = theItem->boundingRect(); - double aCenterX = aRect.width() / 2.; - double aCenterY = aRect.height() / 2.; - if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) - { - aCenterX = anObject->centerPoint().x(); - aCenterY = anObject->centerPoint().y(); - } - else if( QGraphicsPixmapItem* aPixmapItem = dynamic_cast( theItem ) ) - { - QPoint aPoint = aPixmapItem->pixmap().rect().center(); - aCenterX = aPoint.x(); - aCenterY = aPoint.y(); - } - - QTransform aTransform; - aTransform.translate( aCenterX, aCenterY ); - aTransform.rotate( theAngle ); - aTransform.translate( -aCenterX, -aCenterY ); - theItem->setTransform( aTransform, false ); -} diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index a9b22ea81..b55386be6 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -96,11 +96,6 @@ public: virtual QTransform getViewTransform() const { return myViewTransform; } virtual void setViewTransform( const QTransform& theTransform ); - virtual QPointF centerPoint(); - -public: - static void setRotationAroundCenter( QGraphicsItem* theItem, double theAngle ); - protected: QCursor* getHighlightCursor() const { return myHighlightCursor; } diff --git a/src/GraphicsView/GraphicsView_PrsImage.cxx b/src/GraphicsView/GraphicsView_PrsImage.cxx index af423b0cf..1bb7afe59 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.cxx +++ b/src/GraphicsView/GraphicsView_PrsImage.cxx @@ -47,9 +47,15 @@ GraphicsView_PrsImage::GraphicsView_PrsImage() myPixmapItem( 0 ), myPreviewPixmapItem( 0 ), myImageFrame( 0 ), + myPosX( 0.0 ), + myPosY( 0.0 ), myScaleX( 1.0 ), myScaleY( 1.0 ), myRotationAngle( 0.0 ), + myPreviewPosX( 0.0 ), + myPreviewPosY( 0.0 ), + myPreviewScaleX( 1.0 ), + myPreviewScaleY( 1.0 ), myPreviewRotationAngle( 0.0 ) { } @@ -60,6 +66,7 @@ GraphicsView_PrsImage::GraphicsView_PrsImage() //======================================================================= GraphicsView_PrsImage::~GraphicsView_PrsImage() { + /* to be revised if( myPreviewPixmapItem ) { delete myPreviewPixmapItem; @@ -71,6 +78,7 @@ GraphicsView_PrsImage::~GraphicsView_PrsImage() delete myImageFrame; myImageFrame = 0; } + */ QListIterator aChildIter( children() ); while( aChildIter.hasNext() ) @@ -86,6 +94,25 @@ GraphicsView_PrsImage::~GraphicsView_PrsImage() } } +//================================================================ +// Function : updateTransform +// Purpose : +//================================================================ +void GraphicsView_PrsImage::updateTransform() +{ + QTransform aTransform = getTransform(); + + setTransform( aTransform ); + myImageFrame->setTransform( aTransform ); + + // for anchors + myImageFrame->setScaling( myScaleX, myScaleY ); + myImageFrame->setRotationAngle( myRotationAngle ); + + aTransform = getTransform( true ); + myPreviewPixmapItem->setTransform( aTransform ); +} + //================================================================ // Function : setImage // Purpose : @@ -101,29 +128,25 @@ void GraphicsView_PrsImage::setImage( const QImage& theImage ) //================================================================ QImage GraphicsView_PrsImage::getImage() const { - QImage anImage = myPixmap.toImage(); - return anImage; + return myPixmap.toImage(); } //================================================================ // Function : getTransform // Purpose : //================================================================ -QTransform GraphicsView_PrsImage::getTransform() const +QTransform GraphicsView_PrsImage::getTransform( const bool theIsPreview ) const { - double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; - getPosition( aPosX, aPosY ); - getScaling( aScaleX, aScaleY ); - getRotationAngle( aRotationAngle ); - - QPointF aCenter = myPixmapItem->pixmap().rect().center(); + double aPosX = theIsPreview ? myPreviewPosX : myPosX; + double aPosY = theIsPreview ? myPreviewPosY : myPosY; + double aScaleX = theIsPreview ? myPreviewScaleX : myScaleX; + double aScaleY = theIsPreview ? myPreviewScaleY : myScaleY; + double aRotationAngle = theIsPreview ? myPreviewRotationAngle : myRotationAngle; QTransform aTransform; - aTransform.translate( aCenter.x(), aCenter.y() ); + aTransform.translate( aPosX, aPosY ); aTransform.rotate( aRotationAngle ); aTransform.scale( aScaleX, aScaleY ); - aTransform.translate( -aCenter.x() * aScaleX, -aCenter.y() * aScaleY ); - aTransform.translate( aPosX, aPosY ); return aTransform; } @@ -133,7 +156,8 @@ QTransform GraphicsView_PrsImage::getTransform() const //================================================================ void GraphicsView_PrsImage::setPosition( const double thePosX, const double thePosY ) { - setPos( thePosX, thePosY ); + myPosX = thePosX; + myPosY = thePosY; } //================================================================ @@ -142,8 +166,8 @@ void GraphicsView_PrsImage::setPosition( const double thePosX, const double theP //================================================================ void GraphicsView_PrsImage::getPosition( double& thePosX, double& thePosY ) const { - thePosX = pos().x(); - thePosY = pos().y(); + thePosX = myPosX; + thePosY = myPosY; } //================================================================ @@ -233,19 +257,14 @@ void GraphicsView_PrsImage::compute() myImageFrame->setPrsImage( this ); } - QSize aSourceSize = myPixmap.size(); - QSize aScaledSize( aSourceSize.width() * myScaleX, - aSourceSize.height() * myScaleY ); - - QPixmap aPixmap = myPixmap.scaled( aScaledSize ); - myPixmapItem->setPixmap( aPixmap ); + myPixmapItem->setPixmap( myPixmap ); - myPreviewPixmapItem->setPixmap( aPixmap ); + myPreviewPixmapItem->setPixmap( myPixmap ); myPreviewPixmapItem->setVisible( false ); - setRotationAroundCenter( this, myRotationAngle ); - myImageFrame->compute(); + + updateTransform(); } //================================================================ @@ -298,25 +317,6 @@ bool GraphicsView_PrsImage::checkHighlight( double theX, double theY, QCursor& t return false; } -//================================================================ -// Function : highlight -// Purpose : -//================================================================ -bool GraphicsView_PrsImage::highlight( double theX, double theY ) -{ - bool anIsHighlighted = GraphicsView_Object::highlight( theX, theY ); - return anIsHighlighted; -} - -//================================================================ -// Function : unhighlight -// Purpose : -//================================================================ -void GraphicsView_PrsImage::unhighlight() -{ - GraphicsView_Object::unhighlight(); -} - //================================================================ // Function : select // Purpose : @@ -364,7 +364,10 @@ void GraphicsView_PrsImage::move( double theDX, double theDY, bool theIsAtOnce ) enablePreview( true ); myIsMoving = true; - myPreviewPixmapItem->moveBy( theDX, theDY ); + + myPreviewPosX += theDX; + myPreviewPosY += theDY; + updateTransform(); } //================================================================ @@ -375,24 +378,15 @@ bool GraphicsView_PrsImage::finishMove() { if( myIsMoving ) { - setPos( myPreviewPixmapItem->pos() ); - myImageFrame->setPos( pos() ); + myPosX = myPreviewPosX; + myPosY = myPreviewPosY; + updateTransform(); enablePreview( false ); } return GraphicsView_Object::finishMove(); } -//================================================================ -// Function : centerPoint -// Purpose : -//================================================================ -QPointF GraphicsView_PrsImage::centerPoint() -{ - QPointF aPoint = myPixmapItem->boundingRect().center(); - return aPoint; -} - //================================================================ // Function : processResize // Purpose : @@ -457,19 +451,19 @@ void GraphicsView_PrsImage::processResize( const int theAnchor, break; } - QPixmap aCurrentPixmap = myPixmapItem->pixmap(); - int aWidth = aCurrentPixmap.width(); - int aHeight = aCurrentPixmap.height(); + double aWidth = (double)myPixmap.width() * myScaleX; + double aHeight = (double)myPixmap.height() * myScaleY; - int aNewWidth = aWidth + (int)aSizeShift.x(); - int aNewHeight = aHeight + (int)aSizeShift.y(); - if( aNewWidth < 10 || aNewHeight < 10 ) // tmp - return; + double aNewWidth = aWidth + aSizeShift.x(); + double aNewHeight = aHeight + aSizeShift.y(); + + myPreviewScaleX = myScaleX * aNewWidth / aWidth; + myPreviewScaleY = myScaleY * aNewHeight / aHeight; - QPixmap aPixmap = myPixmap.scaled( aNewWidth, aNewHeight ); - myPreviewPixmapItem->setPixmap( aPixmap ); + myPreviewPosX = myPosX + aPosShift.x(); + myPreviewPosY = myPosY + aPosShift.y(); - myPreviewPixmapItem->setPos( pos() + aPosShift ); + updateTransform(); } //================================================================ @@ -478,32 +472,12 @@ void GraphicsView_PrsImage::processResize( const int theAnchor, //================================================================ void GraphicsView_PrsImage::finishResize() { - QSize aSourceSize = myPixmap.size(); - QSize aScaledSize = myPreviewPixmapItem->pixmap().size(); - - myScaleX = ( (double)aScaledSize.width() ) / ( (double)aSourceSize.width() ); - myScaleY = ( (double)aScaledSize.height() ) / ( (double)aSourceSize.height() ); + myPosX = myPreviewPosX; + myPosY = myPreviewPosY; - QPointF aSceneCenter = myPixmapItem->sceneBoundingRect().center(); - QPointF aPreviewSceneCenter = myPreviewPixmapItem->sceneBoundingRect().center(); - - QPointF aCenter = myPixmapItem->pixmap().rect().center(); - QPointF aPreviewCenter = myPreviewPixmapItem->pixmap().rect().center(); - - QPointF aCenterShift = aSceneCenter - aCenter; - QPointF aPreviewCenterShift = aPreviewSceneCenter - aPreviewCenter; - - QPointF aPosShift = myPreviewPixmapItem->pos() - pos(); - QPointF aShift = aPreviewCenterShift - aCenterShift - aPosShift; - - myPixmapItem->setPixmap( myPreviewPixmapItem->pixmap() ); - myImageFrame->computeAnchorItems(); - - setPos( myPreviewPixmapItem->pos() + aShift ); - setRotationAroundCenter( this, myRotationAngle ); - - myImageFrame->setPos( myPreviewPixmapItem->pos() + aShift ); - setRotationAroundCenter( myImageFrame, myRotationAngle ); + myScaleX = myPreviewScaleX; + myScaleY = myPreviewScaleY; + updateTransform(); enablePreview( false ); } @@ -539,7 +513,23 @@ void GraphicsView_PrsImage::processRotate( const double theAngle ) enablePreview( true ); myPreviewRotationAngle = myRotationAngle + theAngle; - setRotationAroundCenter( myPreviewPixmapItem, myPreviewRotationAngle ); + + QPointF aCenter( (double)myPixmap.width() / 2., + (double)myPixmap.height() / 2. ); + + myPreviewPosX = myPosX; + myPreviewPosY = myPosY; + QTransform aTransform1 = getTransform(); + QTransform aTransform2 = getTransform( true ); + + QPointF aPoint1 = aTransform1.map( aCenter ); + QPointF aPoint2 = aTransform2.map( aCenter ); + QPointF aDiff = aPoint2 - aPoint1; + + myPreviewPosX = myPosX - aDiff.x(); + myPreviewPosY = myPosY - aDiff.y(); + + updateTransform(); } //================================================================ @@ -548,11 +538,10 @@ void GraphicsView_PrsImage::processRotate( const double theAngle ) //================================================================ void GraphicsView_PrsImage::finishRotate() { + myPosX = myPreviewPosX; + myPosY = myPreviewPosY; myRotationAngle = myPreviewRotationAngle; - setRotationAroundCenter( this, myRotationAngle ); - setRotationAroundCenter( myImageFrame, myRotationAngle ); - - myImageFrame->setRotationAngle( myRotationAngle ); // for anchors + updateTransform(); enablePreview( false ); } @@ -568,8 +557,10 @@ void GraphicsView_PrsImage::enablePreview( const bool theState ) myPreviewPixmapItem->setZValue( PREVIEW_Z_VALUE ); myPreviewPixmapItem->setOpacity( opacity() / 2. ); - myPreviewPixmapItem->setPos( pos() ); - setRotationAroundCenter( myPreviewPixmapItem, myRotationAngle ); + myPreviewPosX = myPosX; + myPreviewPosY = myPosY; + myPreviewScaleX = myScaleX; + myPreviewScaleY = myScaleY; myPreviewRotationAngle = myRotationAngle; myPreviewPixmapItem->setVisible( true ); diff --git a/src/GraphicsView/GraphicsView_PrsImage.h b/src/GraphicsView/GraphicsView_PrsImage.h index 5faadb72a..fba539426 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.h +++ b/src/GraphicsView/GraphicsView_PrsImage.h @@ -40,10 +40,12 @@ public: virtual ~GraphicsView_PrsImage(); public: + void updateTransform(); + void setImage( const QImage& theImage ); QImage getImage() const; - QTransform getTransform() const; + QTransform getTransform( const bool theIsPreview = false ) const; void setPosition( const double thePosX, const double thePosY ); void getPosition( double& thePosX, double& thePosY ) const; @@ -69,9 +71,6 @@ public: virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const; - virtual bool highlight( double theX, double theY ); - virtual void unhighlight(); - virtual bool select( double theX, double theY, const QRectF& theRect ); virtual void unselect(); virtual void setSelected( bool theState ); @@ -79,8 +78,6 @@ public: virtual void move( double theDX, double theDY, bool theIsAtOnce = false ); virtual bool finishMove(); - virtual QPointF centerPoint(); - protected: void processResize( const int theAnchor, const double theDX, @@ -109,10 +106,16 @@ protected: GraphicsView_PrsImageFrame* myImageFrame; + double myPosX; + double myPosY; double myScaleX; double myScaleY; - double myRotationAngle; + + double myPreviewPosX; + double myPreviewPosY; + double myPreviewScaleX; + double myPreviewScaleY; double myPreviewRotationAngle; private: diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index b57d0221e..a341534fc 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -294,19 +294,6 @@ void GraphicsView_PrsImageFrame::finishPulling( const GraphicsView_ObjectList& t } } -//================================================================ -// Function : centerPoint -// Purpose : -//================================================================ -QPointF GraphicsView_PrsImageFrame::centerPoint() -{ - QPointF aPoint1 = myAnchorMap[ Top ]->getBasePoint(); - QPointF aPoint2 = myAnchorMap[ Bottom ]->getBasePoint(); - QPointF aPoint3 = myAnchorMap[ Left ]->getBasePoint(); - QPointF aPoint4 = myAnchorMap[ Right ]->getBasePoint(); - return ( aPoint1 + aPoint2 + aPoint3 + aPoint4 ) / 4.; -} - //================================================================ // Function : setPrsImage // Purpose : @@ -364,18 +351,22 @@ void GraphicsView_PrsImageFrame::updateAnchorItems() return; bool anIsSelected = myPrsImage->isSelected(); - if( anIsSelected ) - { - double aPosX, aPosY, aRotationAngle; - myPrsImage->getPosition( aPosX, aPosY ); - myPrsImage->getRotationAngle( aRotationAngle ); - - setPos( aPosX, aPosY ); - setRotationAroundCenter( this, aRotationAngle ); - } setVisible( anIsSelected ); } +//================================================================ +// Function : setScaling +// Purpose : +//================================================================ +void GraphicsView_PrsImageFrame::setScaling( const double theScaleX, + const double theScaleY ) +{ + AnchorMapIterator anIter( myAnchorMap ); + while( anIter.hasNext() ) + if( UnscaledGraphicsEllipseItem* anAnchorItem = anIter.next().value() ) + anAnchorItem->setScaling( theScaleX, theScaleY ); +} + //================================================================ // Function : setRotationAngle // Purpose : @@ -397,13 +388,15 @@ QCursor* GraphicsView_PrsImageFrame::getResizeCursor( const int theAnchor ) cons if( !myPrsImage ) return 0; - double aRotationAngle = 0; + double aScaleX, aScaleY, aRotationAngle; + myPrsImage->getScaling( aScaleX, aScaleY ); myPrsImage->getRotationAngle( aRotationAngle ); - int anAngle = (int)aRotationAngle; - anAngle = anAngle % 360; - anAngle += 360; // to avoid negative values - anAngle = anAngle % 360; // 0 <= anAngle <= 359 + int anAngle = (int)aRotationAngle; // -inf <= anAngle <= inf + anAngle = anAngle % 360; // -359 <= anAngle <= 359 + anAngle = ( anAngle + 360 ) % 360; // 0 <= anAngle <= 359 + + int aSign = aScaleX * aScaleY < 0 ? -1 : 1; int aShift = 0; switch( theAnchor ) @@ -417,8 +410,8 @@ QCursor* GraphicsView_PrsImageFrame::getResizeCursor( const int theAnchor ) cons case Left: aShift = 270; break; case TopLeft: aShift = 315; break; } - anAngle += aShift; - anAngle = anAngle % 360; + anAngle += aSign * aShift; // -315 <= anAngle <= 674 + anAngle = ( anAngle + 360 ) % 360; // 0 <= anAngle <= 359 // 360 = 8 sectors of 45 degrees if( anAngle <= 22 || anAngle >= 338 ) @@ -446,6 +439,8 @@ QCursor* GraphicsView_PrsImageFrame::getResizeCursor( const int theAnchor ) cons //======================================================================= GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::UnscaledGraphicsEllipseItem( QGraphicsItem* theParent ) : QGraphicsEllipseItem( theParent ), + myScaleX( 1.0 ), + myScaleY( 1.0 ), myRotationAngle( 0.0 ) { } @@ -458,6 +453,27 @@ GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::~UnscaledGraphicsEllips { } +//================================================================ +// Function : boundingRect +// Purpose : +//================================================================ +void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem:: + setScaling( const double theScaleX, const double theScaleY ) +{ + myScaleX = theScaleX; + myScaleY = theScaleY; +} + +//================================================================ +// Function : boundingRect +// Purpose : +//================================================================ +void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem:: + setRotationAngle( const double theRotationAngle ) +{ + myRotationAngle = theRotationAngle; +} + //================================================================ // Function : boundingRect // Purpose : @@ -472,15 +488,17 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c QTransform aTransform = aParent->getViewTransform(); double aScale = aTransform.m11(); // same as m22(), viewer specific - if( fabs( aScale ) < 1e-10 ) + if( fabs( aScale ) < 1e-10 || + fabs( myScaleX ) < 1e-10 || + fabs( myScaleY ) < 1e-10 ) return aRect; QPointF aCenter = aRect.center(); - double aWidth = aRect.width() / aScale; - double aHeight = aRect.height() / aScale; + double aWidth = aRect.width() / aScale / myScaleX; + double aHeight = aRect.height() / aScale / myScaleY; - double anOffsetX = myOffset.x() / aScale; - double anOffsetY = myOffset.y() / aScale; + double anOffsetX = myOffset.x() / aScale / fabs( myScaleX ); + double anOffsetY = myOffset.y() / aScale / fabs( myScaleY ); aRect = QRectF( aCenter.x() - aWidth / 2 + anOffsetX, aCenter.y() - aHeight / 2 + anOffsetY, @@ -515,15 +533,22 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint( QWidget* theWidget ) { // draw a connection line (mainly, for top-most anchor) - thePainter->drawLine( myBasePoint, boundingRect().center() ); + //thePainter->drawLine( myBasePoint, boundingRect().center() ); thePainter->save(); thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(), myBasePoint ) ); + double anOffsetX = myOffset.x(); + double anOffsetY = myOffset.y(); + if( myScaleX < 0 ) + anOffsetX *= -1; + if( myScaleY < 0 ) + anOffsetY *= -1; + double anAngle = myRotationAngle * PI / 180.; - double aDX = myOffset.x() * cos( anAngle ) - myOffset.y() * sin( anAngle ); - double aDY = myOffset.x() * sin( anAngle ) + myOffset.y() * cos( anAngle ); + double aDX = anOffsetX * cos( anAngle ) - anOffsetY * sin( anAngle ); + double aDY = anOffsetX * sin( anAngle ) + anOffsetY * cos( anAngle ); thePainter->translate( aDX, aDY ); QGraphicsEllipseItem::paint( thePainter, theOption, theWidget ); diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.h b/src/GraphicsView/GraphicsView_PrsImageFrame.h index 84bbdf94c..3ccecd047 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.h +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.h @@ -72,14 +72,13 @@ public: virtual void finishPulling( const GraphicsView_ObjectList& ); virtual bool isPulling() { return myIsPulling; } - virtual QPointF centerPoint(); - public: void setPrsImage( GraphicsView_PrsImage* ); void computeAnchorItems(); void updateAnchorItems(); + void setScaling( const double theScaleX, const double theScaleY ); void setRotationAngle( const double theRotationAngle ); protected: @@ -125,7 +124,8 @@ public: void setOffset( const QPointF& theOffset ) { myOffset = theOffset; } const QPointF& getOffset() const { return myOffset; } - void setRotationAngle( const double theAngle ) { myRotationAngle = theAngle; } + void setScaling( const double theScaleX, const double theScaleY ); + void setRotationAngle( const double theRotationAngle ); public: virtual QRectF boundingRect() const; @@ -135,6 +135,8 @@ private: QPointF myBasePoint; QPointF myOffset; + double myScaleX; + double myScaleY; double myRotationAngle; }; diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx index d2fc4af67..c8d371a32 100644 --- a/src/GraphicsView/GraphicsView_Scene.cxx +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -22,6 +22,7 @@ #include "GraphicsView_Scene.h" +#include #include #include @@ -43,12 +44,18 @@ GraphicsView_Scene::GraphicsView_Scene( QObject* theParent ) connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ), this, SLOT( onSceneRectChanged( const QRectF& ) ) ); - QGraphicsEllipseItem* aCenterItem = new QGraphicsEllipseItem( 0, 0, 5, 5 ); - aCenterItem->setBrush( QBrush( Qt::red ) ); - addItem( aCenterItem ); #endif - setSceneRect( -500, -500, 3000, 3000 ); // testing ImageViewer + // testing ImageViewer + setSceneRect( -2000, -2000, 4000, 4000 ); + + QGraphicsLineItem* aHorLineItem = new QGraphicsLineItem( -2000, 0, 2000, 0 ); + aHorLineItem->setPen( QPen( Qt::red ) ); + addItem( aHorLineItem ); + + QGraphicsLineItem* aVerLineItem = new QGraphicsLineItem( 0, -2000, 0, 2000 ); + aVerLineItem->setPen( QPen( Qt::red ) ); + addItem( aVerLineItem ); } //======================================================================= diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 3c0e26394..5384abef6 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -248,6 +248,7 @@ void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem ) } } myObjects.insert( anIter, anObject ); + anObject->setViewTransform( transform() ); anObject->addTo( this ); } else diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index d627e919c..56c4bc2e6 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -546,26 +546,6 @@ void GraphicsView_Viewer::onSelectionCancel() //================================================================ void GraphicsView_Viewer::onAddImage() { - /*GraphicsView_ViewFrame* aViewFrame = getActiveView(); - GraphicsView_ViewPort* aViewPort = getActiveViewPort(); - - GraphicsView_PrsImage* aPrs1 = new GraphicsView_PrsImage(); - QImage anImage1( "D:\\asl\\hydro\\dev\\HYDRO_SRC\\examples\\example1.png" ); - aPrs1->setImage( anImage1 ); - aPrs1->compute(); - aViewPort->addItem( aPrs1 ); - - GraphicsView_PrsImage* aPrs2 = new GraphicsView_PrsImage(); - QImage anImage2( "D:\\asl\\hydro\\dev\\HYDRO_SRC\\examples\\example2.png" ); - aPrs2->setImage( anImage2 ); - aPrs2->setRotationAngle( 30 ); - aPrs2->setPosition( 200, 50 ); - aPrs2->compute(); - aViewPort->addItem( aPrs2 ); - - aViewPort->fitAll(); - return;*/ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) { QString aFileName = QFileDialog::getOpenFileName(); @@ -795,8 +775,17 @@ void GraphicsView_Viewer::onTestImageComposition() ImageComposer_Image aResult = anImage1 | anImage2; GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage(); aResPrs->setImage( aResult ); - aResPrs->setTransform( aResult.transform() ); - aResPrs->compute(); + + double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; + anObj1->getPosition( aPosX, aPosY ); + anObj1->getScaling( aScaleX, aScaleY ); + anObj1->getRotationAngle( aRotationAngle ); + + aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() ); + aResPrs->setScaling( aScaleX, aScaleY ); + aResPrs->setRotationAngle( aRotationAngle ); + + aResPrs->compute(); aViewPort->addItem( aResPrs ); aViewPort->removeItem( anObj1 ); diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index 3dcce3db5..06ef7526a 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -100,6 +100,7 @@ protected slots: virtual void onChangeBgColor(); // testing ImageViewer + void onTestImageComposition(); void onAddImage(); void onRemoveImages(); void onBringToFront(); @@ -107,7 +108,6 @@ protected slots: void onBringForward(); void onSendBackward(); void onPrsProperties(); - void onTestImageComposition(); private: void handleKeyPress( QKeyEvent* ); -- 2.39.2