Pass all key events through the shortcutmap

This has to happen in QGuiApp, not QApp.

Change-Id: If8a6e81df3ae9b601733d077cce57d2d21572f74
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Lars Knoll 2011-10-13 09:47:23 +02:00 committed by Qt by Nokia
parent 6e7f08182e
commit 479f3c6b11
3 changed files with 20 additions and 16 deletions

View File

@ -512,6 +512,18 @@ int QGuiApplication::exec()
bool QGuiApplication::notify(QObject *object, QEvent *event) 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<QWindow *>(object);
QObject *focus = w ? w->focusObject() : 0;
if (!focus)
focus = object;
if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(focus, static_cast<QKeyEvent *>(event)))
return true;
}
#endif
return QCoreApplication::notify(object, event); return QCoreApplication::notify(object, event);
} }
@ -700,18 +712,10 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
if (!window) if (!window)
return; return;
QObject *target = window; QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount,
e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers);
if (e->nativeScanCode || e->nativeVirtualKey || e->nativeModifiers) { ev.setTimestamp(e->timestamp);
QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount, QGuiApplication::sendSpontaneousEvent(window, &ev);
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);
}
} }
void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e) void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)

View File

@ -53,6 +53,7 @@
#include "private/qwindowsysteminterface_qpa_p.h" #include "private/qwindowsysteminterface_qpa_p.h"
#include <QtGui/qplatformintegration_qpa.h> #include <QtGui/qplatformintegration_qpa.h>
#include <QtGui/qplatformtheme_qpa.h> #include <QtGui/qplatformtheme_qpa.h>
#include "private/qshortcutmap_p.h"
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -183,6 +184,9 @@ public:
static bool quitOnLastWindowClosed; static bool quitOnLastWindowClosed;
static QList<QObject *> generic_plugin_list; static QList<QObject *> generic_plugin_list;
#ifndef QT_NO_SHORTCUT
QShortcutMap shortcutMap;
#endif
private: private:
void init(); void init();

View File

@ -68,7 +68,6 @@
#include "QtCore/qhash.h" #include "QtCore/qhash.h"
#include "QtCore/qpointer.h" #include "QtCore/qpointer.h"
#include "private/qcoreapplication_p.h" #include "private/qcoreapplication_p.h"
#include "private/qshortcutmap_p.h"
#include <private/qthread_p.h> #include <private/qthread_p.h>
#include "QtCore/qpoint.h" #include "QtCore/qpoint.h"
#include <QTime> #include <QTime>
@ -367,9 +366,6 @@ public:
QBasicTimer toolTipWakeUp, toolTipFallAsleep; QBasicTimer toolTipWakeUp, toolTipFallAsleep;
QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos; QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
QPointer<QWidget> toolTipWidget; QPointer<QWidget> toolTipWidget;
#ifndef QT_NO_SHORTCUT
QShortcutMap shortcutMap;
#endif
static QInputContext *inputContext; static QInputContext *inputContext;