forked from qt-creator/qt-creator
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 <mahmoud.badri@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -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<int> 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<QKeyEvent *>(event);
|
||||
if (controlKeys.contains(ke->key()))
|
||||
event->accept();
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void Edit3DCanvas::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
m_contextMenuPending = false;
|
||||
|
@@ -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;
|
||||
|
@@ -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<QKeySequence> 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()
|
||||
|
@@ -187,7 +187,6 @@ private:
|
||||
int m_activeSplit = 0;
|
||||
|
||||
QList<SplitToolState> m_splitToolStates;
|
||||
QList<Edit3DAction *> m_flyModeDisabledActions;
|
||||
ModelNode m_contextMenuPendingNode;
|
||||
ModelNode m_pickView3dNode;
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -221,6 +221,7 @@ private:
|
||||
double m_snapRotationInterval = 5.;
|
||||
double m_snapScaleInterval = .1;
|
||||
double m_cameraSpeed = 10.;
|
||||
double m_cameraSpeedModifier = 1.;
|
||||
|
||||
QVariant m_bgColor;
|
||||
};
|
||||
|
Reference in New Issue
Block a user