Skip to content

Commit cf669cf

Browse files
committed
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.
1 parent 0a66386 commit cf669cf

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

ui/remoteviewwidget.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,15 @@ void RemoteViewWidget::mousePressEvent(QMouseEvent *event)
10291029
{
10301030
m_currentMousePosition = mapToSource(QPointF(event->pos()));
10311031

1032+
// Initiate the middle mouse button panning that works regarless of the interaction mode
1033+
if (event->button() == Qt::MiddleButton) {
1034+
m_mouseDownPosition = event->pos() - QPoint(m_x, m_y);
1035+
m_cursorBeforeMmbPan = cursor();
1036+
setCursor(Qt::ClosedHandCursor);
1037+
QWidget::mousePressEvent(event);
1038+
return;
1039+
}
1040+
10321041
switch (m_interactionMode) {
10331042
case NoInteraction:
10341043
break;
@@ -1075,12 +1084,29 @@ void RemoteViewWidget::mouseReleaseEvent(QMouseEvent *event)
10751084
{
10761085
m_currentMousePosition = mapToSource(QPointF(event->pos()));
10771086

1087+
if (event->button() == Qt::MiddleButton) {
1088+
// In view interaction, set the open hand cursor if the user hasn't
1089+
// initiated LMB panning in the meantime. Otherwise, bring back the
1090+
// original cursor.
1091+
if (m_interactionMode == ViewInteraction) {
1092+
if (!(event->buttons() & Qt::LeftButton)) {
1093+
setCursor(Qt::OpenHandCursor);
1094+
}
1095+
} else {
1096+
setCursor(m_cursorBeforeMmbPan);
1097+
}
1098+
QWidget::mouseReleaseEvent(event);
1099+
return;
1100+
}
1101+
10781102
switch (m_interactionMode) {
10791103
case NoInteraction:
10801104
case ElementPicking:
10811105
break;
10821106
case ViewInteraction:
1083-
setCursor(Qt::OpenHandCursor);
1107+
if (!(event->buttons() & Qt::MiddleButton)) {
1108+
setCursor(Qt::OpenHandCursor);
1109+
}
10841110
break;
10851111
case Measuring:
10861112
if (event->buttons() & Qt::LeftButton)
@@ -1122,6 +1148,17 @@ void RemoteViewWidget::mouseMoveEvent(QMouseEvent *event)
11221148
{
11231149
m_currentMousePosition = mapToSource(QPointF(event->pos()));
11241150

1151+
auto handlePan = [this](QPoint mousePos) {
1152+
m_x = mousePos.x() - m_mouseDownPosition.x();
1153+
m_y = mousePos.y() - m_mouseDownPosition.y();
1154+
clampPanPosition();
1155+
updateUserViewport();
1156+
};
1157+
1158+
if (event->buttons() & Qt::MiddleButton) {
1159+
handlePan(event->pos());
1160+
}
1161+
11251162
switch (m_interactionMode) {
11261163
case NoInteraction:
11271164
case ElementPicking:
@@ -1130,18 +1167,17 @@ void RemoteViewWidget::mouseMoveEvent(QMouseEvent *event)
11301167
if (event->buttons() != Qt::LeftButton) {
11311168
break;
11321169
}
1133-
m_x = event->x() - m_mouseDownPosition.x();
1134-
m_y = event->y() - m_mouseDownPosition.y();
1135-
clampPanPosition();
1136-
updateUserViewport();
1170+
handlePan(event->pos());
11371171
break;
11381172
case Measuring:
11391173
if (event->buttons() & Qt::LeftButton) {
11401174
m_measurementEndPosition = mapToSource(event->pos());
11411175
}
11421176
break;
11431177
case InputRedirection:
1144-
sendMouseEvent(event);
1178+
if (!(event->buttons() & Qt::MiddleButton)) {
1179+
sendMouseEvent(event);
1180+
}
11451181
break;
11461182
case ColorPicking:
11471183
// label should be always fully inside the remoteviewwidget

ui/remoteviewwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ private slots:
229229
QPointF m_currentMousePosition; // in view coordinates
230230
QPoint m_measurementStartPosition; // in source coordinates
231231
QPoint m_measurementEndPosition; // in source coordinates
232+
QCursor m_cursorBeforeMmbPan;
232233
bool m_hasMeasurement;
233234
ObjectIdsFilterProxyModel *m_pickProxyModel;
234235
VisibilityFilterProxyModel *m_invisibleItemsProxyModel;

0 commit comments

Comments
 (0)