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;
173 panel.openQuicklist(panel.highlightIndex)
174 event.accepted = true;
177 panel.highlightIndex = -2;
178 // Falling through intentionally
182 if (panel.highlightIndex == -1) {
184 } else if (panel.highlightIndex >= 0) {
185 launcherApplicationSelected(LauncherModel.get(panel.highlightIndex).appId);
188 panel.highlightIndex = -2
189 event.accepted = true;
198 switchToNextState("visible")
203 id: superLongPressTimer
206 switchToNextState("visible")
207 panel.shortcutHintsShown = true;
213 interval: mode == "teasing" ? 200 : 300
214 property string mode: "teasing"
217 // Because the animation on x is disabled while dragging
218 // switching state directly in the drag handlers would not animate
219 // the completion of the hide/reveal gesture. Lets update the state
220 // machine and switch to the final state in the next event loop run
223 objectName: "animateTimer"
225 property string nextState: ""
227 if (root.lockedVisible && nextState == "") {
228 // Due to binding updates when switching between modes
229 // it could happen that our request to show will be overwritten
230 // with a hide request. Rewrite it when we know hiding is not allowed.
231 nextState = "visible"
234 // switching to an intermediate state here to make sure all the
235 // values are restored, even if we were already in the target state
237 root.state = nextState
242 target: LauncherModel
248 onLanguageChanged: LauncherModel.refresh()
251 SequentialAnimation {
255 animateTimer.stop(); // Don't change the state behind our back
256 panel.layer.enabled = true
259 UbuntuNumberAnimation {
262 easing.type: Easing.InQuad
267 panel.layer.enabled = false
268 panel.animate = false;
270 panel.x = -panel.width
272 panel.animate = true;
280 enabled: root.state == "visible" && (!root.lockedVisible || panel.highlightIndex >= -1)
283 mouse.accepted = false;
284 panel.highlightIndex = -2;
291 enabled: root.available && (root.state == "visible" || root.state == "visibleTemporary") && !root.lockedVisible
293 anchors.rightMargin: -units.gu(2)
301 if (panel.x < -panel.width/3) {
302 root.switchToNextState("")
304 root.switchToNextState("visible")
313 enabled: root.available
314 onPassed: { root.switchToNextState("visibleTemporary"); }
315 material: Component {
321 anchors.centerIn: parent
323 GradientStop { position: 0.0; color: Qt.rgba(panel.color.r, panel.color.g, panel.color.b, .5)}
324 GradientStop { position: 1.0; color: Qt.rgba(panel.color.r,panel.color.g,panel.color.b,0)}
333 objectName: "launcherPanel"
334 enabled: root.available && root.state == "visible" || root.state == "visibleTemporary"
335 width: root.panelWidth
338 bottom: parent.bottom
341 visible: root.x > 0 || x > -width || dragArea.pressed
344 property var dismissTimer: Timer { interval: 500 }
346 target: panel.dismissTimer
348 if (root.autohideEnabled && !root.lockedVisible) {
349 if (!panel.preventHiding) {
352 panel.dismissTimer.restart()
358 property bool animate: true
360 onApplicationSelected: {
362 launcherApplicationSelected(appId)
369 onPreventHidingChanged: {
370 if (panel.dismissTimer.running) {
371 panel.dismissTimer.restart();
375 onKbdNavigationCancelled: {
376 panel.highlightIndex = -2;
382 enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate;
385 easing.type: Easing.OutCubic
389 Behavior on opacity {
391 duration: UbuntuAnimation.FastDuration; easing.type: Easing.OutCubic
398 objectName: "launcherDragArea"
400 direction: Direction.Rightwards
402 enabled: root.available
403 x: -root.x // so if launcher is adjusted relative to screen, we stay put (like tutorial does when teasing)
404 width: root.dragAreaWidth
408 if (!dragging || launcher.state == "visible")
411 panel.x = -panel.width + Math.min(Math.max(0, distance), panel.width);
416 if (distance > panel.width / 2) {
417 root.switchToNextState("visible")
418 if (distance > minimizeDistance) {
421 } else if (root.state === "") {
422 // didn't drag far enough. rollback
423 root.switchToNextState("")
431 name: "" // hidden state. Must be the default state ("") because "when:" falls back to this.
441 x: -root.x // so we never go past panelWidth, even when teased by tutorial
445 name: "visibleTemporary"
449 autohideEnabled: true
454 when: teaseTimer.running && teaseTimer.mode == "teasing"
457 x: -root.panelWidth + units.gu(2)
462 when: teaseTimer.running && teaseTimer.mode == "hinting"