Kirigami2

ApplicationItem.qml
1 /*
2  * SPDX-FileCopyrightText: 2017 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.15
8 import org.kde.kirigami 2.4 as Kirigami
9 
10 /**
11  * @brief An item that provides the features of ApplicationWindow without the window itself.
12  *
13  * This allows embedding into a larger application.
14  * It's based around the PageRow component that allows adding/removing of pages.
15  *
16  * Example usage:
17  * @code
18  * import org.kde.kirigami 2.4 as Kirigami
19  *
20  * Kirigami.ApplicationItem {
21  * globalDrawer: Kirigami.GlobalDrawer {
22  * actions: [
23  * Kirigami.Action {
24  * text: "View"
25  * icon.name: "view-list-icons"
26  * Kirigami.Action {
27  * text: "action 1"
28  * }
29  * Kirigami.Action {
30  * text: "action 2"
31  * }
32  * Kirigami.Action {
33  * text: "action 3"
34  * }
35  * },
36  * Kirigami.Action {
37  * text: "Sync"
38  * icon.name: "folder-sync"
39  * }
40  * ]
41  * }
42  *
43  * contextDrawer: Kirigami.ContextDrawer {
44  * id: contextDrawer
45  * }
46  *
47  * pageStack.initialPage: Kirigami.Page {
48  * mainAction: Kirigami.Action {
49  * icon.name: "edit"
50  * onTriggered: {
51  * // do stuff
52  * }
53  * }
54  * contextualActions: [
55  * Kirigami.Action {
56  * icon.name: "edit"
57  * text: "Action text"
58  * onTriggered: {
59  * // do stuff
60  * }
61  * },
62  * Kirigami.Action {
63  * icon.name: "edit"
64  * text: "Action text"
65  * onTriggered: {
66  * // do stuff
67  * }
68  * }
69  * ]
70  * // ...
71  * }
72  * }
73  * @endcode
74 */
75 Kirigami.AbstractApplicationItem {
76  id: root
77 
78  /**
79  * @brief This property holds the PageRow used to allocate the pages and
80  * manage the transitions between them.
81  *
82  * It's using a PageRow, while having the same API as PageStack,
83  * it positions the pages as adjacent columns, with as many columns
84  * as can fit in the screen. An handheld device would usually have a single
85  * fullscreen column, a tablet device would have many tiled columns.
86  *
87  * @warning This property is readonly.
88  * @property QtQuick.StackView ApplicationItem::pageStack
89  */
90  property alias pageStack: __pageStack // TODO KF6 make readonly
91 
92  // Redefines here as here we can know a pointer to PageRow
93  wideScreen: width >= applicationWindow().pageStack.defaultColumnWidth * 2
94 
95  Component.onCompleted: {
96  if (pageStack.currentItem) {
97  pageStack.currentItem.forceActiveFocus();
98  }
99  }
100 
101  Kirigami.PageRow {
102  id: __pageStack
103  anchors {
104  fill: parent
105  // HACK: workaround a bug in android iOS keyboard management
106  bottomMargin: ((Qt.platform.os === "android" || Qt.platform.os === "ios") || !Qt.inputMethod.visible) ? 0 : Qt.inputMethod.keyboardRectangle.height
107  onBottomMarginChanged: {
108  if (bottomMargin > 0) {
109  root.reachableMode = false;
110  }
111  }
112  }
113  // FIXME
114  onCurrentIndexChanged: root.reachableMode = false;
115 
116  function goBack() {
117  // NOTE: drawers are handling the back button by themselves
118  const backEvent = {accepted: false}
119  if (root.pageStack.currentIndex >= 1) {
120  root.pageStack.currentItem.backRequested(backEvent);
121  if (!backEvent.accepted) {
122  root.pageStack.flickBack();
123  backEvent.accepted = true;
124  }
125  }
126 
127  if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") {
128  Qt.quit();
129  }
130  }
131  function goForward() {
132  root.pageStack.currentIndex = Math.min(root.pageStack.depth - 1, root.pageStack.currentIndex + 1);
133  }
134  Keys.onBackPressed: event => {
135  goBack();
136  event.accepted = true;
137  }
138  Shortcut {
139  sequences: [StandardKey.Forward]
140  onActivated: __pageStack.goForward();
141  }
142  Shortcut {
143  sequences: [StandardKey.Back]
144  onActivated: __pageStack.goBack();
145  }
146 
147  background: Rectangle {
148  color: root.color
149  }
150 
151  focus: true
152  }
153 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.