summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Guichard <nicolas.guichard@kdab.com>2020-07-24 14:07:00 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-08-20 19:44:09 +0000
commitf999d2c34e32909b0299c48c021609ed620942b5 (patch)
treefbd9a027c4785f6f6fd321e8f5c372767d978e8d
parent880096d084b73847bed291c5ab0f66813a6c06ae (diff)
downloadqtbase-f999d2c34e32909b0299c48c021609ed620942b5.tar.gz
QGuiApplication: fix handling of spontaneous events' modifiers
QtQuickTest synthetized events can have modifiers, but those modifiers were not accessible globally, from QGuiApplication::keyboardModifiers for instance. eg. calling QML's TestCase::mouseClick with modifiers triggering a call to QGuiApplication::keyboardModifiers did not give the expected result. QtTest synthesised events can also have modifiers and those were correctly handled by QApplication to set modifiers globally. This fix moves the handling code from QApplication::notify to QGuiApplicationPrivate::maybeSimulateModifiers and calls this function from QGuiApplication::notify too. The definite fix would be to do as suggested in the comment attached to the moved code: > Qt Test should not call qapp->notify(), but rather route the events > through the proper QPA interface. This is required to properly > generate all other events such as enter/leave etc. Change-Id: I734e5bbc82232b13828b1a1f82e06ee8eb695417 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 4b1ffab8ad95eda737fde015c243442a28de8e23) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/gui/kernel/qguiapplication.cpp56
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--src/widgets/kernel/qapplication.cpp54
3 files changed, 58 insertions, 53 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index f603419161..239a78313c 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1867,6 +1867,60 @@ int QGuiApplication::exec()
return QCoreApplication::exec();
}
+void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
+{
+ if (e->spontaneous()) {
+ // Capture the current mouse and keyboard states. Doing so here is
+ // required in order to support Qt Test synthesized events. Real mouse
+ // and keyboard state updates from the platform plugin are managed by
+ // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
+ // ### FIXME: Qt Test should not call qapp->notify(), but rather route
+ // the events through the proper QPA interface. This is required to
+ // properly generate all other events such as enter/leave etc.
+ switch (e->type()) {
+ case QEvent::MouseButtonPress: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons |= me->button();
+ break;
+ }
+ case QEvent::MouseButtonDblClick: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons |= me->button();
+ break;
+ }
+ case QEvent::MouseButtonRelease: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons &= ~me->button();
+ break;
+ }
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ case QEvent::MouseMove:
+#if QT_CONFIG(wheelevent)
+ case QEvent::Wheel:
+#endif
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+#if QT_CONFIG(tabletevent)
+ case QEvent::TabletMove:
+ case QEvent::TabletPress:
+ case QEvent::TabletRelease:
+#endif
+ {
+ QInputEvent *ie = static_cast<QInputEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
/*! \reimp
*/
bool QGuiApplication::notify(QObject *object, QEvent *event)
@@ -1876,6 +1930,8 @@ bool QGuiApplication::notify(QObject *object, QEvent *event)
return true; // Platform plugin ate the event
}
+ QGuiApplicationPrivate::captureGlobalModifierState(event);
+
return QCoreApplication::notify(object, event);
}
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 855b369640..261add1ba4 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -100,6 +100,7 @@ public:
bool shouldQuitInternal(const QWindowList &processedWindows);
virtual bool tryCloseAllWindows();
+ static void captureGlobalModifierState(QEvent *e);
static Qt::KeyboardModifiers modifier_buttons;
static Qt::MouseButtons mouse_buttons;
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 849805231c..0375531960 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2873,59 +2873,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
return true; // Platform plugin ate the event
}
- if(e->spontaneous()) {
- // Capture the current mouse and keyboard states. Doing so here is
- // required in order to support Qt Test synthesized events. Real mouse
- // and keyboard state updates from the platform plugin are managed by
- // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
- // ### FIXME: Qt Test should not call qapp->notify(), but rather route
- // the events through the proper QPA interface. This is required to
- // properly generate all other events such as enter/leave etc.
- switch (e->type()) {
- case QEvent::MouseButtonPress:
- {
- QMouseEvent *me = static_cast<QMouseEvent*>(e);
- QApplicationPrivate::modifier_buttons = me->modifiers();
- QApplicationPrivate::mouse_buttons |= me->button();
- break;
- }
- case QEvent::MouseButtonDblClick:
- {
- QMouseEvent *me = static_cast<QMouseEvent*>(e);
- QApplicationPrivate::modifier_buttons = me->modifiers();
- QApplicationPrivate::mouse_buttons |= me->button();
- break;
- }
- case QEvent::MouseButtonRelease:
- {
- QMouseEvent *me = static_cast<QMouseEvent*>(e);
- QApplicationPrivate::modifier_buttons = me->modifiers();
- QApplicationPrivate::mouse_buttons &= ~me->button();
- break;
- }
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- case QEvent::MouseMove:
-#if QT_CONFIG(wheelevent)
- case QEvent::Wheel:
-#endif
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
-#if QT_CONFIG(tabletevent)
- case QEvent::TabletMove:
- case QEvent::TabletPress:
- case QEvent::TabletRelease:
-#endif
- {
- QInputEvent *ie = static_cast<QInputEvent*>(e);
- QApplicationPrivate::modifier_buttons = ie->modifiers();
- break;
- }
- default:
- break;
- }
- }
+ QGuiApplicationPrivate::captureGlobalModifierState(e);
#ifndef QT_NO_GESTURES
// walk through parents and check for gestures