9import QtQuick.Templates as T
10import org.kde.kirigami as Kirigami
34 property Kirigami.PagePool pagePool
43 property Item pageStack: typeof applicationWindow !== 'undefined' ? applicationWindow().pageStack : null
51 property T.Page basePage
72 property var initialProperties
86 property bool useLayers: false
92 function pageItem(): Item {
93 return pagePool.pageForUrl(page)
100 function layerContainsPage(): bool {
101 if (!useLayers || !pageStack.hasOwnProperty("layers")) {
105 const pageItem = this.pageItem();
106 const item = pageStack.layers.find(item => item === pageItem);
107 return item !== null;
114 function stackContainsPage(): bool {
118 return pageStack.columnView.containsItem(pagePool.pageForUrl(page));
124 if (page.length === 0 || !pagePool || !pageStack) {
129 const pageItem = this.pageItem();
130 if (layerContainsPage() && pageItem !== pageStack.layers.currentItem) {
131 pageStack.layers.replace(pageItem, pageItem);
136 if (stackContainsPage()) {
137 if (pageStack.hasOwnProperty(
"layers")) {
138 pageStack.layers.clear();
142 const stack = useLayers ? pageStack.layers : pageStack
144 if (pageItem != null && stack.currentItem == pageItem) {
148 if (initialProperties && typeof(initialProperties) !==
"object") {
149 console.warn(
"initialProperties must be of type object");
153 if (!stack.hasOwnProperty(
"pop") || typeof stack.pop !==
"function" || !stack.hasOwnProperty(
"push") || typeof stack.push !==
"function") {
157 if (pagePool.isLocalUrl(page)) {
161 }
else if (!useLayers) {
165 stack.push(initialProperties
166 ? pagePool.loadPageWithProperties(page, initialProperties)
167 : pagePool.loadPage(page));
169 const callback = item => {
173 }
else if (!useLayers) {
180 if (initialProperties) {
181 pagePool.loadPage(page, initialProperties, callback);
184 pagePool.loadPage(page, callback);
190 property QtObject _private: QtObject {
193 function setChecked(checked) {
194 root.checked = checked;
197 function clearLayers() {
198 root.pageStack.layers.clear();
201 property list<Connections> connections: [
203 target: root.pageStack
205 function onCurrentItemChanged() {
206 if (root.useLayers) {
207 if (root.layerContainsPage()) {
208 _private.clearLayers();
210 if (root.checkable) {
211 _private.setChecked(
false);
215 if (root.checkable) {
216 _private.setChecked(root.stackContainsPage());
222 enabled: root.pageStack.hasOwnProperty(
"layers")
223 target: root.pageStack.layers
225 function onCurrentItemChanged() {
226 if (root.useLayers && root.checkable) {
227 _private.setChecked(root.layerContainsPage());
230 if (root.pageStack.layers.depth === 1 && root.stackContainsPage()) {
231 _private.setChecked(
true);