Skip to content

Commit

Permalink
Pan with Middle mouse button in remote view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MiKom committed Nov 26, 2022
1 parent 0a66386 commit 94ff1ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
48 changes: 42 additions & 6 deletions ui/remoteviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -1130,18 +1167,17 @@ 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) {
m_measurementEndPosition = mapToSource(event->pos());
}
break;
case InputRedirection:
sendMouseEvent(event);
if (!(event->buttons() & Qt::MiddleButton)) {
sendMouseEvent(event);
}
break;
case ColorPicking:
// label should be always fully inside the remoteviewwidget
Expand Down
1 change: 1 addition & 0 deletions ui/remoteviewwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94ff1ad

Please sign in to comment.