From c342980135a177596ee63801f8fbf7f51018fb4b Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 21 Feb 2011 13:03:45 +0000 Subject: [PATCH] Modification of setting scene rectangle and fit all functionality --- src/GraphicsView/GraphicsView_ViewPort.cxx | 37 ++++++++++++++++++---- src/GraphicsView/GraphicsView_ViewPort.h | 8 ++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 7a556ca4c..158c436c4 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -40,8 +40,6 @@ #include -#define VIEW_GAP 20 - int GraphicsView_ViewPort::nCounter = 0; QCursor* GraphicsView_ViewPort::defCursor = 0; QCursor* GraphicsView_ViewPort::handCursor = 0; @@ -140,6 +138,9 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myScene = new GraphicsView_Scene( this ); setScene( myScene ); + mySceneGap = 20; + myFitAllGap = 40; + // background setBackgroundBrush( QBrush( Qt::white ) ); @@ -256,7 +257,7 @@ GraphicsView_ObjectList GraphicsView_ViewPort::getObjects() const // Function : objectsBoundingRect // Purpose : //================================================================ -QRectF GraphicsView_ViewPort::objectsBoundingRect() const +QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const { QRectF aRect; QListIterator anIter( items() ); @@ -264,6 +265,9 @@ QRectF GraphicsView_ViewPort::objectsBoundingRect() const { if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) { + if( theOnlyVisible && !anObject->isVisible() ) + continue; + QRectF anObjectRect = anObject->getRect(); if( !anObjectRect.isNull() ) { @@ -317,6 +321,25 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene ) return anImage; } +//================================================================ +// Function : setSceneGap +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setSceneGap( double theSceneGap ) +{ + mySceneGap = theSceneGap; + onBoundingRectChanged(); +} + +//================================================================ +// Function : setFitAllGap +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap ) +{ + myFitAllGap = theFitAllGap; +} + //================================================================ // Function : setViewNameEnabled // Purpose : @@ -450,7 +473,7 @@ void GraphicsView_ViewPort::updateForeground() myForegroundItem->setVisible( true ); - myScene->setSceneRect( aRect.adjusted( -VIEW_GAP, -VIEW_GAP, VIEW_GAP, VIEW_GAP ) ); + myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); } else { @@ -582,7 +605,9 @@ void GraphicsView_ViewPort::fitAll( bool theKeepScale ) if( theKeepScale ) myCurrentTransform = transform(); - fitInView( myScene->sceneRect(), Qt::KeepAspectRatio ); + double aGap = myFitAllGap; + QRectF aRect = objectsBoundingRect( true ); + fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); myIsTransforming = false; } @@ -1106,7 +1131,7 @@ void GraphicsView_ViewPort::finishPulling() void GraphicsView_ViewPort::onBoundingRectChanged() { QRectF aRect = objectsBoundingRect(); - myScene->setSceneRect( aRect.adjusted( -VIEW_GAP, -VIEW_GAP, VIEW_GAP, VIEW_GAP ) ); + myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); } //================================================================ diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index cd40efe77..63da84203 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -63,11 +63,15 @@ public: GraphicsView_ObjectList getObjects() const; - QRectF objectsBoundingRect() const; + QRectF objectsBoundingRect( bool theOnlyVisible = false ) const; QImage dumpView( bool theWholeScene = false ); public: + // scene + void setSceneGap( double theSceneGap ); + void setFitAllGap( double theFitAllGap ); + // view name void setViewNameEnabled( bool theState, bool theIsForced = false ); void setViewName( const QString& theName ); @@ -188,6 +192,8 @@ private: private: // scene GraphicsView_Scene* myScene; + double mySceneGap; + double myFitAllGap; // view name NameLabel* myNameLabel; -- 2.39.2