From 479f3c6b1124bc830ee60e764ea50d14db526f7e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 13 Oct 2011 09:47:23 +0200 Subject: [PATCH] Pass all key events through the shortcutmap MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This has to happen in QGuiApp, not QApp. Change-Id: If8a6e81df3ae9b601733d077cce57d2d21572f74 Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 28 ++++++++++++++++------------ src/gui/kernel/qguiapplication_p.h | 4 ++++ src/widgets/kernel/qapplication_p.h | 4 ---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 8f74e3d..1101764 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -512,6 +512,18 @@ int QGuiApplication::exec() bool QGuiApplication::notify(QObject *object, QEvent *event) { +#ifndef QT_NO_SHORTCUT + if (event->type() == QEvent::KeyPress) { + // Try looking for a Shortcut before sending key events + QWindow *w = qobject_cast(object); + QObject *focus = w ? w->focusObject() : 0; + if (!focus) + focus = object; + if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(focus, static_cast(event))) + return true; + } +#endif + return QCoreApplication::notify(object, event); } @@ -700,18 +712,10 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE if (!window) return; - QObject *target = window; - - if (e->nativeScanCode || e->nativeVirtualKey || e->nativeModifiers) { - QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount, - e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers); - ev.setTimestamp(e->timestamp); - QGuiApplication::sendSpontaneousEvent(target, &ev); - } else { - QKeyEvent ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount); - ev.setTimestamp(e->timestamp); - QGuiApplication::sendSpontaneousEvent(target, &ev); - } + QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount, + e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers); + ev.setTimestamp(e->timestamp); + QGuiApplication::sendSpontaneousEvent(window, &ev); } void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index af1c71d..255a158 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -53,6 +53,7 @@ #include "private/qwindowsysteminterface_qpa_p.h" #include #include +#include "private/qshortcutmap_p.h" QT_BEGIN_HEADER @@ -183,6 +184,9 @@ public: static bool quitOnLastWindowClosed; static QList generic_plugin_list; +#ifndef QT_NO_SHORTCUT + QShortcutMap shortcutMap; +#endif private: void init(); diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 77a02bd..d0674d4 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -68,7 +68,6 @@ #include "QtCore/qhash.h" #include "QtCore/qpointer.h" #include "private/qcoreapplication_p.h" -#include "private/qshortcutmap_p.h" #include #include "QtCore/qpoint.h" #include @@ -367,9 +366,6 @@ public: QBasicTimer toolTipWakeUp, toolTipFallAsleep; QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos; QPointer toolTipWidget; -#ifndef QT_NO_SHORTCUT - QShortcutMap shortcutMap; -#endif static QInputContext *inputContext; -- 2.7.4