2 * Copyright (C) 2013, 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Gestures 0.1
22 import Unity.DashCommunicator 0.1
23 import "../Components"
35 dashContent.currentScope.performQuery(uris[0])
39 property bool windowActive: window.active
41 DashCommunicatorService {
42 objectName: "dashCommunicatorService"
43 onSetCurrentScopeRequested: {
44 if (!isSwipe || !windowActive || bottomEdgeController.progress != 0 || scopeItem.scope || dashContent.subPageShown) {
45 if (bottomEdgeController.progress != 0 && window.active) animate = false;
46 dashContent.setCurrentScopeAtIndex(index, animate, true)
52 function backToDashContent()
54 // Close dash overview and nested temp scopes in it
55 if (bottomEdgeController.progress != 0) {
56 bottomEdgeController.enableAnimation = window.active;
57 bottomEdgeController.progress = 0;
59 // Close normal temp scopes (e.g. App Store)
60 if (scopeItem.scope) {
61 scopeItem.backClicked();
64 if (dashContent.subPageShown) {
65 dashContent.closePreview();
69 function setCurrentScope(scopeId, animate, reset) {
71 for (var i = 0; i < scopes.count; ++i) {
72 if (scopes.getScope(i).id == scopeId) {
78 if (scopeIndex == -1) {
79 console.warn("No match for scope with id: %1".arg(scopeId))
85 dashContent.closePreview();
87 if (scopeIndex == dashContent.currentIndex && !reset) {
88 // the scope is already the current one
92 dashContent.workaroundRestoreIndex = -1;
93 dashContent.setCurrentScopeAtIndex(scopeIndex, animate, reset)
96 function closeOverlayScope() {
97 if (dashContent.x != 0) {
107 id: bottomEdgeController
108 objectName: "bottomEdgeController"
110 property alias enableAnimation: progressAnimation.enabled
111 property real progress: 0
112 Behavior on progress {
113 id: progressAnimation
114 UbuntuNumberAnimation { }
118 // FIXME This is to workaround a Qt bug with the model moving the current item
119 // when the list is ListView.SnapOneItem and ListView.StrictlyEnforceRange
120 // together with the code in DashContent.qml
121 if (dashContent.workaroundRestoreIndex != -1) {
122 dashContent.currentIndex = dashContent.workaroundRestoreIndex;
123 dashContent.workaroundRestoreIndex = -1;
131 objectName: "dashContent"
137 dash.setCurrentScope(scopeId, true, false);
140 scopeItem.scope = scope;
144 UbuntuNumberAnimation {
146 if (!running && dashContent.x == 0) {
147 scopes.closeScope(scopeItem.scope);
148 scopeItem.scope = null;
154 // This is to avoid the situation where a bottom-edge swipe would bring up the dash overview
155 // (as expected) but would also cause the dash content flickable to move a bit, because
156 // that flickable was getting the touch events while overviewDragHandle was still undecided
157 // about whether that touch was indeed performing a directional drag gesture.
158 forceNonInteractive: overviewDragHandle.dragging
160 enabled: bottomEdgeController.progress == 0
165 opacity: bottomEdgeController.progress
166 anchors.fill: dashContent
171 objectName: "scopesList"
174 scope: scopes.overviewScope
175 y: dash.height * (1 - bottomEdgeController.progress)
176 visible: bottomEdgeController.progress != 0
178 bottomEdgeController.enableAnimation = true;
179 bottomEdgeController.progress = 0;
182 bottomEdgeController.enableAnimation = true;
183 bottomEdgeController.progress = 0;
184 scopesList.scope.performQuery("scope://com.canonical.scopes.clickstore");
187 scopes.setFavorite(scopeId, favorite);
189 onRequestFavoriteMoveTo: {
190 scopes.moveFavoriteTo(scopeId, index);
193 bottomEdgeController.enableAnimation = true;
194 bottomEdgeController.progress = 0;
195 dash.setCurrentScope(scopeId, false, false);
199 target: scopesList.scope
201 value: bottomEdgeController.progress === 1 && (Qt.application.state == Qt.ApplicationActive)
205 target: scopesList.scope
207 bottomEdgeController.enableAnimation = true;
208 bottomEdgeController.progress = 0;
209 scopeItem.scope = scope;
210 dashContent.x = -dashContent.width;
213 bottomEdgeController.enableAnimation = true;
214 bottomEdgeController.progress = 0;
215 dashContent.gotoScope(scopeId);
221 anchors.fill: scopeItem
222 visible: scopeItem.visible
227 objectName: "dashTempScopeItem"
229 x: dashContent.x + width
232 height: parent.height
233 visible: scope != null
242 target: scopeItem.scope
244 dashContent.gotoScope(scopeId);
247 scopeItem.closePreview();
248 var oldScope = scopeItem.scope;
249 scopeItem.scope = scope;
250 scopes.closeScope(oldScope);
257 objectName: "processingIndicator"
261 bottom: parent.bottom
262 bottomMargin: Qt.inputMethod.keyboardRectangle.height
265 color: scopeStyle.backgroundLuminance > 0.7 ? "#50000000" : "#50ffffff"
269 readonly property bool processing: dashContent.processing || scopeItem.processing || scopesList.processing
271 Behavior on opacity {
272 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
275 onProcessingChanged: {
276 if (processing) delay.start();
277 else if (!persist.running) indicator.opacity = 0;
283 onTriggered: if (indicator.processing) {
285 indicator.opacity = 1;
291 interval: 2 * UbuntuAnimation.SleepyDuration - UbuntuAnimation.FastDuration
292 onTriggered: if (!indicator.processing) indicator.opacity = 0
297 anchors { top: parent.top; bottom: parent.bottom }
298 width: parent.width / 4
299 color: UbuntuColors.orange
301 SequentialAnimation {
302 running: indicator.visible
303 loops: Animation.Infinite
305 from: -orange.width / 2
306 to: indicator.width - orange.width / 2
307 duration: UbuntuAnimation.SleepyDuration
308 easing.type: Easing.InOutSine
312 from: indicator.width - orange.width / 2
313 to: -orange.width / 2
314 duration: UbuntuAnimation.SleepyDuration
315 easing.type: Easing.InOutSine
323 objectName: "overviewHint"
324 source: "graphics/overview_hint.png"
325 anchors.horizontalCenter: parent.horizontalCenter
326 opacity: !scopeItem.scope && (scopes.count == 0 || dashContent.pageHeaderTotallyVisible) &&
327 (overviewDragHandle.enabled || bottomEdgeController.progress != 0) ? 1 : 0
328 Behavior on opacity {
329 enabled: bottomEdgeController.progress == 0
330 UbuntuNumberAnimation {}
332 y: parent.height - height * (1 - bottomEdgeController.progress * 4)
334 // Eat direct presses on the overview hint so that they do not end up in the card below
336 enabled: parent.opacity != 0
338 // TODO: This is a temporary workaround to allow people opening the
339 // dash overview when there's no touch input around. Will be replaced with
340 // a SDK component once that's available
341 onClicked: bottomEdgeController.progress = 1;
343 // We need to eat touch events here in order to not allow opening the bottom edge with a touch press
344 MultiPointTouchArea {
347 enabled: parent.enabled
352 DirectionalDragArea {
353 id: overviewDragHandle
354 objectName: "overviewDragHandle"
356 direction: Direction.Upwards
357 enabled: !dashContent.subPageShown &&
358 (scopes.count == 0 || (dashContent.currentScope && dashContent.currentScope.searchQuery == "")) &&
360 (bottomEdgeController.progress == 0 || dragging)
362 readonly property real fullMovement: dash.height
364 anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
367 onSceneDistanceChanged: {
369 bottomEdgeController.enableAnimation = false;
370 bottomEdgeController.progress = Math.max(0, Math.min(1, sceneDistance / fullMovement));
376 bottomEdgeController.enableAnimation = true;
377 bottomEdgeController.progress = (bottomEdgeController.progress > 0.2) ? 1 : 0;