From: mkr Date: Thu, 7 Dec 2017 15:48:36 +0000 (+0300) Subject: refs #1472: patch for unlimited panning in graphics view. X-Git-Tag: V8_5_0b1^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=230d54ef5657cf9e818a02bde2c407a223ad7e12;p=modules%2Fgui.git refs #1472: patch for unlimited panning in graphics view. --- diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index f18cd1e6c..6753aa5f6 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -134,6 +134,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myForegroundItem( 0 ), myGridItem( 0 ), myIsTransforming( false ), + myUnlimitedPanning( false ), myHighlightedObject( 0 ), myHighlightX( 0 ), myHighlightY( 0 ), @@ -195,6 +196,9 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing ); + myHBarPolicy = horizontalScrollBarPolicy(); + myVBarPolicy = verticalScrollBarPolicy(); + connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ), this, SLOT( onKeyEvent( QKeyEvent* ) ) ); connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ), @@ -843,9 +847,29 @@ void GraphicsView_ViewPort::pan( double theDX, double theDY ) myViewLabel->setAcceptMoveEvents( false ); if( QScrollBar* aHBar = horizontalScrollBar() ) + { + if( isUnlimitedPanning() ) + { + int aNewValue = aHBar->value() - theDX; + if( aNewValue < aHBar->minimum() ) + aHBar->setMinimum( aNewValue ); + if( aNewValue > aHBar->maximum() ) + aHBar->setMaximum( aNewValue ); + } aHBar->setValue( aHBar->value() - theDX ); + } if( QScrollBar* aVBar = verticalScrollBar() ) + { + if( isUnlimitedPanning() ) + { + int aNewValue = aVBar->value() + theDY; + if( aNewValue < aVBar->minimum() ) + aVBar->setMinimum( aNewValue ); + if( aNewValue > aVBar->maximum() ) + aVBar->setMaximum( aNewValue ); + } aVBar->setValue( aVBar->value() + theDY ); + } if( myViewLabel ) myViewLabel->setAcceptMoveEvents( true ); @@ -1013,6 +1037,29 @@ void GraphicsView_ViewPort::setZoomCoeff( const int& theZoomCoeff ) myZoomCoeff = theZoomCoeff; } +//================================================================ +// Function : setUnlimitedPanning +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setUnlimitedPanning( const bool& theValue ) +{ + myUnlimitedPanning = theValue; + + if( myUnlimitedPanning ) + { + myHBarPolicy = horizontalScrollBarPolicy(); + myVBarPolicy = verticalScrollBarPolicy(); + + setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + } + else + { + setHorizontalScrollBarPolicy( myHBarPolicy ); + setVerticalScrollBarPolicy( myVBarPolicy ); + } +} + //================================================================ // Function : currentBlock // Purpose : diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 1d66b0ac2..50ac0b65f 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -164,6 +164,9 @@ public: int zoomCoeff() const { return myZoomCoeff; } void setZoomCoeff( const int& theZoomCoeff ); + bool isUnlimitedPanning() const { return myUnlimitedPanning; } + void setUnlimitedPanning( const bool& theValue ); + // block status BlockStatus currentBlock(); @@ -303,6 +306,10 @@ private: bool myIsTransforming; QTransform myCurrentTransform; + bool myUnlimitedPanning; + Qt::ScrollBarPolicy myHBarPolicy; + Qt::ScrollBarPolicy myVBarPolicy; + // highlighting GraphicsView_Object* myHighlightedObject; double myHighlightX;