2 * Copyright (C) 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.1
19 import Ubuntu.Gestures 0.1
20 import "../Components"
25 property alias indicatorsModel: bar.indicatorsModel
26 property alias showDragHandle: __showDragHandle
27 property alias hideDragHandle: __hideDragHandle
28 property alias overFlowWidth: bar.overFlowWidth
29 property alias verticalVelocityThreshold: yVelocityCalculator.velocityThreshold
30 property int minimizedPanelHeight: units.gu(3)
31 property int expandedPanelHeight: units.gu(7)
32 property real openedHeight: units.gu(71)
33 readonly property real unitProgress: Math.max(0, (height - minimizedPanelHeight) / (openedHeight - minimizedPanelHeight))
34 readonly property bool fullyOpened: unitProgress >= 1
35 readonly property bool partiallyOpened: unitProgress > 0 && unitProgress < 1.0
36 readonly property bool fullyClosed: unitProgress == 0
37 property bool enableHint: true
38 property bool contentEnabled: true
39 property bool showOnClick: true
40 property color panelColor: "black"
42 signal showTapped(point position)
44 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
45 // use its own values. Need to ask design about this.
46 showAnimation: StandardAnimation {
49 duration: UbuntuAnimation.BriskDuration
50 easing.type: Easing.OutCubic
53 hideAnimation: StandardAnimation {
55 to: minimizedPanelHeight
56 duration: UbuntuAnimation.BriskDuration
57 easing.type: Easing.OutCubic
60 height: minimizedPanelHeight
62 onUnitProgressChanged: d.updateState()
63 clip: root.partiallyOpened
77 objectName: "menuContent"
84 height: openedHeight - bar.height - handle.height
85 indicatorsModel: root.indicatorsModel
86 visible: root.unitProgress > 0
87 enabled: contentEnabled
88 currentMenuIndex: bar.currentItemIndex
100 active: d.activeDragHandle ? true : false
102 //small shadow gradient at bottom of menu
109 height: units.gu(0.5)
111 GradientStop { position: 0.0; color: "transparent" }
112 GradientStop { position: 1.0; color: "black" }
125 objectName: "indicatorsBar"
132 enableLateralChanges: false
134 unitProgress: root.unitProgress
136 height: expanded ? expandedPanelHeight : minimizedPanelHeight
137 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
143 anchors.left: bar.left
146 forceScrollingPercentage: 0.33
147 stopScrollThreshold: units.gu(0.75)
148 direction: Qt.RightToLeft
151 onScroll: bar.addScrollOffset(-scrollAmount);
157 anchors.right: bar.right
160 forceScrollingPercentage: 0.33
161 stopScrollThreshold: units.gu(0.75)
162 direction: Qt.LeftToRight
165 onScroll: bar.addScrollOffset(scrollAmount);
169 anchors.bottom: parent.bottom
170 anchors.left: parent.left
171 anchors.right: parent.right
172 height: minimizedPanelHeight
173 enabled: __showDragHandle.enabled && showOnClick
175 bar.selectItemAt(mouseX)
182 objectName: "showDragHandle"
183 anchors.bottom: parent.bottom
184 anchors.left: parent.left
185 anchors.right: parent.right
186 height: minimizedPanelHeight
187 direction: Direction.Downwards
188 enabled: !root.shown && root.available
189 autoCompleteDragThreshold: maxTotalDragDistance / 2
194 touchPressTime = new Date().getTime();
196 var touchReleaseTime = new Date().getTime();
197 if (touchReleaseTime - touchPressTime <= 300) {
198 root.showTapped(Qt.point(touchSceneX, touchSceneY));
202 property var touchPressTime
204 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
205 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
206 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
207 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
211 anchors.fill: __hideDragHandle
212 enabled: __hideDragHandle.enabled
213 onClicked: root.hide()
218 objectName: "hideDragHandle"
220 direction: Direction.Upwards
221 enabled: root.shown && root.available
222 hintDisplacement: units.gu(3)
223 autoCompleteDragThreshold: maxTotalDragDistance / 6
225 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
227 onTouchSceneXChanged: {
228 if (root.state === "locked") {
229 d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
230 d.lastHideTouchSceneX = touchSceneX;
235 PanelVelocityCalculator {
236 id: yVelocityCalculator
237 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
238 trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
240 onVelocityAboveThresholdChanged: d.updateState()
244 target: showAnimation
246 if (showAnimation.running) {
247 root.state = "commit";
253 target: hideAnimation
255 if (hideAnimation.running) {
256 root.state = "initial";
263 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
264 property bool hasCommitted: false
265 property real lastHideTouchSceneX: 0
266 property real xDisplacementSinceLock: 0
267 onXDisplacementSinceLockChanged: d.updateState()
269 property real rowMappedLateralPosition: {
270 if (!d.activeDragHandle) return -1;
271 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
274 function updateState() {
275 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
276 if (unitProgress <= 0) {
277 root.state = "initial";
278 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
279 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
280 root.state = "locked";
282 root.state = "reveal";
291 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
297 yVelocityCalculator.reset();
298 // initial item selection
299 if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
300 d.hasCommitted = false;
306 // changes to lateral touch position effect which indicator is selected
307 lateralPosition: d.rowMappedLateralPosition
308 // vertical velocity determines if changes in lateral position has an effect
309 enableLateralChanges: d.activeDragHandle &&
310 !yVelocityCalculator.velocityAboveThreshold
312 // left scroll bar handling
316 if (!d.activeDragHandle) return -1;
317 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
321 // right scroll bar handling
323 target: rightScroller
325 if (!d.activeDragHandle) return -1;
326 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
335 d.xDisplacementSinceLock = 0;
336 d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
339 PropertyChanges { target: bar; expanded: true }
344 PropertyChanges { target: bar; interactive: true }
348 lastHideTouchSceneX: 0
349 xDisplacementSinceLock: 0
350 restoreEntryValues: false