From 94ff1ad512dfea6ddaec8ae37473d64e286aa5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Kosobucki?= Date: Sat, 26 Nov 2022 16:51:28 +0100 Subject: [PATCH] Pan with Middle mouse button in remote view Allow panning with middle mouse button regardless of the current interaction mode. This reduces the need to switch the interaction mode in the remote view when the area where the user wants to look at is out of the view. --- ui/remoteviewwidget.cpp | 48 +++++++++++++++++++++++++++++++++++------ ui/remoteviewwidget.h | 1 + 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/ui/remoteviewwidget.cpp b/ui/remoteviewwidget.cpp index 35c0f1e9c7..89df6af8a0 100644 --- a/ui/remoteviewwidget.cpp +++ b/ui/remoteviewwidget.cpp @@ -1029,6 +1029,15 @@ void RemoteViewWidget::mousePressEvent(QMouseEvent *event) { m_currentMousePosition = mapToSource(QPointF(event->pos())); + // Initiate the middle mouse button panning that works regarless of the interaction mode + if(event->button() == Qt::MiddleButton) { + m_mouseDownPosition = event->pos() - QPoint(m_x, m_y); + m_cursorBeforeMmbPan = cursor(); + setCursor(Qt::ClosedHandCursor); + QWidget::mousePressEvent(event); + return; + } + switch (m_interactionMode) { case NoInteraction: break; @@ -1075,12 +1084,29 @@ void RemoteViewWidget::mouseReleaseEvent(QMouseEvent *event) { m_currentMousePosition = mapToSource(QPointF(event->pos())); + if (event->button() == Qt::MiddleButton) { + // In view interaction, set the open hand cursor if the user hasn't + // initiated LMB panning in the meantime. Otherwise, bring back the + // original cursor. + if(m_interactionMode == ViewInteraction) { + if(!(event->buttons() & Qt::LeftButton)) { + setCursor(Qt::OpenHandCursor); + } + } else { + setCursor(m_cursorBeforeMmbPan); + } + QWidget::mouseReleaseEvent(event); + return; + } + switch (m_interactionMode) { case NoInteraction: case ElementPicking: break; case ViewInteraction: - setCursor(Qt::OpenHandCursor); + if (!(event->buttons() & Qt::MiddleButton)) { + setCursor(Qt::OpenHandCursor); + } break; case Measuring: if (event->buttons() & Qt::LeftButton) @@ -1122,6 +1148,17 @@ void RemoteViewWidget::mouseMoveEvent(QMouseEvent *event) { m_currentMousePosition = mapToSource(QPointF(event->pos())); + auto handlePan = [this](QPoint mousePos) { + m_x = mousePos.x() - m_mouseDownPosition.x(); + m_y = mousePos.y() - m_mouseDownPosition.y(); + clampPanPosition(); + updateUserViewport(); + }; + + if (event->buttons() & Qt::MiddleButton) { + handlePan(event->pos()); + } + switch (m_interactionMode) { case NoInteraction: case ElementPicking: @@ -1130,10 +1167,7 @@ void RemoteViewWidget::mouseMoveEvent(QMouseEvent *event) if (event->buttons() != Qt::LeftButton) { break; } - m_x = event->x() - m_mouseDownPosition.x(); - m_y = event->y() - m_mouseDownPosition.y(); - clampPanPosition(); - updateUserViewport(); + handlePan(event->pos()); break; case Measuring: if (event->buttons() & Qt::LeftButton) { @@ -1141,7 +1175,9 @@ void RemoteViewWidget::mouseMoveEvent(QMouseEvent *event) } break; case InputRedirection: - sendMouseEvent(event); + if (!(event->buttons() & Qt::MiddleButton)) { + sendMouseEvent(event); + } break; case ColorPicking: // label should be always fully inside the remoteviewwidget diff --git a/ui/remoteviewwidget.h b/ui/remoteviewwidget.h index 8c2a2fee68..22364bc25d 100644 --- a/ui/remoteviewwidget.h +++ b/ui/remoteviewwidget.h @@ -229,6 +229,7 @@ private slots: QPointF m_currentMousePosition; // in view coordinates QPoint m_measurementStartPosition; // in source coordinates QPoint m_measurementEndPosition; // in source coordinates + QCursor m_cursorBeforeMmbPan; bool m_hasMeasurement; ObjectIdsFilterProxyModel *m_pickProxyModel; VisibilityFilterProxyModel *m_invisibleItemsProxyModel;