Fix shortcut handling with modifiers

Since d7ca800a87 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>
This commit is contained in:
Frederik Gladhorn 2015-07-14 18:31:03 +02:00
parent 771235285c
commit 4067bbc24c
4 changed files with 32 additions and 4 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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,

View File

@ -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) {