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 contentEnabled: true
40 property bool showOnClick: true
41 property color panelColor: UbuntuColors.jet
43 signal showTapped(point position)
45 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
46 // use its own values. Need to ask design about this.
47 showAnimation: StandardAnimation {
50 duration: UbuntuAnimation.BriskDuration
51 easing.type: Easing.OutCubic
54 hideAnimation: StandardAnimation {
56 to: minimizedPanelHeight
57 duration: UbuntuAnimation.BriskDuration
58 easing.type: Easing.OutCubic
61 height: minimizedPanelHeight
63 onUnitProgressChanged: d.updateState()
64 clip: root.partiallyOpened
78 objectName: "menuContent"
79 color: root.panelColor
86 height: openedHeight - bar.height - handle.height
87 indicatorsModel: root.indicatorsModel
88 visible: root.unitProgress > 0
89 enabled: contentEnabled
90 currentMenuIndex: bar.currentItemIndex
102 active: d.activeDragHandle ? true : false
104 //small shadow gradient at bottom of menu
111 height: units.gu(0.5)
113 GradientStop { position: 0.0; color: "transparent" }
114 GradientStop { position: 1.0; color: root.panelColor }
127 objectName: "indicatorsBar"
134 enableLateralChanges: false
136 unitProgress: root.unitProgress
138 height: expanded ? expandedPanelHeight : minimizedPanelHeight
139 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
145 anchors.left: bar.left
148 forceScrollingPercentage: 0.33
149 stopScrollThreshold: units.gu(0.75)
150 direction: Qt.RightToLeft
153 onScroll: bar.addScrollOffset(-scrollAmount);
159 anchors.right: bar.right
162 forceScrollingPercentage: 0.33
163 stopScrollThreshold: units.gu(0.75)
164 direction: Qt.LeftToRight
167 onScroll: bar.addScrollOffset(scrollAmount);
171 anchors.bottom: parent.bottom
172 anchors.left: parent.left
173 anchors.right: parent.right
174 height: minimizedPanelHeight
175 enabled: __showDragHandle.enabled && showOnClick
177 bar.selectItemAt(mouseX)
184 objectName: "showDragHandle"
185 anchors.bottom: parent.bottom
186 anchors.left: parent.left
187 anchors.right: parent.right
188 height: minimizedPanelHeight
189 direction: Direction.Downwards
190 enabled: !root.shown && root.available
191 autoCompleteDragThreshold: maxTotalDragDistance / 2
196 touchPressTime = new Date().getTime();
198 var touchReleaseTime = new Date().getTime();
199 if (touchReleaseTime - touchPressTime <= 300) {
200 root.showTapped(Qt.point(touchSceneX, touchSceneY));
204 property var touchPressTime
206 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
207 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
208 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
209 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
213 anchors.fill: __hideDragHandle
214 enabled: __hideDragHandle.enabled
215 onClicked: root.hide()
220 objectName: "hideDragHandle"
222 direction: Direction.Upwards
223 enabled: root.shown && root.available
224 hintDisplacement: units.gu(3)
225 autoCompleteDragThreshold: maxTotalDragDistance / 6
227 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
229 onTouchSceneXChanged: {
230 if (root.state === "locked") {
231 d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
232 d.lastHideTouchSceneX = touchSceneX;
237 PanelVelocityCalculator {
238 id: yVelocityCalculator
239 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
240 trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
242 onVelocityAboveThresholdChanged: d.updateState()
246 target: showAnimation
248 if (showAnimation.running) {
249 root.state = "commit";
255 target: hideAnimation
257 if (hideAnimation.running) {
258 root.state = "initial";
265 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
266 property bool hasCommitted: false
267 property real lastHideTouchSceneX: 0
268 property real xDisplacementSinceLock: 0
269 onXDisplacementSinceLockChanged: d.updateState()
271 property real rowMappedLateralPosition: {
272 if (!d.activeDragHandle) return -1;
273 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
276 function updateState() {
277 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
278 if (unitProgress <= 0) {
279 root.state = "initial";
280 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
281 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
282 root.state = "locked";
284 root.state = "reveal";
293 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
299 yVelocityCalculator.reset();
300 // initial item selection
301 if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
302 d.hasCommitted = false;
308 // changes to lateral touch position effect which indicator is selected
309 lateralPosition: d.rowMappedLateralPosition
310 // vertical velocity determines if changes in lateral position has an effect
311 enableLateralChanges: d.activeDragHandle &&
312 !yVelocityCalculator.velocityAboveThreshold
314 // left scroll bar handling
318 if (!d.activeDragHandle) return -1;
319 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
323 // right scroll bar handling
325 target: rightScroller
327 if (!d.activeDragHandle) return -1;
328 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
337 d.xDisplacementSinceLock = 0;
338 d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
341 PropertyChanges { target: bar; expanded: true }
346 PropertyChanges { target: bar; interactive: true }
350 lastHideTouchSceneX: 0
351 xDisplacementSinceLock: 0
352 restoreEntryValues: false