Changeset View
Changeset View
Standalone View
Standalone View
src/controls/ApplicationItem.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2017 Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.5 | ||||
21 | import "templates/private" | ||||
22 | import org.kde.kirigami 2.0 as Kirigami | ||||
23 | import QtGraphicalEffects 1.0 | ||||
24 | | ||||
25 | /** | ||||
26 | * A window that provides some basic features needed for all apps | ||||
27 | * This version is an Item as opposed to a window, it's intended | ||||
28 | * for use into a QQuickView | ||||
29 | * | ||||
30 | * It's usually used as a root QML component for the application. | ||||
31 | * It's based around the PageRow component, the application will be | ||||
32 | * about pages adding and removal. | ||||
33 | * For most of the usages, this class should be used instead | ||||
34 | * of AbstractApplicationWidnow | ||||
35 | * @see AbstractApplicationWidnow | ||||
36 | * | ||||
37 | * Example usage: | ||||
38 | * @code | ||||
39 | * import org.kde.kirigami 2.0 as Kirigami | ||||
40 | * | ||||
41 | * Kirigami.ApplicationItem { | ||||
42 | * [...] | ||||
43 | * globalDrawer: Kirigami.GlobalDrawer { | ||||
44 | * actions: [ | ||||
45 | * Kirigami.Action { | ||||
46 | * text: "View" | ||||
47 | * iconName: "view-list-icons" | ||||
48 | * Kirigami.Action { | ||||
49 | * text: "action 1" | ||||
50 | * } | ||||
51 | * Kirigami.Action { | ||||
52 | * text: "action 2" | ||||
53 | * } | ||||
54 | * Kirigami.Action { | ||||
55 | * text: "action 3" | ||||
56 | * } | ||||
57 | * }, | ||||
58 | * Kirigami.Action { | ||||
59 | * text: "Sync" | ||||
60 | * iconName: "folder-sync" | ||||
61 | * } | ||||
62 | * ] | ||||
63 | * } | ||||
64 | * | ||||
65 | * contextDrawer: Kirigami.ContextDrawer { | ||||
66 | * id: contextDrawer | ||||
67 | * } | ||||
68 | * | ||||
69 | * pageStack.initialPage: Kirigami.Page { | ||||
70 | * mainAction: Kirigami.Action { | ||||
71 | * iconName: "edit" | ||||
72 | * onTriggered: { | ||||
73 | * // do stuff | ||||
74 | * } | ||||
75 | * } | ||||
76 | * contextualActions: [ | ||||
77 | * Kirigami.Action { | ||||
78 | * iconName: "edit" | ||||
79 | * text: "Action text" | ||||
80 | * onTriggered: { | ||||
81 | * // do stuff | ||||
82 | * } | ||||
83 | * }, | ||||
84 | * Kirigami.Action { | ||||
85 | * iconName: "edit" | ||||
86 | * text: "Action text" | ||||
87 | * onTriggered: { | ||||
88 | * // do stuff | ||||
89 | * } | ||||
90 | * } | ||||
91 | * ] | ||||
92 | * [...] | ||||
93 | * } | ||||
94 | * [...] | ||||
95 | * } | ||||
96 | * @endcode | ||||
97 | * | ||||
98 | */ | ||||
99 | AbstractApplicationItem { | ||||
100 | id: root | ||||
101 | | ||||
102 | /** | ||||
103 | * pageStack: StackView | ||||
104 | * Readonly. | ||||
105 | * The stack used to allocate the pages and to manage the transitions | ||||
106 | * between them. | ||||
107 | * It's using a PageRow, while having the same API as PageStack, | ||||
108 | * it positions the pages as adjacent columns, with as many columns | ||||
109 | * as can fit in the screen. An handheld device would usually have a single | ||||
110 | * fullscreen column, a tablet device would have many tiled columns. | ||||
111 | */ | ||||
112 | property alias pageStack: __pageStack | ||||
113 | | ||||
114 | //redefines here as here we can know a pointer to PageRow | ||||
115 | wideScreen: width >= applicationWindow().pageStack.defaultColumnWidth*2 | ||||
116 | | ||||
117 | PageRow { | ||||
118 | id: __pageStack | ||||
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 (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 | var backEvent = {accepted: false} | ||||
135 | if (root.pageStack.currentIndex >= 1) { | ||||
136 | root.pageStack.currentItem.backRequested(backEvent); | ||||
137 | if (!backEvent.accepted) { | ||||
138 | root.pageStack.flickBack(); | ||||
139 | backEvent.accepted = true; | ||||
140 | } | ||||
141 | } | ||||
142 | | ||||
143 | if (Kirigami.Settings.isMobile && !backEvent.accepted && Qt.platform.os !== "ios") { | ||||
144 | Qt.quit(); | ||||
145 | } | ||||
146 | } | ||||
147 | function goForward() { | ||||
148 | root.pageStack.currentIndex = Math.min(root.pageStack.depth-1, root.pageStack.currentIndex + 1); | ||||
149 | } | ||||
150 | Keys.onBackPressed: { | ||||
151 | goBack(); | ||||
152 | event.accepted = true | ||||
153 | } | ||||
154 | Shortcut { | ||||
155 | sequence: "Forward" | ||||
156 | onActivated: __pageStack.goForward(); | ||||
157 | } | ||||
158 | Shortcut { | ||||
159 | sequence: StandardKey.Forward | ||||
160 | onActivated: __pageStack.goForward(); | ||||
161 | } | ||||
162 | Shortcut { | ||||
163 | sequence: StandardKey.Back | ||||
164 | onActivated: __pageStack.goBack(); | ||||
165 | } | ||||
166 | | ||||
167 | Rectangle { | ||||
168 | z: -1 | ||||
169 | anchors.fill: parent | ||||
170 | color: Kirigami.Theme.backgroundColor | ||||
171 | } | ||||
172 | focus: true | ||||
173 | } | ||||
174 | } |