[PATCH] Allow the app to filter the back key even at the top level
Dirk Hohndel
dirk at hohndel.org
Sun Feb 14 05:41:13 UTC 2016
The onBackRequested trick didn't work on the top level page. Which seems
odd to me - why shouldn't an application be allowed to prevent the back
key from exiting?
In my case we have a slightly odd design (ask sebas why we ended up with
that - he wrote it) where the top page actually morphs into two "states",
one of which is a start page where the user enters credentials, the other
one is the main view of the app once credentials were entered.
Now imagine we want to allow the user to change credentials. Simple,
right? Just go back to the other incarnation of that top page. But how do
you change your mind and go back? Easy again. Hit the back button.
Oops. You just quit your application.
The patch below fixes that.
/D
>From 8381291d8b82a815691290bb75fe6cba3b4e08c0 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk at hohndel.org>
Date: Sat, 13 Feb 2016 21:00:13 -0800
Subject: [PATCH 3/3] Allow the app to filter the back key even at the top
level
There's no reason why the application shouldn't be able to prevent the
user from exiting with the back key.
Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
components/mobilecomponents/qml/ApplicationWindow.qml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/components/mobilecomponents/qml/ApplicationWindow.qml b/components/mobilecomponents/qml/ApplicationWindow.qml
index ff6b1618a55e..1ed25e6dc640 100644
--- a/components/mobilecomponents/qml/ApplicationWindow.qml
+++ b/components/mobilecomponents/qml/ApplicationWindow.qml
@@ -72,11 +72,15 @@ ApplicationWindow {
root.contextDrawer.close();
} else if (root.globalDrawer && root.globalDrawer.opened) {
root.globalDrawer.close();
- } else if (__pageStack.depth > 1) {
+ } else if (__pageStack.depth >= 1) {
var backEvent = {accepted: false}
__pageStack.lastVisiblePage.backRequested(backEvent);
if (!backEvent.accepted) {
- __pageStack.pop();
+ if (__pageStack.depth > 1) {
+ __pageStack.pop();
+ } else {
+ Qt.quit();
+ }
}
} else {
Qt.quit();
--
2.7.0
More information about the Plasma-devel
mailing list