diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-06-01 16:37:05 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-06-01 15:04:45 +0000 |
commit | 9851f6cada7228aea14e356e0353f896973fd1bb (patch) | |
tree | 739aab328871272ad3048ce1b24044ba4f514a03 | |
parent | b13294bc39a1759e55e057e0e73f998bf1347450 (diff) |
Fix other mouse buttons from interfering with drag-adjust of floats
Install an event filter that blocks all mouse button events for other
buttons than the left button for the duration of the drag. Key events
and shortcut overrides are also blocked.
Task-number: QT3DS-565
Change-Id: Idbc03eae5e4e4e0718ebdd43066f58275bd5f44f
Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
3 files changed, 34 insertions, 0 deletions
diff --git a/src/Authoring/Studio/Palettes/Inspector/MouseHelper.cpp b/src/Authoring/Studio/Palettes/Inspector/MouseHelper.cpp index 9686a195..947f957e 100644 --- a/src/Authoring/Studio/Palettes/Inspector/MouseHelper.cpp +++ b/src/Authoring/Studio/Palettes/Inspector/MouseHelper.cpp @@ -35,6 +35,7 @@ #include <QtGui/qscreen.h> #include <QtWidgets/qmainwindow.h> #include <QtCore/qtimer.h> +#include <QtGui/qevent.h> MouseHelper::MouseHelper(QObject *parent) : QObject(parent) @@ -55,6 +56,7 @@ void MouseHelper::startUnboundedDrag() QWindow *window = g_StudioApp.m_pMainWnd->windowHandle(); if (window) { + window->installEventFilter(this); QSize screenSize = window->screen()->size() / window->screen()->devicePixelRatio(); m_referencePoint = QPoint(screenSize.width() / 2, screenSize.height() / 2); } else { @@ -68,6 +70,9 @@ void MouseHelper::startUnboundedDrag() void MouseHelper::endUnboundedDrag() { + QWindow *window = g_StudioApp.m_pMainWnd->windowHandle(); + if (window) + window->removeEventFilter(this); m_dragState = StateEndingDrag; m_cursorResetTimer.start(); } @@ -117,3 +122,28 @@ void MouseHelper::resetCursor() } } +bool MouseHelper::eventFilter(QObject *obj, QEvent *event) +{ + Q_UNUSED(obj) + + // Eat all mouse button events that are not for left button and all key events + switch (event->type()) { + case QEvent::MouseButtonDblClick: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: { + QMouseEvent *me = static_cast<QMouseEvent *>(event); + if (me->button() == Qt::LeftButton) + return false; + else + return true; + } + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::ShortcutOverride: + return true; + default: + break; + } + return false; +} + diff --git a/src/Authoring/Studio/Palettes/Inspector/MouseHelper.h b/src/Authoring/Studio/Palettes/Inspector/MouseHelper.h index 2bbb973f..3e87bd78 100644 --- a/src/Authoring/Studio/Palettes/Inspector/MouseHelper.h +++ b/src/Authoring/Studio/Palettes/Inspector/MouseHelper.h @@ -47,6 +47,9 @@ public: private Q_SLOTS: void resetCursor(); +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + private: QPoint m_startPos; QPoint m_referencePoint; diff --git a/src/Authoring/Studio/Palettes/controls/FloatTextField.qml b/src/Authoring/Studio/Palettes/controls/FloatTextField.qml index c920cbdb..03e0cf48 100644 --- a/src/Authoring/Studio/Palettes/controls/FloatTextField.qml +++ b/src/Authoring/Studio/Palettes/controls/FloatTextField.qml @@ -103,6 +103,7 @@ TextField { property int pressedX: 0 property bool draggingActive: false + acceptedButtons: Qt.LeftButton preventStealing: true anchors.fill: parent onPressed: { |