#include <math.h>
-#define VIEW_GAP 20
-
int GraphicsView_ViewPort::nCounter = 0;
QCursor* GraphicsView_ViewPort::defCursor = 0;
QCursor* GraphicsView_ViewPort::handCursor = 0;
myScene = new GraphicsView_Scene( this );
setScene( myScene );
+ mySceneGap = 20;
+ myFitAllGap = 40;
+
// background
setBackgroundBrush( QBrush( Qt::white ) );
// Function : objectsBoundingRect
// Purpose :
//================================================================
-QRectF GraphicsView_ViewPort::objectsBoundingRect() const
+QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const
{
QRectF aRect;
QListIterator<QGraphicsItem*> anIter( items() );
{
if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
{
+ if( theOnlyVisible && !anObject->isVisible() )
+ continue;
+
QRectF anObjectRect = anObject->getRect();
if( !anObjectRect.isNull() )
{
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 :
myForegroundItem->setVisible( true );
- myScene->setSceneRect( aRect.adjusted( -VIEW_GAP, -VIEW_GAP, VIEW_GAP, VIEW_GAP ) );
+ myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
}
else
{
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;
}
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 ) );
}
//================================================================
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 );
private:
// scene
GraphicsView_Scene* myScene;
+ double mySceneGap;
+ double myFitAllGap;
// view name
NameLabel* myNameLabel;