From 1d333c058b86a9d0993398b2d62a41c9799bd1b8 Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 2 Jul 2013 14:08:20 +0000 Subject: [PATCH] Raw development for ImageViewer. --- src/GraphicsView/GraphicsView_Object.cxx | 9 +++++++ src/GraphicsView/GraphicsView_Object.h | 5 ++++ .../GraphicsView_PrsImageFrame.cxx | 24 +++++++++-------- src/GraphicsView/GraphicsView_PrsImageFrame.h | 1 - src/GraphicsView/GraphicsView_ViewPort.cxx | 26 +++++++++++++++++++ src/GraphicsView/GraphicsView_ViewPort.h | 2 ++ 6 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index 47d3959ae..9c91904df 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -175,6 +175,15 @@ bool GraphicsView_Object::finishMove() return true; } +//================================================================ +// Function : setViewTransform +// Purpose : +//================================================================ +void GraphicsView_Object::setViewTransform( const QTransform& theTransform ) +{ + myViewTransform = theTransform; +} + //================================================================ // Function : centerPoint // Purpose : diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index 6693df0cc..a9b22ea81 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -93,6 +93,9 @@ public: virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; } virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; } + virtual QTransform getViewTransform() const { return myViewTransform; } + virtual void setViewTransform( const QTransform& theTransform ); + virtual QPointF centerPoint(); public: @@ -112,6 +115,8 @@ protected: bool myIsMoving; + QTransform myViewTransform; + private: QCursor* myHighlightCursor; }; diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index e361d821c..b57d0221e 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -446,8 +446,7 @@ QCursor* GraphicsView_PrsImageFrame::getResizeCursor( const int theAnchor ) cons //======================================================================= GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::UnscaledGraphicsEllipseItem( QGraphicsItem* theParent ) : QGraphicsEllipseItem( theParent ), - myRotationAngle( 0.0 ), - myScale( 1.0 ) + myRotationAngle( 0.0 ) { } @@ -467,19 +466,26 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c { QRectF aRect = QGraphicsEllipseItem::boundingRect(); - if( fabs( myScale ) < 1e-10 ) + GraphicsView_Object* aParent = dynamic_cast( parentItem() ); + if( !aParent ) + return aRect; + + QTransform aTransform = aParent->getViewTransform(); + double aScale = aTransform.m11(); // same as m22(), viewer specific + if( fabs( aScale ) < 1e-10 ) return aRect; QPointF aCenter = aRect.center(); - double aWidth = aRect.width() / myScale; - double aHeight = aRect.height() / myScale; + double aWidth = aRect.width() / aScale; + double aHeight = aRect.height() / aScale; - double anOffsetX = myOffset.x() / myScale; - double anOffsetY = myOffset.y() / myScale; + double anOffsetX = myOffset.x() / aScale; + double anOffsetY = myOffset.y() / aScale; aRect = QRectF( aCenter.x() - aWidth / 2 + anOffsetX, aCenter.y() - aHeight / 2 + anOffsetY, aWidth, aHeight ); + return aRect; } @@ -508,10 +514,6 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint( const QStyleOptionGraphicsItem* theOption, QWidget* theWidget ) { - QTransform aTransform = thePainter->transform(); - aTransform.rotate( -myRotationAngle ); // exclude rotation from matrix - myScale = aTransform.m11(); // same as m22(), viewer specific - // draw a connection line (mainly, for top-most anchor) thePainter->drawLine( myBasePoint, boundingRect().center() ); diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.h b/src/GraphicsView/GraphicsView_PrsImageFrame.h index 736b6c46b..84bbdf94c 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.h +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.h @@ -136,7 +136,6 @@ private: QPointF myOffset; double myRotationAngle; - double myScale; }; #endif diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 49f809f45..3c0e26394 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -754,6 +754,8 @@ void GraphicsView_ViewPort::pan( double theDX, double theDY ) myNameLabel->setAcceptMoveEvents( true ); myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -768,6 +770,8 @@ void GraphicsView_ViewPort::setCenter( double theX, double theY ) centerOn( theX, theY ); myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -793,6 +797,8 @@ void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, doub setTransform( aTransform ); myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -806,6 +812,8 @@ void GraphicsView_ViewPort::fitRect( const QRectF& theRect ) fitInView( theRect, Qt::KeepAspectRatio ); myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -837,6 +845,8 @@ void GraphicsView_ViewPort::fitSelect() } myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -855,6 +865,8 @@ void GraphicsView_ViewPort::fitAll( bool theKeepScale ) fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); myIsTransforming = false; + + applyTransform(); } //================================================================ @@ -879,6 +891,20 @@ void GraphicsView_ViewPort::fitWidth() ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap ); myIsTransforming = false; + + applyTransform(); +} + +//================================================================ +// Function : applyTransform +// Purpose : +//================================================================ +void GraphicsView_ViewPort::applyTransform() +{ + GraphicsView_ObjectListIterator anIter( getObjects() ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + anObject->setViewTransform( transform() ); } //================================================================ diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 6dbc74023..6943c8d9c 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -149,6 +149,8 @@ public: bool isTransforming() const { return myIsTransforming; } + void applyTransform(); + // block status BlockStatus currentBlock(); -- 2.39.2