From dc35a7fd3acd454563b418ed187523cc2f640d59 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 25 Apr 2024 15:09:18 +0300 Subject: [PATCH] QmlDesigner: Add Shift and Alt modifiers to fly mode While in fly mode, Shift will speed up the WASD/QE movement by 100% and Alt will slow it down 50%. Also changed how shortcuts are disabled in fly mode. ShortcutOverride events are now used to suppress conflicting shortcuts, which has the advantage over old method as it will also suppress application global shortcuts (such as Alt key moving focus to application menu). Task-number: QDS-12291 Change-Id: I5c97d10b6f8955f3b3214e8e254a80cae7357ce5 Reviewed-by: Mahmoud Badri Reviewed-by: Qt CI Patch Build Bot --- .../components/edit3d/edit3dcanvas.cpp | 19 ++++++++++++++ .../components/edit3d/edit3dcanvas.h | 1 + .../components/edit3d/edit3dview.cpp | 26 ------------------- .../components/edit3d/edit3dview.h | 1 - .../mockfiles/qt6/EditCameraController.qml | 15 ++++++++++- .../qml2puppet/editor3d/generalhelper.h | 1 + 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.cpp index 2e8ef8304f6..ef2e2ee7b56 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.cpp @@ -51,6 +51,8 @@ Edit3DCanvas::Edit3DCanvas(Edit3DWidget *parent) setAcceptDrops(true); setFocusPolicy(Qt::ClickFocus); m_busyIndicator->show(); + + installEventFilter(this); } void Edit3DCanvas::updateRenderImage(const QImage &img) @@ -132,6 +134,23 @@ void Edit3DCanvas::setFlyMode(bool enabled, const QPoint &pos) m_parent->view()->setFlyMode(enabled); } +bool Edit3DCanvas::eventFilter(QObject *obj, QEvent *event) +{ + if (m_flyMode && event->type() == QEvent::ShortcutOverride) { + // Suppress shortcuts that conflict with fly mode keys + const QList controlKeys = { Qt::Key_W, Qt::Key_A, Qt::Key_S, + Qt::Key_D, Qt::Key_Q, Qt::Key_E, + Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, + Qt::Key_Right, Qt::Key_PageDown, Qt::Key_PageUp, + Qt::Key_Alt, Qt::Key_Shift }; + auto ke = static_cast(event); + if (controlKeys.contains(ke->key())) + event->accept(); + } + + return QObject::eventFilter(obj, event); +} + void Edit3DCanvas::mousePressEvent(QMouseEvent *e) { m_contextMenuPending = false; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.h b/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.h index 39207554a73..7f043520b33 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dcanvas.h @@ -30,6 +30,7 @@ public: bool isFlyMode() const { return m_flyMode; } protected: + bool eventFilter(QObject *obj, QEvent *event) override; void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void mouseDoubleClickEvent(QMouseEvent *e) override; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index 4712b048b14..c7d70d4b8af 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -736,32 +736,6 @@ void Edit3DView::showContextMenu() void Edit3DView::setFlyMode(bool enabled) { emitView3DAction(View3DActionType::FlyModeToggle, enabled); - - // Disable any actions with conflicting hotkeys - if (enabled) { - m_flyModeDisabledActions.clear(); - const QList controlKeys = { Qt::Key_W, Qt::Key_A, Qt::Key_S, - Qt::Key_D, Qt::Key_Q, Qt::Key_E, - Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, - Qt::Key_Right, Qt::Key_PageDown, Qt::Key_PageUp}; - for (auto i = m_edit3DActions.cbegin(), end = m_edit3DActions.cend(); i != end; ++i) { - for (const QKeySequence &controlKey : controlKeys) { - if (Core::Command *cmd = m_edit3DWidget->actionToCommandHash().value(i.value()->action())) { - if (cmd->keySequence().matches(controlKey) == QKeySequence::ExactMatch) { - if (i.value()->action()->isEnabled()) { - m_flyModeDisabledActions.append(i.value()); - i.value()->action()->setEnabled(false); - } - break; - } - } - } - } - } else { - for (Edit3DAction *action : std::as_const(m_flyModeDisabledActions)) - action->action()->setEnabled(true); - m_flyModeDisabledActions.clear(); - } } void Edit3DView::syncSnapAuxPropsToSettings() diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.h b/src/plugins/qmldesigner/components/edit3d/edit3dview.h index ade2ef6a8f9..918df3c6f98 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.h @@ -187,7 +187,6 @@ private: int m_activeSplit = 0; QList m_splitToolStates; - QList m_flyModeDisabledActions; ModelNode m_contextMenuPendingNode; ModelNode m_pickView3dNode; diff --git a/src/tools/qml2puppet/mockfiles/qt6/EditCameraController.qml b/src/tools/qml2puppet/mockfiles/qt6/EditCameraController.qml index 255d93e5295..509273901a4 100644 --- a/src/tools/qml2puppet/mockfiles/qt6/EditCameraController.qml +++ b/src/tools/qml2puppet/mockfiles/qt6/EditCameraController.qml @@ -29,6 +29,7 @@ Item { readonly property real _keyPanAmount: _generalHelper.cameraSpeed property bool ignoreToolState: false property bool flyMode: viewRoot.flyMode + property real _cameraSpeedModifier: 1 z: 10 anchors.fill: parent @@ -244,6 +245,7 @@ Item { cameraCtrl.storeCameraState(0); } _generalHelper.stopAllCameraMoves() + cameraCtrl._cameraSpeedModifier = 1 } Connections { @@ -251,7 +253,7 @@ Item { enabled: viewRoot.activeSplit === cameraCtrl.splitId function onRequestCameraMove(camera, moveVec) { if (camera === cameraCtrl.camera) { - cameraCtrl.moveCamera(moveVec); + cameraCtrl.moveCamera(moveVec.times(_cameraSpeedModifier)); _generalHelper.requestRender(); } } @@ -326,7 +328,17 @@ Item { } } + function setCameraSpeed(event) { + if (event.modifiers === Qt.AltModifier) + cameraCtrl._cameraSpeedModifier = 0.5 + else if (event.modifiers === Qt.ShiftModifier) + cameraCtrl._cameraSpeedModifier = 2 + else + cameraCtrl._cameraSpeedModifier = 1 + } + Keys.onPressed: (event) => { + setCameraSpeed(event) event.accepted = true; if (cameraCtrl.flyMode && event.key === Qt.Key_Space) approachObject(); @@ -335,6 +347,7 @@ Item { } Keys.onReleased: (event) => { + setCameraSpeed(event) event.accepted = true; _generalHelper.stopCameraMove(cameraCtrl.getMoveVectorForKey(event.key)); } diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h index 62a95d86a6f..558e0363df2 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h @@ -221,6 +221,7 @@ private: double m_snapRotationInterval = 5.; double m_snapScaleInterval = .1; double m_cameraSpeed = 10.; + double m_cameraSpeedModifier = 1.; QVariant m_bgColor; };