From 0a4a2b003184a2a14ba4d8d4c4ca692b339b4f02 Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Mon, 18 Mar 2024 14:25:33 +0100 Subject: [PATCH] Add global pan --- src/GraphicsView/GraphicsView_ViewFrame.cxx | 3 +-- src/GraphicsView/GraphicsView_ViewPort.cxx | 27 +++++++++++++++++++-- src/GraphicsView/GraphicsView_ViewPort.h | 2 ++ src/GraphicsView/GraphicsView_Viewer.cxx | 9 +++++++ src/GraphicsView/GraphicsView_Viewer.h | 1 + 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index c97c62ec1..9c40eaad3 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -341,7 +341,7 @@ void GraphicsView_ViewFrame::onViewFitSelect() //================================================================ void GraphicsView_ViewFrame::onViewGlobalPan() { -// myViewer->activateTransform( GraphicsView_Viewer::PanGlobal ); + myViewer->globalPan(); } //================================================================ @@ -350,7 +350,6 @@ void GraphicsView_ViewFrame::onViewGlobalPan() //================================================================ void GraphicsView_ViewFrame::onViewReset() { -// myViewer->activateTransform( GraphicsView_Viewer::Reset ); } //================================================================ diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 44f7966ab..41c6535f8 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -58,6 +58,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) previousPos = QPoint(); panning = false; + globalPanning = false; SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr(); zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) ); @@ -162,11 +163,20 @@ void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect) void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event) { - if (!zooming && !panning && items(event->pos()).count()==0 && (event->buttons() & Qt::LeftButton)) + if (!zooming && !panning && !globalPanning && items(event->pos()).count()==0 && (event->buttons() & Qt::LeftButton)) { startDrawingRect(event->pos().x(), event->pos().y()); } - + + if (globalPanning) + { + QPoint p0 = viewport()->rect().center(); + QPoint p1 = event->pos(); + double deltaX = p0.x() - p1.x(); + double deltaY = p0.y() - p1.y(); + + pan(deltaX, -deltaY); + } QGraphicsView::mousePressEvent(event); emit vpMouseEvent(event); } @@ -267,6 +277,7 @@ void GraphicsView_ViewPort::clearActions() fittingArea = false; zooming = false; panning = false; + globalPanning = false; previousPos = QPoint(); } @@ -275,6 +286,7 @@ void GraphicsView_ViewPort::activateZoomAction() zooming = true; fittingArea = false; panning = false; + globalPanning = false; setCursor(*zoomCursor); } @@ -283,6 +295,7 @@ void GraphicsView_ViewPort::activateFitAreaAction() fittingArea = true; zooming = false; panning = false; + globalPanning = false; setCursor(Qt::PointingHandCursor); } @@ -291,9 +304,19 @@ void GraphicsView_ViewPort::activatePanAction() panning = true; fittingArea = false; zooming = false; + globalPanning = false; setCursor(Qt::SizeAllCursor); } +void GraphicsView_ViewPort::activateGlobalPanAction() +{ + globalPanning = true; + panning = false; + fittingArea = false; + zooming = false; + setCursor(Qt::CrossCursor); +} + void GraphicsView_ViewPort::pan( double theDX, double theDY ) { if( QScrollBar* aHBar = horizontalScrollBar() ) diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 46db685b4..5387c5269 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -52,6 +52,7 @@ public: void activateZoomAction(); void activateFitAreaAction(); void activatePanAction(); + void activateGlobalPanAction(); void pan( double theDX, double theDY ); @@ -87,6 +88,7 @@ private: bool fittingArea; bool zooming; bool panning; + bool globalPanning; QPoint previousPos; QCursor* zoomCursor; }; diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index ca910ea81..87a3d2251 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -301,3 +301,12 @@ void GraphicsView_Viewer::pan() if (GraphicsView_ViewPort* aViewPort = getActiveViewPort()) aViewPort->activatePanAction(); } + +void GraphicsView_Viewer::globalPan() +{ + if (GraphicsView_ViewPort* aViewPort = getActiveViewPort()) + { + aViewPort->fitAll(); + aViewPort->activateGlobalPanAction(); + } +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index ba2dfa997..a0fe51abd 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -66,6 +66,7 @@ public: void fitArea(); void zoom(); void pan(); + void globalPan(); signals: void selectionChanged(); -- 2.39.2