2 * Copyright (C) 2013-2015 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 "../Components"
19 import Ubuntu.Components 1.3
20 import Ubuntu.Gestures 0.1
21 import Unity.Launcher 0.1
26 property bool autohideEnabled: false
27 property bool lockedVisible: false
28 property bool available: true // can be used to disable all interactions
29 property alias inverted: panel.inverted
31 property int panelWidth: units.gu(10)
32 property int dragAreaWidth: units.gu(1)
33 property int minimizeDistance: units.gu(26)
34 property real progress: dragArea.dragging && dragArea.touchPosition.x > panelWidth ?
35 (width * (dragArea.touchPosition.x-panelWidth) / (width - panelWidth)) : 0
37 property bool superPressed: false
38 property bool superTabPressed: false
40 readonly property bool dragging: dragArea.dragging
41 readonly property real dragDistance: dragArea.dragging ? dragArea.touchPosition.x : 0
42 readonly property real visibleWidth: panel.width + panel.x
43 readonly property alias shortcutHintsShown: panel.shortcutHintsShown
45 readonly property bool shown: panel.x > -panel.width
47 // emitted when an application is selected
48 signal launcherApplicationSelected(string appId)
50 // emitted when the apps dash should be shown because of a swipe gesture
53 // emitted when the dash icon in the launcher has been tapped
58 panel.dismissTimer.stop()
60 panel.dismissTimer.restart()
64 onSuperPressedChanged: {
66 superPressTimer.start();
67 superLongPressTimer.start();
69 superPressTimer.stop();
70 superLongPressTimer.stop();
71 launcher.switchToNextState("");
72 panel.shortcutHintsShown = false;
76 onSuperTabPressedChanged: {
77 if (superTabPressed) {
78 switchToNextState("visible")
79 panel.highlightIndex = -1;
81 superPressTimer.stop();
82 superLongPressTimer.stop();
84 if (panel.highlightIndex == -1) {
86 } else if (panel.highlightIndex >= 0){
87 launcherApplicationSelected(LauncherModel.get(panel.highlightIndex).appId);
89 panel.highlightIndex = -2;
90 switchToNextState("");
95 onLockedVisibleChanged: {
96 if (lockedVisible && state == "") {
97 panel.dismissTimer.stop();
98 fadeOutAnimation.stop();
99 switchToNextState("visible")
100 } else if (!lockedVisible && state == "visible") {
106 switchToNextState("")
110 if (!root.lockedVisible) {
111 fadeOutAnimation.start();
115 function switchToNextState(state) {
116 animateTimer.nextState = state
117 animateTimer.start();
121 if (available && !dragArea.dragging) {
122 teaseTimer.mode = "teasing"
128 if (available && root.state == "") {
129 teaseTimer.mode = "hinting"
134 function pushEdge(amount) {
135 if (root.state === "") {
136 edgeBarrier.push(amount);
140 function openForKeyboardNavigation() {
141 panel.highlightIndex = -1; // The BFB
143 switchToNextState("visible")
149 panel.highlightPrevious();
150 event.accepted = true;
154 panel.highlightNext()
156 panel.highlightPrevious();
158 event.accepted = true;
161 panel.highlightNext();
162 event.accepted = true;
166 panel.highlightPrevious();
168 panel.highlightNext();
170 event.accepted = true;
174 panel.openQuicklist(panel.highlightIndex)
175 event.accepted = true;
178 panel.highlightIndex = -2;
179 // Falling through intentionally
183 if (panel.highlightIndex == -1) {
185 } else if (panel.highlightIndex >= 0) {
186 launcherApplicationSelected(LauncherModel.get(panel.highlightIndex).appId);
189 panel.highlightIndex = -2
190 event.accepted = true;
199 switchToNextState("visible")
204 id: superLongPressTimer
207 switchToNextState("visible")
208 panel.shortcutHintsShown = true;
214 interval: mode == "teasing" ? 200 : 300
215 property string mode: "teasing"
218 // Because the animation on x is disabled while dragging
219 // switching state directly in the drag handlers would not animate
220 // the completion of the hide/reveal gesture. Lets update the state
221 // machine and switch to the final state in the next event loop run
224 objectName: "animateTimer"
226 property string nextState: ""
228 if (root.lockedVisible && nextState == "") {
229 // Due to binding updates when switching between modes
230 // it could happen that our request to show will be overwritten
231 // with a hide request. Rewrite it when we know hiding is not allowed.
232 nextState = "visible"
235 // switching to an intermediate state here to make sure all the
236 // values are restored, even if we were already in the target state
238 root.state = nextState
243 target: LauncherModel
249 onLanguageChanged: LauncherModel.refresh()
252 SequentialAnimation {
256 animateTimer.stop(); // Don't change the state behind our back
257 panel.layer.enabled = true
260 UbuntuNumberAnimation {
263 easing.type: Easing.InQuad
268 panel.layer.enabled = false
269 panel.animate = false;
271 panel.x = -panel.width
273 panel.animate = true;
281 enabled: root.state == "visible" && (!root.lockedVisible || panel.highlightIndex >= -1)
284 mouse.accepted = false;
285 panel.highlightIndex = -2;
292 enabled: root.available && (root.state == "visible" || root.state == "visibleTemporary") && !root.lockedVisible
294 anchors.rightMargin: -units.gu(2)
302 if (panel.x < -panel.width/3) {
303 root.switchToNextState("")
305 root.switchToNextState("visible")
314 enabled: root.available
315 onPassed: { root.switchToNextState("visibleTemporary"); }
316 material: Component {
322 anchors.centerIn: parent
324 GradientStop { position: 0.0; color: Qt.rgba(panel.color.r, panel.color.g, panel.color.b, .5)}
325 GradientStop { position: 1.0; color: Qt.rgba(panel.color.r,panel.color.g,panel.color.b,0)}
334 objectName: "launcherPanel"
335 enabled: root.available && root.state == "visible" || root.state == "visibleTemporary"
336 width: root.panelWidth
339 bottom: parent.bottom
342 visible: root.x > 0 || x > -width || dragArea.pressed
345 property var dismissTimer: Timer { interval: 500 }
347 target: panel.dismissTimer
349 if (root.autohideEnabled && !root.lockedVisible) {
350 if (!panel.preventHiding) {
353 panel.dismissTimer.restart()
359 property bool animate: true
361 onApplicationSelected: {
363 launcherApplicationSelected(appId)
370 onPreventHidingChanged: {
371 if (panel.dismissTimer.running) {
372 panel.dismissTimer.restart();
376 onKbdNavigationCancelled: {
377 panel.highlightIndex = -2;
383 enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate;
386 easing.type: Easing.OutCubic
390 Behavior on opacity {
392 duration: UbuntuAnimation.FastDuration; easing.type: Easing.OutCubic
399 objectName: "launcherDragArea"
401 direction: Direction.Rightwards
403 enabled: root.available
404 x: -root.x // so if launcher is adjusted relative to screen, we stay put (like tutorial does when teasing)
405 width: root.dragAreaWidth
409 if (!dragging || launcher.state == "visible")
412 panel.x = -panel.width + Math.min(Math.max(0, distance), panel.width);
417 if (distance > panel.width / 2) {
418 root.switchToNextState("visible")
419 if (distance > minimizeDistance) {
422 } else if (root.state === "") {
423 // didn't drag far enough. rollback
424 root.switchToNextState("")
432 name: "" // hidden state. Must be the default state ("") because "when:" falls back to this.
442 x: -root.x // so we never go past panelWidth, even when teased by tutorial
446 name: "visibleTemporary"
450 autohideEnabled: true
455 when: teaseTimer.running && teaseTimer.mode == "teasing"
458 x: -root.panelWidth + units.gu(2)
463 when: teaseTimer.running && teaseTimer.mode == "hinting"