summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2016-06-18 09:09:00 +0100
committerMike Krus <mike.krus@kdab.com>2016-07-06 05:34:42 +0000
commit829e421ddcd5e8ff065eaece965f499d7d1d8b40 (patch)
treefc28ca5d879d95f63b563df09a97af1854c5fe0f /src/plugins
parentc9366c10bd2f1aef0c06866085383f1aff048009 (diff)
UIKit: Handle UIPress events
On tvOS the system will deliver UIPress events for touch gestures on the remote such as pressing up, down, left, or right, as well as for the dedicated hardware buttons, such as menu or play/pause. We deliver these as Qt key events when possible (the siri, volume and home button can't be handled). Change-Id: Id4bd4960e3036a7b8b67cf5b9e9d653f233dc4af Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/ios/quiview.mm53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm
index bf929667a6..9f910dfe5e 100644
--- a/src/plugins/platforms/ios/quiview.mm
+++ b/src/plugins/platforms/ios/quiview.mm
@@ -50,6 +50,7 @@
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qwindow_p.h>
+#include <qpa/qwindowsysteminterface_p.h>
@implementation QUIView
@@ -442,6 +443,58 @@
QWindowSystemInterface::flushWindowSystemEvents();
}
+- (int)mapPressTypeToKey:(UIPress*)press
+{
+ switch (press.type) {
+ case UIPressTypeUpArrow: return Qt::Key_Up;
+ case UIPressTypeDownArrow: return Qt::Key_Down;
+ case UIPressTypeLeftArrow: return Qt::Key_Left;
+ case UIPressTypeRightArrow: return Qt::Key_Right;
+ case UIPressTypeSelect: return Qt::Key_Select;
+ case UIPressTypeMenu: return Qt::Key_Menu;
+ case UIPressTypePlayPause: return Qt::Key_MediaTogglePlayPause;
+ }
+ return Qt::Key_unknown;
+}
+
+- (bool)processPresses:(NSSet *)presses withType:(QEvent::Type)type {
+ // Presses on Menu button will generate a Menu key event. By default, not handling
+ // this event will cause the application to return to Headboard (tvOS launcher).
+ // When handling the event (for example, as a back button), both press and
+ // release events must be handled accordingly.
+
+ QScopedValueRollback<bool> syncRollback(QWindowSystemInterfacePrivate::synchronousWindowSystemEvents, true);
+
+ bool handled = false;
+ for (UIPress* press in presses) {
+ int key = [self mapPressTypeToKey:press];
+ if (key == Qt::Key_unknown)
+ continue;
+ if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier))
+ handled = true;
+ }
+
+ return handled;
+}
+
+- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (![self processPresses:presses withType:QEvent::KeyPress])
+ [super pressesBegan:presses withEvent:event];
+}
+
+- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (![self processPresses:presses withType:QEvent::KeyPress])
+ [super pressesChanged:presses withEvent:event];
+}
+
+- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (![self processPresses:presses withType:QEvent::KeyRelease])
+ [super pressesEnded:presses withEvent:event];
+}
+
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
#ifndef Q_OS_TVOS