Kirigami2

ApplicationWindow.qml
1 /*
2  * SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.5
8 import "templates/private"
9 import org.kde.kirigami 2.4 as Kirigami
10 
11 /**
12  * A window that provides some basic features needed for all apps
13  *
14  * It's usually used as a root QML component for the application.
15  * It's based around the PageRow component, the application will be
16  * about pages adding and removal.
17  * For most of the usages, this class should be used instead
18  * of AbstractApplicationWindow
19  * @see AbstractApplicationWindow
20  *
21  * Setting a width and height property on the ApplicationWindow
22  * will set its initial size, but it won't set it as an automatically binding.
23  * to resize programmatically the ApplicationWindow they need to
24  * be assigned again in an imperative fashion
25  *
26  * Example usage:
27  * @code
28  * import org.kde.kirigami 2.4 as Kirigami
29  *
30  * Kirigami.ApplicationWindow {
31  * [...]
32  * globalDrawer: Kirigami.GlobalDrawer {
33  * actions: [
34  * Kirigami.Action {
35  * text: "View"
36  * iconName: "view-list-icons"
37  * Kirigami.Action {
38  * text: "action 1"
39  * }
40  * Kirigami.Action {
41  * text: "action 2"
42  * }
43  * Kirigami.Action {
44  * text: "action 3"
45  * }
46  * },
47  * Kirigami.Action {
48  * text: "Sync"
49  * iconName: "folder-sync"
50  * }
51  * ]
52  * }
53  *
54  * contextDrawer: Kirigami.ContextDrawer {
55  * id: contextDrawer
56  * }
57  *
58  * pageStack.initialPage: Kirigami.Page {
59  * mainAction: Kirigami.Action {
60  * iconName: "edit"
61  * onTriggered: {
62  * // do stuff
63  * }
64  * }
65  * contextualActions: [
66  * Kirigami.Action {
67  * iconName: "edit"
68  * text: "Action text"
69  * onTriggered: {
70  * // do stuff
71  * }
72  * },
73  * Kirigami.Action {
74  * iconName: "edit"
75  * text: "Action text"
76  * onTriggered: {
77  * // do stuff
78  * }
79  * }
80  * ]
81  * [...]
82  * }
83  * [...]
84  * }
85  * @endcode
86  *
87 */
89  id: root
90 
91  /**
92  * @property QtQuick.StackView ApplicationItem::pageStack
93  *
94  * @brief This property holds the stack used to allocate the pages and to
95  * manage the transitions between them.
96  *
97  * It's using a PageRow, while having the same API as PageStack,
98  * it positions the pages as adjacent columns, with as many columns
99  * as can fit in the screen. An handheld device would usually have a single
100  * fullscreen column, a tablet device would have many tiled columns.
101  *
102  * @warning This property is not currently readonly, but it should be treated like it is readonly.
103  */
104  property alias pageStack: __pageStack // TODO KF6 make readonly
105 
106  // Redefined here as here we can know a pointer to PageRow.
107  // We negate the canBeEnabled check because we don't want to factor in the automatic drawer provided by Kirigami for page actions for our calculations
108  wideScreen: width >= (root.pageStack.defaultColumnWidth) + ((contextDrawer && !(contextDrawer instanceof Kirigami.ContextDrawer)) ? contextDrawer.width : 0) + (globalDrawer ? globalDrawer.width : 0)
109 
110  Component.onCompleted: {
111  if (pageStack.currentItem) {
112  pageStack.currentItem.forceActiveFocus()
113  }
114  }
115 
116  PageRow {
117  id: __pageStack
118  globalToolBar.style: Kirigami.ApplicationHeaderStyle.Auto
119  anchors {
120  fill: parent
121  //HACK: workaround a bug in android iOS keyboard management
122  bottomMargin: ((Qt.platform.os == "android" || Qt.platform.os == "ios") || !Qt.inputMethod.visible) ? 0 : Qt.inputMethod.keyboardRectangle.height
123  onBottomMarginChanged: {
124  if (__pageStack.anchors.bottomMargin > 0) {
125  root.reachableMode = false;
126  }
127  }
128  }
129  //FIXME
130  onCurrentIndexChanged: root.reachableMode = false;
131 
132  function goBack() {
133  //NOTE: drawers are handling the back button by themselves
134  let backEvent = {accepted: false}
135  if (root.pageStack.hasOwnProperty("layers") && root.pageStack.layers && root.pageStack.layers.depth > 1) {
136  root.pageStack.layers.currentItem.backRequested(backEvent);
137  if (!backEvent.accepted) {
138  root.pageStack.layers.pop();
139  backEvent.accepted = true;
140  }
141  } else {
142  root.pageStack.currentItem.backRequested(backEvent);
143  if (root.pageStack.currentIndex >= 1) {
144  if (!backEvent.accepted) {
145  root.pageStack.flickBack();
146  backEvent.accepted = true;
147  }
148  }
149  }
150 
151  if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") {
152  Qt.quit();
153  }
154  }
155  function goForward() {
156  root.pageStack.currentIndex = Math.min(root.pageStack.depth-1, root.pageStack.currentIndex + 1);
157  }
158  Keys.onBackPressed: {
159  goBack();
160  event.accepted = true
161  }
162  Shortcut {
163  sequence: "Forward"
164  onActivated: __pageStack.goForward();
165  }
166  Shortcut {
167  sequence: StandardKey.Forward
168  onActivated: __pageStack.goForward();
169  }
170  Shortcut {
171  sequence: StandardKey.Back
172  onActivated: __pageStack.goBack();
173  }
174 
175  focus: true
176  }
177 }
Definition: icon.h:18
A window that provides some basic features needed for all apps Use this class only if you need a cust...
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jan 15 2022 22:34:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.