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 "../Components"
19 import Ubuntu.Components 0.1
20 import Ubuntu.Gestures 0.1
21 import Unity.Launcher 0.1
26 property bool available: true // can be used to disable all interactions
28 property int panelWidth: units.gu(8)
29 property int dragAreaWidth: units.gu(1)
30 property int minimizeDistance: units.gu(26)
31 property real progress: dragArea.dragging && dragArea.touchX > panelWidth ?
32 (width * (dragArea.touchX-panelWidth) / (width - panelWidth)) : 0
34 readonly property bool shown: panel.x > -panel.width
36 // emitted when an application is selected
37 signal launcherApplicationSelected(string appId)
39 // emitted when the apps dash should be shown because of a swipe gesture
42 // emitted when the dash icon in the launcher has been tapped
49 dismissTimer.restart()
58 fadeOutAnimation.start();
61 function switchToNextState(state) {
62 animateTimer.nextState = state
67 if (available && !dragArea.dragging) {
68 teaseTimer.mode = "teasing"
74 if (available && root.state == "") {
75 teaseTimer.mode = "hinting"
82 interval: mode == "teasing" ? 200 : 300
83 property string mode: "teasing"
88 objectName: "dismissTimer"
91 if (!panel.preventHiding) {
94 dismissTimer.restart()
99 // Because the animation on x is disabled while dragging
100 // switching state directly in the drag handlers would not animate
101 // the completion of the hide/reveal gesture. Lets update the state
102 // machine and switch to the final state in the next event loop run
105 objectName: "animateTimer"
107 property string nextState: ""
109 // switching to an intermediate state here to make sure all the
110 // values are restored, even if we were already in the target state
112 root.state = nextState
117 target: LauncherModel
121 SequentialAnimation {
125 panel.layer.enabled = true
128 UbuntuNumberAnimation {
131 easing.type: Easing.InQuad
136 panel.layer.enabled = false
137 panel.animate = false;
139 panel.x = -panel.width
141 panel.animate = true;
148 enabled: root.state == "visible"
150 anchors.rightMargin: -units.gu(2)
158 if (panel.x < -panel.width/3) {
159 root.switchToNextState("")
161 root.switchToNextState("visible")
169 left: launcherDragArea.right
172 bottom: parent.bottom
174 enabled: root.state == "visible"
184 opacity: root.state == "visible" ? 0.6 : 0
186 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.BriskDuration } }
191 objectName: "launcherPanel"
192 enabled: root.available
193 width: root.panelWidth
196 bottom: parent.bottom
199 visible: x > -width || dragArea.status === DirectionalDragArea.Undecided
202 property bool animate: true
204 onApplicationSelected: {
206 launcherApplicationSelected(appId)
213 onPreventHidingChanged: {
214 if (dismissTimer.running) {
215 dismissTimer.restart();
220 enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate;
223 easing.type: Easing.OutCubic
227 Behavior on opacity {
229 duration: UbuntuAnimation.FastDuration; easing.type: Easing.OutCubic
236 objectName: "launcherDragArea"
238 direction: Direction.Rightwards
240 enabled: root.available
241 width: root.dragAreaWidth
245 if (status !== DirectionalDragArea.Recognized || launcher.state == "visible")
248 // When the gesture finally gets recognized, the finger will likely be
249 // reasonably far from the edge. If we made the panel immediately
250 // follow the finger position it would be visually unpleasant as it
251 // would appear right next to the user's finger out of nowhere.
252 // Instead, we make the panel go towards the user's finger in several
253 // steps. ie., in an animated way.
254 var targetPanelX = Math.min(0, touchX - panel.width)
255 var delta = targetPanelX - panel.x
256 // the trick is not to go all the way (1.0) as it would cause a sudden jump
257 panel.x += 0.4 * delta
262 if (distance > panel.width / 2) {
263 root.switchToNextState("visible")
264 if (distance > minimizeDistance) {
268 root.switchToNextState("")
276 name: "" // hidden state. Must be the default state ("") because "when:" falls back to this.
291 when: teaseTimer.running && teaseTimer.mode == "teasing"
294 x: -root.panelWidth + units.gu(2)
299 when: teaseTimer.running && teaseTimer.mode == "hinting"