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 }
103
104 function goBack() {
105 // NOTE: drawers are handling the back button by themselves
106 const backEvent = {accepted: false}
107 if (root.pageStack.currentIndex >= 1) {
108 root.pageStack.currentItem.backRequested(backEvent);
109 if (!backEvent.accepted) {
110 root.pageStack.flickBack();
111 backEvent.accepted = true;
112 }
113 }
114
115 if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") {
116 Qt.quit();
117 }
118 }
119 function goForward() {
120 root.pageStack.currentIndex = Math.min(root.pageStack.depth - 1, root.pageStack.currentIndex + 1);
121 }
122 Keys.onBackPressed: event => {
123 goBack();
124 event.accepted = true;
125 }
126 Shortcut {
127 sequences: [StandardKey.Forward]
128 onActivated: __pageStack.goForward();
129 }
130 Shortcut {
131 sequences: [StandardKey.Back]
132 onActivated: __pageStack.goBack();
133 }
134
135 background: Rectangle {
136 color: root.color
137 }
138
139 focus: true
140 }
141}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:49:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.