Kirigami2

ApplicationItem.qml
1/*
2 * SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import org.kde.kirigami 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*/
75Kirigami.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 * @property org::kde::kirigami::PageRow pageStack
88 */
89 readonly property alias pageStack: __pageStack
90
91 // Redefines here as here we can know a pointer to PageRow
92 wideScreen: width >= applicationWindow().pageStack.defaultColumnWidth * 2
93
94 Component.onCompleted: {
95 pageStack.currentItem?.forceActiveFocus();
96 }
97
98 Kirigami.PageRow {
99 id: __pageStack
100 anchors {
101 fill: parent
102 // HACK: workaround a bug in android iOS keyboard management
103 bottomMargin: ((Qt.platform.os === "android" || Qt.platform.os === "ios") || !Qt.inputMethod.visible) ? 0 : Qt.inputMethod.keyboardRectangle.height
104 }
105
106 function goBack() {
107 // NOTE: drawers are handling the back button by themselves
108 const backEvent = {accepted: false}
109 if (root.pageStack.currentIndex >= 1) {
110 root.pageStack.currentItem.backRequested(backEvent);
111 if (!backEvent.accepted) {
112 root.pageStack.flickBack();
113 backEvent.accepted = true;
114 }
115 }
116
117 if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") {
118 Qt.quit();
119 }
120 }
121 function goForward() {
122 root.pageStack.currentIndex = Math.min(root.pageStack.depth - 1, root.pageStack.currentIndex + 1);
123 }
124 Keys.onBackPressed: event => {
125 goBack();
126 event.accepted = true;
127 }
128 Shortcut {
129 sequences: [StandardKey.Forward]
130 onActivated: __pageStack.goForward();
131 }
132 Shortcut {
133 sequences: [StandardKey.Back]
134 onActivated: __pageStack.goBack();
135 }
136
137 background: Rectangle {
138 color: root.color
139 }
140
141 focus: true
142 }
143}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:45:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.