diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-09-04 17:56:20 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-10-07 13:24:45 +0000 |
commit | c7e5e1d9e01849347a9e59b8285477a20d82002b (patch) | |
tree | 3e53068d1b421f935905cb4b60b29ed94cd0457a /src/gui/kernel/qevent.cpp | |
parent | 590c73bee2083c8dc8635123726e138a26dd3a97 (diff) |
Move shortcut handling back into QPA and simplify delivery
Commit 7f5b94b47 moved shortcut handling into QGuiApplication (for all
platforms except OS X), due to crashes on Android where the events are
delivered from another thread.
Now that we have synchronous event delivery (also across threads) from
QPA, this is no longer needed, and we can move the code back to QPA,
where the platform has more control over when and how shortcut events
are delivered in relation to normal key events.
Handling shortcuts is as before a two step process. We first send a
QKeyEvent::ShortcutOverride event to the active window, which allows
clients (widgets e.g.) to signal that they want to handle the shortcut
themselves. If the override event is accepted, we treat it as the
shortcut not being handled as a regular shortcut, and send the event
as a key press instead, allowing the widget to handle the shortcut.
If nothing accepted the shortcut override event we pass it along to
the global shortcut map, which will treat the event as handled if
an exact or partial match is found.
The QShortcutMap::tryShortcutEvent() and nextState() implementation
has been simplified to not use the events accepted state for its
internal operation, which removes the need for saving the state
of the incoming event.
The QKeyEvent::ShortcutOverride event was also always sent with
the accepted state set to false, by calling ignore() on it before
sending it. This is now explicit by having shortcut override
events being ignored by default in their constructor, and the
documentation has been updated accordingly.
Change-Id: I9afa29dbc00bef09fd22ee6bf09661b06340d715
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel/qevent.cpp')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 780a102644..0bb21752bc 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1029,8 +1029,10 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, when keys are pressed or released. A key event contains a special accept flag that indicates whether - the receiver will handle the key event. This flag is set by default, - so there is no need to call accept() when acting on a key event. + the receiver will handle the key event. This flag is set by default + for QEvent::KeyPress and QEvent::KeyRelease, so there is no need to + call accept() when acting on a key event. For QEvent::ShortcutOverride + the receiver needs to explicitly accept the event to trigger the override. Calling ignore() on a key event will propagate it to the parent widget. The event is propagated up the parent widget chain until a widget accepts it or an event filter consumes it. @@ -1065,6 +1067,8 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const nScanCode(0), nVirtualKey(0), nModifiers(0), c(count), autor(autorep) { + if (type == QEvent::ShortcutOverride) + ignore(); } /*! @@ -1092,6 +1096,8 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers), c(count), autor(autorep) { + if (type == QEvent::ShortcutOverride) + ignore(); } |