From b2363a935c8dac2c332c79d4c10c99be89656047 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 22 Mar 2012 17:43:25 +0100 Subject: Fix QGuiApplication::keyboardModifiers() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that the keybaord modifiers are maintained properly when handling window system events. Change-Id: Ie75cbe5eb509c29e3d2291694f2de509fbf3098a Reviewed-by: Morten Johan Sørvig Reviewed-by: Friedemann Kleint --- src/gui/kernel/qguiapplication.cpp | 4 ++++ src/gui/kernel/qwindowsysteminterface_qpa.cpp | 4 ++++ src/widgets/kernel/qapplication.cpp | 22 +--------------------- 3 files changed, 9 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index e12183869a..5a95ebe848 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1005,6 +1005,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo } QWindow *window = e->window.data(); + modifier_buttons = e->modifiers; if (!window) window = QGuiApplication::topLevelAt(e->globalPos.toPoint()); @@ -1107,6 +1108,7 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh QPointF globalPoint = e->globalPos; QGuiApplicationPrivate::lastCursorPosition = globalPoint; + modifier_buttons = e->modifiers; QWindow *window = e->window.data(); @@ -1123,6 +1125,7 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e) { QWindow *window = e->window.data(); + modifier_buttons = e->modifiers; if (e->nullWindow) window = QGuiApplication::activeWindow(); if (!window) @@ -1280,6 +1283,7 @@ Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e) { QGuiApplicationPrivate *d = self; + modifier_buttons = e->modifiers; if (e->touchType == QEvent::TouchCancel) { // The touch sequence has been canceled (e.g. by the compositor). diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 1953ce47bb..0aa9251642 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -158,6 +158,8 @@ bool QWindowSystemInterface::tryHandleSynchronousShortcutEvent(QWindow *w, int k bool QWindowSystemInterface::tryHandleSynchronousShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) { + QGuiApplicationPrivate::modifier_buttons = mods; + QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count); qevent.setTimestamp(timestamp); return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent); @@ -175,6 +177,8 @@ bool QWindowSystemInterface::tryHandleSynchronousExtendedShortcutEvent(QWindow * quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text, bool autorep, ushort count) { + QGuiApplicationPrivate::modifier_buttons = mods; + QKeyEventEx qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count, nativeScanCode, nativeVirtualKey, nativeModifiers); qevent.setTimestamp(timestamp); return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent); diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index ce57e2868d..2615ac891d 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3014,34 +3014,14 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // capture the current mouse/keyboard state if(e->spontaneous()) { - if (e->type() == QEvent::KeyPress - || e->type() == QEvent::KeyRelease) { - QKeyEvent *ke = static_cast(e); - QApplicationPrivate::modifier_buttons = ke->modifiers(); - } else if(e->type() == QEvent::MouseButtonPress + if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease) { QMouseEvent *me = static_cast(e); - QApplicationPrivate::modifier_buttons = me->modifiers(); if(me->type() == QEvent::MouseButtonPress) QApplicationPrivate::mouse_buttons |= me->button(); else QApplicationPrivate::mouse_buttons &= ~me->button(); } -#if !defined(QT_NO_WHEELEVENT) || !defined(QT_NO_TABLETEVENT) - else if (false -# ifndef QT_NO_WHEELEVENT - || e->type() == QEvent::Wheel -# endif -# ifndef QT_NO_TABLETEVENT - || e->type() == QEvent::TabletMove - || e->type() == QEvent::TabletPress - || e->type() == QEvent::TabletRelease -# endif - ) { - QInputEvent *ie = static_cast(e); - QApplicationPrivate::modifier_buttons = ie->modifiers(); - } -#endif // !QT_NO_WHEELEVENT || !QT_NO_TABLETEVENT } #ifndef QT_NO_GESTURES -- cgit v1.2.3