summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-07-14 18:31:03 +0200
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-08-05 16:15:05 +0000
commit4067bbc24cf7a6d3058387225d9e67ad093991cd (patch)
tree2e9a6dae92d646d5b1e7050b9ddb4224ff2bf5f7
parent771235285c5306dd385fbd0be64ab4120a916e1c (diff)
Fix shortcut handling with modifiers
Since d7ca800a87a2291c94c6580f0cfe068bb2280caf the shortcut events were only sent once. The one sent by QGuiApplication did not create a QKeyEvent with the full native modifier state - basically the extended key event expected everywhere. That means that shortcuts on some keyboard layouts - like ctrl-shift-7 on the German keyboard (resulting in ctrl+/) - would not work when the shortcut override was tested from QGuiApplication, but then the same shortcut was sent from QApplication with the full information, so it worked the second time. Shortcuts of this type in Qt Quick were broken before. Task-number: QTBUG-47062 Change-Id: I8390b9a96d0d998a2a538ac65503702e0d299cc7 Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com> Reviewed-by: Gatis Paeglis <gatis.paeglis@digia.com>
-rw-r--r--src/gui/kernel/qguiapplication.cpp10
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp16
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h2
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm8
4 files changed, 32 insertions, 4 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 8ebddf33a6..654567e7df 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1884,8 +1884,14 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
#if !defined(Q_OS_OSX)
// On OS X the shortcut override is checked earlier, see: QWindowSystemInterface::handleKeyEvent()
const bool checkShortcut = e->keyType == QEvent::KeyPress && window != 0;
- if (checkShortcut && QWindowSystemInterface::tryHandleShortcutEvent(window, e->timestamp, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount))
- return;
+ if (checkShortcut) {
+ QKeyEvent override(QEvent::ShortcutOverride, e->key, e->modifiers,
+ e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
+ e->unicode, e->repeat, e->repeatCount);
+ override.setTimestamp(e->timestamp);
+ if (QWindowSystemInterface::tryHandleShortcutOverrideEvent(window, &override))
+ return;
+ }
#endif // Q_OS_OSX
QKeyEvent ev(e->keyType, e->key, e->modifiers,
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index b17978cb7d..9a9eab2fe7 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -225,6 +225,22 @@ bool QWindowSystemInterface::tryHandleShortcutEvent(QWindow *w, ulong timestamp,
#endif
}
+bool QWindowSystemInterface::tryHandleShortcutOverrideEvent(QWindow *w, QKeyEvent *ev)
+{
+#ifndef QT_NO_SHORTCUT
+ Q_ASSERT(ev->type() == QKeyEvent::ShortcutOverride);
+
+ QObject *focus = w->focusObject();
+ if (!focus)
+ focus = w;
+ return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(focus, ev);
+#else
+ Q_UNUSED(w)
+ Q_UNUSED(ev)
+ return false;
+#endif
+}
+
// used by QTestLib to directly send shortcuts to objects
bool QWindowSystemInterface::tryHandleShortcutEventToObject(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods,
const QString &text, bool autorep, ushort count)
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index c004fc6ef2..448c5d0893 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -78,6 +78,8 @@ public:
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
+ static bool tryHandleShortcutOverrideEvent(QWindow *w, QKeyEvent *ev);
+
static bool tryHandleShortcutEvent(QWindow *w, int k, Qt::KeyboardModifiers mods,
const QString & text = QString(), bool autorep = false, ushort count = 1);
static bool tryHandleShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods,
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 456c9d8c68..d802a36676 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1430,8 +1430,12 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
if (eventType == QEvent::KeyPress) {
- if (m_composingText.isEmpty())
- m_sendKeyEvent = !QWindowSystemInterface::tryHandleShortcutEvent(focusWindow, timestamp, keyCode, modifiers, text, [nsevent isARepeat], 1);
+ if (m_composingText.isEmpty()) {
+ QKeyEvent override(QEvent::ShortcutOverride, keyCode, modifiers,
+ nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1);
+ override.setTimestamp(timestamp);
+ m_sendKeyEvent = !QWindowSystemInterface::tryHandleShortcutOverrideEvent(focusWindow, &override);
+ }
QObject *fo = QGuiApplication::focusObject();
if (m_sendKeyEvent && fo) {