]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
refs #1472: patch for unlimited panning in graphics view.
authormkr <mkr@opencascade.com>
Thu, 7 Dec 2017 15:48:36 +0000 (18:48 +0300)
committermkr <mkr@opencascade.com>
Thu, 7 Dec 2017 15:49:15 +0000 (18:49 +0300)
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h

index f18cd1e6c75cc66a67c78b383f4db81742e604ea..6753aa5f6b28c3bbcf18696befd9f8afc5a787ea 100644 (file)
@@ -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  : 
index 1d66b0ac260c14ef4dca5d0667fef204c2a50818..50ac0b65f641c601b0a10862fed33f53b638cde3 100644 (file)
@@ -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;