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.3
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 alias currentIndicator: bar.currentIndicator
31 property int minimizedPanelHeight: units.gu(3)
32 property int expandedPanelHeight: units.gu(7)
33 property real openedHeight: units.gu(71)
34 readonly property real unitProgress: Math.max(0, (height - minimizedPanelHeight) / (openedHeight - minimizedPanelHeight))
35 readonly property bool fullyOpened: unitProgress >= 1
36 readonly property bool partiallyOpened: unitProgress > 0 && unitProgress < 1.0
37 readonly property bool fullyClosed: unitProgress == 0
38 property bool enableHint: true
39 property bool showOnClick: true
40 property color panelColor: theme.palette.normal.background
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: SequentialAnimation {
51 duration: UbuntuAnimation.BriskDuration
52 easing.type: Easing.OutCubic
54 // set binding in case units.gu changes while menu open, so height correctly adjusted to fit
55 ScriptAction { script: root.height = Qt.binding( function(){ return root.openedHeight; } ) }
58 hideAnimation: SequentialAnimation {
62 to: minimizedPanelHeight
63 duration: UbuntuAnimation.BriskDuration
64 easing.type: Easing.OutCubic
66 // set binding in case units.gu changes while menu closed, so menu adjusts to fit
67 ScriptAction { script: root.height = Qt.binding( function(){ return root.minimizedPanelHeight; } ) }
70 height: minimizedPanelHeight
72 onUnitProgressChanged: d.updateState()
73 clip: root.partiallyOpened
87 objectName: "menuContent"
94 height: openedHeight - bar.height - handle.height
95 indicatorsModel: root.indicatorsModel
96 visible: root.unitProgress > 0
97 currentMenuIndex: bar.currentItemIndex
106 bottom: parent.bottom
109 active: d.activeDragHandle ? true : false
111 //small shadow gradient at bottom of menu
118 height: units.gu(0.5)
120 GradientStop { position: 0.0; color: "transparent" }
121 GradientStop { position: 1.0; color: theme.palette.normal.background }
134 objectName: "indicatorsBar"
141 enableLateralChanges: false
143 unitProgress: root.unitProgress
145 height: expanded ? expandedPanelHeight : minimizedPanelHeight
146 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
152 anchors.left: bar.left
155 forceScrollingPercentage: 0.33
156 stopScrollThreshold: units.gu(0.75)
157 direction: Qt.RightToLeft
160 onScroll: bar.addScrollOffset(-scrollAmount);
166 anchors.right: bar.right
169 forceScrollingPercentage: 0.33
170 stopScrollThreshold: units.gu(0.75)
171 direction: Qt.LeftToRight
174 onScroll: bar.addScrollOffset(scrollAmount);
178 anchors.bottom: parent.bottom
179 anchors.left: parent.left
180 anchors.right: parent.right
181 height: minimizedPanelHeight
182 enabled: __showDragHandle.enabled && showOnClick
184 bar.selectItemAt(mouseX)
191 objectName: "showDragHandle"
192 anchors.bottom: parent.bottom
193 anchors.left: parent.left
194 anchors.right: parent.right
195 height: minimizedPanelHeight
196 direction: Direction.Downwards
197 enabled: !root.shown && root.available
198 autoCompleteDragThreshold: maxTotalDragDistance / 2
203 touchPressTime = new Date().getTime();
205 var touchReleaseTime = new Date().getTime();
206 if (touchReleaseTime - touchPressTime <= 300) {
211 property var touchPressTime
213 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
214 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
215 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
216 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
220 anchors.fill: __hideDragHandle
221 enabled: __hideDragHandle.enabled
222 onClicked: root.hide()
227 objectName: "hideDragHandle"
229 direction: Direction.Upwards
230 enabled: root.shown && root.available
231 hintDisplacement: units.gu(3)
232 autoCompleteDragThreshold: maxTotalDragDistance / 6
234 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
236 onTouchPositionChanged: {
237 if (root.state === "locked") {
238 d.xDisplacementSinceLock += (touchPosition.x - d.lastHideTouchX)
239 d.lastHideTouchX = touchPosition.x;
244 PanelVelocityCalculator {
245 id: yVelocityCalculator
246 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
247 trackedValue: d.activeDragHandle ?
248 (Direction.isPositive(d.activeDragHandle.direction) ?
249 d.activeDragHandle.distance :
250 -d.activeDragHandle.distance)
253 onVelocityAboveThresholdChanged: d.updateState()
257 target: showAnimation
259 if (showAnimation.running) {
260 root.state = "commit";
266 target: hideAnimation
268 if (hideAnimation.running) {
269 root.state = "initial";
276 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
277 property bool hasCommitted: false
278 property real lastHideTouchX: 0
279 property real xDisplacementSinceLock: 0
280 onXDisplacementSinceLockChanged: d.updateState()
282 property real rowMappedLateralPosition: {
283 if (!d.activeDragHandle) return -1;
284 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchPosition.x, 0).x;
287 function updateState() {
288 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
289 if (unitProgress <= 0) {
290 root.state = "initial";
291 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
292 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
293 root.state = "locked";
295 root.state = "reveal";
304 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
310 yVelocityCalculator.reset();
311 // initial item selection
312 if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchPosition.x : -1);
313 d.hasCommitted = false;
319 // changes to lateral touch position effect which indicator is selected
320 lateralPosition: d.rowMappedLateralPosition
321 // vertical velocity determines if changes in lateral position has an effect
322 enableLateralChanges: d.activeDragHandle &&
323 !yVelocityCalculator.velocityAboveThreshold
325 // left scroll bar handling
329 if (!d.activeDragHandle) return -1;
330 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchPosition.x, 0);
334 // right scroll bar handling
336 target: rightScroller
338 if (!d.activeDragHandle) return -1;
339 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchPosition.x, 0);
348 d.xDisplacementSinceLock = 0;
349 d.lastHideTouchX = hideDragHandle.touchPosition.x;
352 PropertyChanges { target: bar; expanded: true }
357 PropertyChanges { target: bar; interactive: true }
362 xDisplacementSinceLock: 0
363 restoreEntryValues: false