From 9860c8b9e5390a864dac9d1e4a509f186861f04c Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 17 Aug 2022 12:04:36 -0400 Subject: [PATCH] Only show single page at any time, and pop pages that aren't visible --- src/qml/main.qml | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/qml/main.qml b/src/qml/main.qml index 5e2b75f5..b249eded 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -20,11 +20,16 @@ Kirigami.ApplicationWindow { id: root title: "Kasts" - pageStack.clip: true - width: Kirigami.Settings.isMobile ? 360 : 800 height: Kirigami.Settings.isMobile ? 660 : 600 + pageStack.clip: true + pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar; + pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton; + + // only have a single page visible at any time + pageStack.columnView.columnResizeMode: Kirigami.ColumnView.SingleColumn + minimumWidth: Kirigami.Units.gridUnit * 17 minimumHeight: Kirigami.Units.gridUnit * 12 @@ -91,6 +96,26 @@ Kirigami.ApplicationWindow { } } + // pop pages when not in use + Connections { + target: applicationWindow().pageStack + function onCurrentIndexChanged() { + // wait for animation to finish before popping pages + timer.restart(); + } + } + + Timer { + id: timer + interval: 300 + onTriggered: { + let currentIndex = applicationWindow().pageStack.currentIndex; + while (applicationWindow().pageStack.depth > (currentIndex + 1) && currentIndex >= 0) { + applicationWindow().pageStack.pop(); + } + } + } + Component.onDestruction: { saveWindowLayout(); } @@ -100,11 +125,6 @@ Kirigami.ApplicationWindow { currentPage = SettingsManager.lastOpenedPage; pageStack.initialPage = getPage(SettingsManager.lastOpenedPage); - if (Kirigami.Settings.isMobile) { - pageStack.globalToolBar.style = Kirigami.ApplicationHeaderStyle.ToolBar; - pageStack.globalToolBar.showNavigationButtons = Kirigami.ApplicationHeaderStyle.ShowBackButton; - } - // Delete played enclosures if set in settings if (SettingsManager.autoDeleteOnPlayed == 2) { DataManager.deletePlayedEnclosures();