QmlDesigner: Fix fly mode speed on macOS

Task-number: QDS-12337
Change-Id: I7590cd79a8d3b0b27cad7edb5e11be091223b6fb
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Shrief Gabr
2024-04-12 16:38:30 +03:00
committed by Miikka Heikkinen
parent af6dcb6659
commit 465a2e7ac4
2 changed files with 18 additions and 2 deletions

View File

@@ -81,11 +81,20 @@ QWidget *Edit3DCanvas::busyIndicator() const
return m_busyIndicator;
}
#ifdef Q_OS_MACOS
extern "C" bool AXIsProcessTrusted();
#endif
void Edit3DCanvas::setFlyMode(bool enabled, const QPoint &pos)
{
if (m_flyMode == enabled)
return;
#ifdef Q_OS_MACOS
if (!AXIsProcessTrusted())
m_isTrusted = false;
#endif
m_flyMode = enabled;
if (enabled) {
@@ -190,7 +199,8 @@ void Edit3DCanvas::mouseMoveEvent(QMouseEvent *e)
// We notify explicit camera rotation need for puppet rather than rely in mouse events,
// as mouse isn't grabbed on puppet side and can't handle fast movements that go out of
// edit camera mouse area. This also simplifies split view handling.
QPointF diff = m_hiddenCursorPos - e->globalPos();
QPointF diff = m_isTrusted ? (m_hiddenCursorPos - e->globalPos()) : (m_lastCursorPos - e->globalPos());
if (e->buttons() == (Qt::LeftButton | Qt::RightButton)) {
m_parent->view()->emitView3DAction(View3DActionType::EditCameraMove,
QVector3D{float(-diff.x()), float(-diff.y()), 0.f});
@@ -201,7 +211,11 @@ void Edit3DCanvas::mouseMoveEvent(QMouseEvent *e)
// Skip first move to avoid undesirable jump occasionally when initiating flight mode
m_flyModeFirstUpdate = false;
}
QCursor::setPos(m_hiddenCursorPos);
if (m_isTrusted)
QCursor::setPos(m_hiddenCursorPos);
else
m_lastCursorPos = e->globalPos();
}
}

View File

@@ -53,10 +53,12 @@ private:
qint32 m_activeScene = -1;
QElapsedTimer m_usageTimer;
qreal m_opacity = 1.0;
bool m_isTrusted = true;
QWidget *m_busyIndicator = nullptr;
bool m_flyMode = false;
QPoint m_flyModeStartCursorPos;
QPoint m_hiddenCursorPos;
QPoint m_lastCursorPos;
qint64 m_flyModeStartTime = 0;
bool m_flyModeFirstUpdate = false;
bool m_contextMenuPending = false;