Changeset View
Changeset View
Standalone View
Standalone View
applets/kickoff/package/contents/ui/ApplicationsView.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org> | 2 | Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | Copyright (C) 2012 Gregor Taetzner <gregor@freenet.de> | 3 | Copyright (C) 2012 Gregor Taetzner <gregor@freenet.de> | ||
4 | Copyright 2014 Sebastian Kügler <sebas@kde.org> | 4 | Copyright 2014 Sebastian Kügler <sebas@kde.org> | ||
5 | Copyright (C) 2015 Eike Hein <hein@kde.org> | 5 | Copyright (C) 2015-2018 Eike Hein <hein@kde.org> | ||
6 | 6 | | |||
7 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 9 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 10 | (at your option) any later version. | ||
11 | 11 | | |||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 11 Lines | |||||
25 | 25 | | |||
26 | Item { | 26 | Item { | ||
27 | id: appViewContainer | 27 | id: appViewContainer | ||
28 | 28 | | |||
29 | anchors.fill: parent | 29 | anchors.fill: parent | ||
30 | 30 | | |||
31 | objectName: "ApplicationsView" | 31 | objectName: "ApplicationsView" | ||
32 | 32 | | |||
33 | property ListView listView: applicationsView | 33 | property ListView listView: applicationsView.listView | ||
34 | 34 | | |||
35 | function decrementCurrentIndex() { | 35 | function decrementCurrentIndex() { | ||
36 | applicationsView.decrementCurrentIndex(); | 36 | applicationsView.decrementCurrentIndex(); | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | function incrementCurrentIndex() { | 39 | function incrementCurrentIndex() { | ||
40 | applicationsView.incrementCurrentIndex(); | 40 | applicationsView.incrementCurrentIndex(); | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | function activateCurrentIndex(start) { | 43 | function activateCurrentIndex(start) { | ||
44 | if (!applicationsView.currentItem.modelChildren) { | 44 | if (!applicationsView.currentItem.modelChildren) { | ||
45 | if (!start) { | 45 | if (!start) { | ||
46 | return; | 46 | return; | ||
47 | } | 47 | } | ||
48 | } | 48 | } | ||
49 | appViewScrollArea.state = "OutgoingLeft"; | 49 | applicationsView.state = "OutgoingLeft"; | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | function openContextMenu() { | 52 | function openContextMenu() { | ||
53 | applicationsView.currentItem.openActionMenu(); | 53 | applicationsView.currentItem.openActionMenu(); | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | function deactivateCurrentIndex() { | 56 | function deactivateCurrentIndex() { | ||
57 | if (crumbModel.count > 0) { // this is not the case when switching from the "Applications" to the "Favorites" tab using the "Left" key | 57 | if (crumbModel.count > 0) { // this is not the case when switching from the "Applications" to the "Favorites" tab using the "Left" key | ||
58 | breadcrumbsElement.children[crumbModel.count-1].clickCrumb(); | 58 | breadcrumbsElement.children[crumbModel.count-1].clickCrumb(); | ||
59 | appViewScrollArea.state = "OutgoingRight"; | 59 | applicationsView.state = "OutgoingRight"; | ||
60 | return true; | 60 | return true; | ||
61 | } | 61 | } | ||
62 | return false; | 62 | return false; | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | function reset() { | 65 | function reset() { | ||
66 | applicationsView.model = rootModel; | 66 | applicationsView.model = rootModel; | ||
67 | applicationsView.positionViewAtBeginning(); | 67 | applicationsView.listView.positionViewAtBeginning(); | ||
68 | applicationsView.clearBreadcrumbs(); | 68 | applicationsView.clearBreadcrumbs(); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | function refreshed() { | 71 | function refreshed() { | ||
72 | reset(); | 72 | reset(); | ||
73 | updatedLabelTimer.running = true; | 73 | updatedLabelTimer.running = true; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 137 | onWidthChanged: { | |||
140 | } else { | 140 | } else { | ||
141 | breadcrumbFlickable.contentX = Math.max(0, breadcrumbsElement.width - breadcrumbFlickable.width) | 141 | breadcrumbFlickable.contentX = Math.max(0, breadcrumbsElement.width - breadcrumbFlickable.width) | ||
142 | } | 142 | } | ||
143 | } | 143 | } | ||
144 | } | 144 | } | ||
145 | } // Flickable | 145 | } // Flickable | ||
146 | } // crumbContainer | 146 | } // crumbContainer | ||
147 | 147 | | |||
148 | PlasmaExtras.ScrollArea { | 148 | KickoffListView { | ||
149 | id: appViewScrollArea | 149 | id: applicationsView | ||
150 | | ||||
151 | property Item activatedItem: null | | |||
152 | 150 | | |||
153 | anchors { | 151 | anchors { | ||
154 | top: crumbContainer.bottom | 152 | top: crumbContainer.bottom | ||
155 | bottom: parent.bottom | 153 | bottom: parent.bottom | ||
156 | rightMargin: -units.largeSpacing | 154 | rightMargin: -units.largeSpacing | ||
157 | leftMargin: -units.largeSpacing | 155 | leftMargin: -units.largeSpacing | ||
158 | } | 156 | } | ||
159 | 157 | | |||
158 | width: parent.width | ||||
159 | | ||||
160 | property Item activatedItem: null | ||||
161 | property var newModel: null | ||||
162 | | ||||
160 | Behavior on opacity { NumberAnimation { duration: units.longDuration } } | 163 | Behavior on opacity { NumberAnimation { duration: units.longDuration } } | ||
161 | 164 | | |||
162 | width: parent.width | 165 | focus: true | ||
163 | 166 | | |||
164 | function moveRight() { | 167 | appView: true | ||
165 | state = ""; | 168 | | ||
166 | activatedItem.activate() | 169 | model: rootModel | ||
167 | applicationsView.positionViewAtBeginning() | | |||
168 | } | | |||
169 | 170 | | |||
170 | function moveLeft() { | 171 | function moveLeft() { | ||
171 | state = ""; | 172 | state = ""; | ||
172 | // newModelIndex set by clicked breadcrumb | 173 | // newModelIndex set by clicked breadcrumb | ||
173 | var oldModel = applicationsView.model; | 174 | var oldModel = applicationsView.model; | ||
174 | applicationsView.model = applicationsView.newModel; | 175 | applicationsView.model = applicationsView.newModel; | ||
175 | applicationsView.positionViewAtIndex(applicationsView.model.rowForModel(oldModel), ListView.Center) | 176 | listView.positionViewAtIndex(model.rowForModel(oldModel), ListView.Center) | ||
176 | } | | |||
177 | | ||||
178 | ListView { | | |||
179 | id: applicationsView | | |||
180 | | ||||
181 | property variant newModel | | |||
182 | | ||||
183 | focus: true | | |||
184 | keyNavigationWraps: true | | |||
185 | boundsBehavior: Flickable.StopAtBounds | | |||
186 | highlight: KickoffHighlight {} | | |||
187 | highlightMoveDuration : 0 | | |||
188 | highlightResizeDuration: 0 | | |||
189 | | ||||
190 | model: rootModel | | |||
191 | | ||||
192 | delegate: KickoffItem { | | |||
193 | id: kickoffItem | | |||
194 | | ||||
195 | appView: true | | |||
196 | } | 177 | } | ||
197 | 178 | | |||
198 | function addBreadcrumb(model, title) { | 179 | function moveRight() { | ||
199 | crumbModel.append({"text": title, "depth": crumbModel.count+1}) | 180 | state = ""; | ||
200 | crumbModel.models.push(model); | 181 | activatedItem.activate() | ||
182 | applicationsView.listView.positionViewAtBeginning() | ||||
201 | } | 183 | } | ||
202 | 184 | | |||
203 | function clearBreadcrumbs() { | 185 | function clearBreadcrumbs() { | ||
204 | crumbModel.clear(); | 186 | crumbModel.clear(); | ||
205 | crumbModel.models = []; | 187 | crumbModel.models = []; | ||
206 | } | 188 | } | ||
207 | } // applicationsView | 189 | | ||
190 | onReset: appViewContainer.reset() | ||||
191 | | ||||
192 | onAddBreadcrumb: { | ||||
193 | crumbModel.append({"text": title, "depth": crumbModel.count+1}) | ||||
194 | crumbModel.models.push(model); | ||||
195 | } | ||||
208 | 196 | | |||
209 | states: [ | 197 | states: [ | ||
210 | State { | 198 | State { | ||
211 | name: "OutgoingLeft" | 199 | name: "OutgoingLeft" | ||
212 | PropertyChanges { | 200 | PropertyChanges { | ||
213 | target: appViewScrollArea | 201 | target: applicationsView | ||
214 | x: -parent.width | 202 | x: -parent.width | ||
215 | opacity: 0.0 | 203 | opacity: 0.0 | ||
216 | } | 204 | } | ||
217 | }, | 205 | }, | ||
218 | State { | 206 | State { | ||
219 | name: "OutgoingRight" | 207 | name: "OutgoingRight" | ||
220 | PropertyChanges { | 208 | PropertyChanges { | ||
221 | target: appViewScrollArea | 209 | target: applicationsView | ||
222 | x: parent.width | 210 | x: parent.width | ||
223 | opacity: 0.0 | 211 | opacity: 0.0 | ||
224 | } | 212 | } | ||
225 | } | 213 | } | ||
226 | ] | 214 | ] | ||
227 | 215 | | |||
228 | transitions: [ | 216 | transitions: [ | ||
229 | Transition { | 217 | Transition { | ||
230 | to: "OutgoingLeft" | 218 | to: "OutgoingLeft" | ||
231 | SequentialAnimation { | 219 | SequentialAnimation { | ||
232 | // We need to cache the currentItem since the selection can move during animation, | 220 | // We need to cache the currentItem since the selection can move during animation, | ||
233 | // and we want the item that has been clicked on, not the one that is under the | 221 | // and we want the item that has been clicked on, not the one that is under the | ||
234 | // mouse once the animation is done | 222 | // mouse once the animation is done | ||
235 | ScriptAction { script: appViewScrollArea.activatedItem = applicationsView.currentItem } | 223 | ScriptAction { script: applicationsView.activatedItem = applicationsView.currentItem } | ||
236 | NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration } | 224 | NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration } | ||
237 | ScriptAction { script: appViewScrollArea.moveRight() } | 225 | ScriptAction { script: applicationsView.moveRight() } | ||
238 | } | 226 | } | ||
239 | }, | 227 | }, | ||
240 | Transition { | 228 | Transition { | ||
241 | to: "OutgoingRight" | 229 | to: "OutgoingRight" | ||
242 | SequentialAnimation { | 230 | SequentialAnimation { | ||
243 | NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration } | 231 | NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration } | ||
244 | ScriptAction { script: appViewScrollArea.moveLeft() } | 232 | ScriptAction { script: applicationsView.moveLeft() } | ||
245 | } | 233 | } | ||
246 | } | 234 | } | ||
247 | ] | 235 | ] | ||
248 | } // appViewScrollArea | 236 | } | ||
249 | 237 | | |||
250 | MouseArea { | 238 | MouseArea { | ||
251 | anchors.fill: appViewScrollArea | 239 | anchors.fill: parent | ||
240 | | ||||
252 | acceptedButtons: Qt.BackButton | 241 | acceptedButtons: Qt.BackButton | ||
242 | | ||||
253 | onClicked: { | 243 | onClicked: { | ||
254 | deactivateCurrentIndex() | 244 | deactivateCurrentIndex() | ||
255 | } | 245 | } | ||
256 | } | 246 | } | ||
257 | 247 | | |||
258 | Timer { | 248 | Timer { | ||
259 | id: updatedLabelTimer | 249 | id: updatedLabelTimer | ||
260 | interval: 1500 | 250 | interval: 1500 | ||
261 | running: false | 251 | running: false | ||
262 | repeat: true | 252 | repeat: true | ||
263 | 253 | | |||
264 | onRunningChanged: { | 254 | onRunningChanged: { | ||
265 | if (running) { | 255 | if (running) { | ||
266 | updatedLabel.opacity = 1; | 256 | updatedLabel.opacity = 1; | ||
267 | crumbContainer.opacity = 0.3; | 257 | crumbContainer.opacity = 0.3; | ||
268 | appViewScrollArea.opacity = 0.3; | 258 | applicationsView.scrollArea.opacity = 0.3; | ||
269 | } | 259 | } | ||
270 | } | 260 | } | ||
271 | onTriggered: { | 261 | onTriggered: { | ||
272 | updatedLabel.opacity = 0; | 262 | updatedLabel.opacity = 0; | ||
273 | crumbContainer.opacity = 1; | 263 | crumbContainer.opacity = 1; | ||
274 | appViewScrollArea.opacity = 1; | 264 | applicationsView.scrollArea.opacity = 1; | ||
275 | running = false; | 265 | running = false; | ||
276 | } | 266 | } | ||
277 | } | 267 | } | ||
278 | 268 | | |||
279 | PlasmaComponents.Label { | 269 | PlasmaComponents.Label { | ||
280 | id: updatedLabel | 270 | id: updatedLabel | ||
281 | text: i18n("Applications updated.") | 271 | text: i18n("Applications updated.") | ||
282 | opacity: 0 | 272 | opacity: 0 | ||
Show All 11 Lines |