summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@digia.com>2013-04-23 10:47:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 15:30:48 +0100
commitfc98d027c00aeff0dc8062492683e4952126bb1b (patch)
tree5af4bcc88ce6a58369af3ab73f0655efcdea2886
parent472e448d6a71f679dd022f7405564c42d8f47916 (diff)
Android: handle keyPress event for Key_Back
Added logic so that accepting either the press or the release will keep the app running. This makes it possible to use the onBackPressed functionality in QML. This functionality is only intended for running in a complete Android environment, so make sure that we don't terminate the application in the NO_SDK case. Task-number: QTBUG-30803 Change-Id: I2546eea73bf6a6ee8b196125b7556479b9b10a9c Reviewed-by: BogDan Vatra <bogdan@kde.org>
-rw-r--r--src/gui/kernel/qguiapplication.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index d254f7c9bc..2e6000625e 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1666,41 +1666,36 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
QWindow *window = e->window.data();
modifier_buttons = e->modifiers;
if (e->nullWindow
-#ifdef Q_OS_ANDROID
- || (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back) || e->key == Qt::Key_Menu
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
+ || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
#endif
) {
window = QGuiApplication::focusWindow();
}
- if (!window
-#ifdef Q_OS_ANDROID
- && e->keyType != QEvent::KeyRelease && e->key != Qt::Key_Back
-#endif
- ) {
- return;
- }
- if (window && window->d_func()->blockedByModalWindow) {
- // a modal window is blocking this window, don't allow key events through
- return;
- }
QKeyEvent ev(e->keyType, e->key, e->modifiers,
e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
e->unicode, e->repeat, e->repeatCount);
ev.setTimestamp(e->timestamp);
-#ifdef Q_OS_ANDROID
- if (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back) {
- if (!window) {
+ // only deliver key events when we have a window, and no modal window is blocking this window
+
+ if (window && !window->d_func()->blockedByModalWindow)
+ QGuiApplication::sendSpontaneousEvent(window, &ev);
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
+ else
+ ev.setAccepted(false);
+
+ static bool backKeyPressAccepted = false;
+ if (e->keyType == QEvent::KeyPress) {
+ backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
+ } else if (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
+ if (!window)
qApp->quit();
- } else {
- QGuiApplication::sendEvent(window, &ev);
- if (!ev.isAccepted() && e->key == Qt::Key_Back)
- QWindowSystemInterface::handleCloseEvent(window);
- }
- } else
+ else
+ QWindowSystemInterface::handleCloseEvent(window);
+ }
#endif
- QGuiApplication::sendSpontaneousEvent(window, &ev);
}
void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)