On Sat, Feb 06, 2016 at 07:38:12AM -0800, Dirk Hohndel wrote: > On Sat, Feb 06, 2016 at 04:01:01PM +0100, k...@privat.broulik.de wrote: > > > > in the apps I wrote I have a onBackRequested signal on my Page class which > > can also be used to reject the back button event (eg. event.accepted = > > false); I think something like this could be added to Plasma Mobile > > Components, too. > > That may be just beyond my QML skills (still a steep learning curve > ahead), but I'll give it a try.
Yeah, as expected, the whole signals thing doesn't work for me at all. But the way I tend to cope with the ridiculously bad documentation of QML is to simply imitate things that someone else already wrote. The patch below allows you to define a popAction for a page and if that is present, it is executed when the page is popped. Note that this only executes the popAction for the top page (but that said, I have never been able to get the multiple page pop to work where you tell it which page to pop down to... I think this is broken or the way it is used is totally non-intuitive). Anyway, maybe this could be added to plasma-mobile. /D From 83de1e8ba2c7e72897dd8798367daa5f0a33d928 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel <d...@hohndel.org> Date: Sat, 6 Feb 2016 11:44:09 -0800 Subject: [PATCH] Add popAction to page This allows a page to reset state or clean up after itself if it gets popped of the stack (for example when the user presses the back button on Android). Signed-off-by: Dirk Hohndel <d...@hohndel.org> --- components/mobilecomponents/qml/Page.qml | 5 +++++ components/mobilecomponents/qml/PageRow.qml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/components/mobilecomponents/qml/Page.qml b/components/mobilecomponents/qml/Page.qml index 28afbd3..ac90505 100644 --- a/components/mobilecomponents/qml/Page.qml +++ b/components/mobilecomponents/qml/Page.qml @@ -52,6 +52,11 @@ Rectangle { */ property QtObject mainAction + /** + * An optional single action when the page is popped + */ + property QtObject popAction + Layout.fillWidth: true color: "transparent" } diff --git a/components/mobilecomponents/qml/PageRow.qml b/components/mobilecomponents/qml/PageRow.qml index c331ee5..379d01b 100644 --- a/components/mobilecomponents/qml/PageRow.qml +++ b/components/mobilecomponents/qml/PageRow.qml @@ -62,6 +62,7 @@ Item { //A column is wide enough for 30 characters property int columnWidth: Math.round(parent.width/(Units.gridUnit*30)) > 0 ? parent.width/Math.round(parent.width/(Units.gridUnit*30)) : width property alias clip: scrollArea.clip + property QtObject action: pageStack.lastVisiblePage ? pageStack.lastVisiblePage.popAction : null // Indicates whether there is an ongoing page transition. property bool busy: internal.ongoingTransitionCount > 0 @@ -96,6 +97,10 @@ Item { function pop(page, immediate) { scrollToLevel(depth-1); + if (actualRoot.action && actualRoot.action.trigger) { + actualRoot.action.trigger() + } + return Engine.pop(page, immediate); } -- 1.9.1 _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel