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 available: true // can be used to disable all interactions
28 property alias inverted: panel.inverted
29 property bool shadeBackground: true // can be used to disable background shade when launcher is visible
31 property int panelWidth: units.gu(8)
32 property int dragAreaWidth: units.gu(1)
33 property int minimizeDistance: units.gu(26)
34 property real progress: dragArea.dragging && dragArea.touchX > panelWidth ?
35 (width * (dragArea.touchX-panelWidth) / (width - panelWidth)) : 0
37 readonly property bool dragging: dragArea.dragging
38 readonly property real dragDistance: dragArea.dragging ? dragArea.touchX : 0
39 readonly property real visibleWidth: panel.width + panel.x
41 readonly property bool shown: panel.x > -panel.width
43 // emitted when an application is selected
44 signal launcherApplicationSelected(string appId)
46 // emitted when the apps dash should be shown because of a swipe gesture
49 // emitted when the dash icon in the launcher has been tapped
56 dismissTimer.restart()
65 fadeOutAnimation.start();
68 function switchToNextState(state) {
69 animateTimer.nextState = state
74 if (available && !dragArea.dragging) {
75 teaseTimer.mode = "teasing"
81 if (available && root.state == "") {
82 teaseTimer.mode = "hinting"
87 function pushEdge(amount) {
88 if (root.state === "") {
89 edgeBarrier.push(amount);
95 interval: mode == "teasing" ? 200 : 300
96 property string mode: "teasing"
101 objectName: "dismissTimer"
104 if (root.autohideEnabled) {
105 if (!panel.preventHiding) {
108 dismissTimer.restart()
114 // Because the animation on x is disabled while dragging
115 // switching state directly in the drag handlers would not animate
116 // the completion of the hide/reveal gesture. Lets update the state
117 // machine and switch to the final state in the next event loop run
120 objectName: "animateTimer"
122 property string nextState: ""
124 // switching to an intermediate state here to make sure all the
125 // values are restored, even if we were already in the target state
127 root.state = nextState
132 target: LauncherModel
138 onLanguageChanged: LauncherModel.refresh()
141 SequentialAnimation {
145 animateTimer.stop(); // Don't change the state behind our back
146 panel.layer.enabled = true
149 UbuntuNumberAnimation {
152 easing.type: Easing.InQuad
157 panel.layer.enabled = false
158 panel.animate = false;
160 panel.x = -panel.width
162 panel.animate = true;
169 enabled: root.available && (root.state == "visible" || root.state == "visibleTemporary")
171 anchors.rightMargin: -units.gu(2)
179 if (panel.x < -panel.width/3) {
180 root.switchToNextState("")
182 root.switchToNextState("visible")
190 enabled: root.shadeBackground && root.state == "visible"
201 opacity: root.shadeBackground && root.state == "visible" ? 0.6 : 0
203 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.BriskDuration } }
210 enabled: root.available
211 onPassed: { root.switchToNextState("visibleTemporary"); }
212 material: Component {
218 anchors.centerIn: parent
220 GradientStop { position: 0.0; color: panel.color}
221 GradientStop { position: 1.0; color: Qt.rgba(panel.r,panel.g,panel.b,0)}
230 objectName: "launcherPanel"
231 enabled: root.available && root.state == "visible" || root.state == "visibleTemporary"
232 width: root.panelWidth
235 bottom: parent.bottom
238 visible: root.x > 0 || x > -width || dragArea.pressed
241 property bool animate: true
243 onApplicationSelected: {
245 launcherApplicationSelected(appId)
252 onPreventHidingChanged: {
253 if (dismissTimer.running) {
254 dismissTimer.restart();
259 enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate;
262 easing.type: Easing.OutCubic
266 Behavior on opacity {
268 duration: UbuntuAnimation.FastDuration; easing.type: Easing.OutCubic
273 DirectionalDragArea {
275 objectName: "launcherDragArea"
277 direction: Direction.Rightwards
279 enabled: root.available
280 x: -root.x // so if launcher is adjusted relative to screen, we stay put (like tutorial does when teasing)
281 width: root.dragAreaWidth
285 if (!dragging || launcher.state == "visible")
288 panel.x = -panel.width + Math.min(Math.max(0, distance), panel.width);
293 if (distance > panel.width / 2) {
294 root.switchToNextState("visible")
295 if (distance > minimizeDistance) {
298 } else if (root.state === "") {
299 // didn't drag far enough. rollback
300 root.switchToNextState("")
308 name: "" // hidden state. Must be the default state ("") because "when:" falls back to this.
318 x: -root.x // so we never go past panelWidth, even when teased by tutorial
322 name: "visibleTemporary"
326 autohideEnabled: true
331 when: teaseTimer.running && teaseTimer.mode == "teasing"
334 x: -root.panelWidth + units.gu(2)
339 when: teaseTimer.running && teaseTimer.mode == "hinting"