From: CHEMIN Sebastien Date: Fri, 8 Mar 2024 07:34:34 +0000 (+0100) Subject: Panning action (in progress) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=20831530c2d3d6f1ab50002dc8a220597a7d731f;p=modules%2Fgui.git Panning action (in progress) --- diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index 974a8a6bc..44cd01ac4 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -308,6 +308,7 @@ void GraphicsView_ViewFrame::expandToolBarActions() //================================================================ void GraphicsView_ViewFrame::onViewPan() { + myViewer->pan(); // myViewer->activateTransform( GraphicsView_Viewer::Pan ); } diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index af16efdaa..db8ad6a86 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -23,10 +23,11 @@ #include #include #include +#include #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" - +#include //======================================================================= // 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 ); + } +} diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index f5bf5a233..ea04e08a5 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -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; }; diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index bfb50f147..9c593f619 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -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(); +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index b5b53c29c..5ac77cabb 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -77,6 +77,7 @@ public: void fitSelect(); void fitArea(); void zoom(); + void pan(); bool isInitialized() const { return myIsInitialized; } void setIsInitialized( bool );