]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Panning action (in progress)
authorCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Fri, 8 Mar 2024 07:34:34 +0000 (08:34 +0100)
committerCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Fri, 8 Mar 2024 07:34:34 +0000 (08:34 +0100)
src/GraphicsView/GraphicsView_ViewFrame.cxx
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h
src/GraphicsView/GraphicsView_Viewer.cxx
src/GraphicsView/GraphicsView_Viewer.h

index 974a8a6bcc33cede3f521e0915766583c20fb240..44cd01ac4f50fe2cc202efd917c65498dbefde13 100644 (file)
@@ -308,6 +308,7 @@ void GraphicsView_ViewFrame::expandToolBarActions()
 //================================================================
 void GraphicsView_ViewFrame::onViewPan()
 {
+  myViewer->pan();
 //  myViewer->activateTransform( GraphicsView_Viewer::Pan );
 }
 
index af16efdaa75a0f9a7712e40b556b8daf2d4767bd..db8ad6a86ee1d2470fdcc53448766bb0a8847aa7 100644 (file)
 #include <QRubberBand>
 #include <QMouseEvent>
 #include <QCursor>
+#include <QScrollBar>
 
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_Session.h"
-
+#include <iostream>
 //=======================================================================
 // Name    : GraphicsView_ViewPort
 // Purpose : Constructor
@@ -38,6 +39,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
 
   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
   setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
   
   setMouseTracking( true );
@@ -52,6 +54,8 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
 
   zooming = false;
   previousPos = QPoint();
+
+  panning = false;
   
   SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
   zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
@@ -160,7 +164,7 @@ void GraphicsView_ViewPort::finishDrawingRect()
 
 void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event)
 { 
- if (!zooming && items(event->pos()).count()==0)
+ if (!zooming && !panning && items(event->pos()).count()==0)
     {
       startDrawingRect(event->pos().x(), event->pos().y());
     }
@@ -175,6 +179,22 @@ void GraphicsView_ViewPort::mouseMoveEvent(QMouseEvent *event)
   if ((event->modifiers() & Qt::ShiftModifier) && (event->buttons() & Qt::LeftButton))
     activateZoomAction();
 
+  if (panning && (event->buttons() & Qt::LeftButton))
+    {
+    QPoint currentPos = event->pos();
+
+    if (!previousPos.isNull())
+    {
+      double deltaX = currentPos.x() - previousPos.x();
+      double deltaY = currentPos.y() - previousPos.y();
+
+      pan(deltaX, deltaY);
+
+    }
+    previousPos = currentPos;  
+
+    }
+
   if (zooming && (event->buttons() & Qt::LeftButton))
   {
     QPoint currentPos = event->pos();
@@ -228,12 +248,16 @@ void GraphicsView_ViewPort::clearActions()
   setCursor(Qt::ArrowCursor);
   fittingArea = false;
   zooming = false;
+  panning  = false;
+  previousPos = QPoint();
+  setDragMode(QGraphicsView::RubberBandDrag); 
 }
   
 void GraphicsView_ViewPort::activateZoomAction() 
 { 
   zooming = true;
   fittingArea = false;
+  panning  = false;
   setCursor(*zoomCursor); 
 }
 
@@ -241,5 +265,36 @@ void GraphicsView_ViewPort::activateFitAreaAction()
 { 
   fittingArea = true;
   zooming = false;
+  panning  = false;
   setCursor(Qt::PointingHandCursor);
 }
+
+void GraphicsView_ViewPort::activatePanAction() 
+{
+  panning = true; 
+  fittingArea = false;
+  zooming = false;
+  setCursor(Qt::SizeAllCursor);
+}
+
+void GraphicsView_ViewPort::pan( double theDX, double theDY )
+{
+  std::cout << "pan : " << theDX << " " << theDY << std::endl;
+
+  if( QScrollBar* aHBar = horizontalScrollBar() )
+  {
+      int aNewValue = aHBar->value() - theDX;
+      if( aNewValue < aHBar->minimum() )
+        aHBar->setMinimum( aNewValue );
+      if( aNewValue > aHBar->maximum() )
+        aHBar->setMaximum( aNewValue );
+  }
+  if( QScrollBar* aVBar = verticalScrollBar() )
+  {
+      int aNewValue = aVBar->value() - theDY;
+      if( aNewValue < aVBar->minimum() )
+        aVBar->setMinimum( aNewValue );
+      if( aNewValue > aVBar->maximum() )
+        aVBar->setMaximum( aNewValue );
+  }
+}
index f5bf5a233f1090ea6aad021adf15593849cf0522..ea04e08a5e26df2a9870a0b876434ef4704e20b6 100644 (file)
@@ -56,6 +56,8 @@ public:
 
   void activateZoomAction();
   void activateFitAreaAction(); 
+  void activatePanAction(); 
+  void pan( double theDX, double theDY );
 
 signals:
   void vpMouseEvent(QMouseEvent*);
@@ -84,6 +86,7 @@ private:
 
   bool fittingArea;
   bool zooming;
+  bool panning;
   QPoint previousPos;
   QCursor* zoomCursor;
 };
index bfb50f147a0690e36360c8743e5312e22802f815..9c593f6190f0050bbbd16b2a2627556989c118a5 100644 (file)
@@ -379,3 +379,9 @@ void GraphicsView_Viewer::zoom()
   if (GraphicsView_ViewPort* aViewPort = getActiveViewPort())
     aViewPort->activateZoomAction();
 }
+
+void GraphicsView_Viewer::pan()
+{
+  if (GraphicsView_ViewPort* aViewPort = getActiveViewPort())
+    aViewPort->activatePanAction();
+}
index b5b53c29cdd4f5aa7217b6930b6445efa6ebc172..5ac77cabb7f7055ade71dcad6e5dbb4df30b16b3 100644 (file)
@@ -77,6 +77,7 @@ public:
   void fitSelect();
   void fitArea();
   void zoom();
+  void pan();
 
   bool                          isInitialized() const { return myIsInitialized; }
   void                          setIsInitialized( bool );