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
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 currentMenuIndex: bar.currentItemIndex
99 active: d.activeDragHandle ? true : false
101 //small shadow gradient at bottom of menu
108 height: units.gu(0.5)
110 GradientStop { position: 0.0; color: "transparent" }
111 GradientStop { position: 1.0; color: theme.palette.normal.background }
124 objectName: "indicatorsBar"
131 enableLateralChanges: false
133 unitProgress: root.unitProgress
135 height: expanded ? expandedPanelHeight : minimizedPanelHeight
136 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
142 anchors.left: bar.left
145 forceScrollingPercentage: 0.33
146 stopScrollThreshold: units.gu(0.75)
147 direction: Qt.RightToLeft
150 onScroll: bar.addScrollOffset(-scrollAmount);
156 anchors.right: bar.right
159 forceScrollingPercentage: 0.33
160 stopScrollThreshold: units.gu(0.75)
161 direction: Qt.LeftToRight
164 onScroll: bar.addScrollOffset(scrollAmount);
168 anchors.bottom: parent.bottom
169 anchors.left: parent.left
170 anchors.right: parent.right
171 height: minimizedPanelHeight
172 enabled: __showDragHandle.enabled && showOnClick
174 bar.selectItemAt(mouseX)
181 objectName: "showDragHandle"
182 anchors.bottom: parent.bottom
183 anchors.left: parent.left
184 anchors.right: parent.right
185 height: minimizedPanelHeight
186 direction: Direction.Downwards
187 enabled: !root.shown && root.available
188 autoCompleteDragThreshold: maxTotalDragDistance / 2
193 touchPressTime = new Date().getTime();
195 var touchReleaseTime = new Date().getTime();
196 if (touchReleaseTime - touchPressTime <= 300) {
197 root.showTapped(Qt.point(touchSceneX, touchSceneY));
201 property var touchPressTime
203 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
204 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
205 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
206 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
210 anchors.fill: __hideDragHandle
211 enabled: __hideDragHandle.enabled
212 onClicked: root.hide()
217 objectName: "hideDragHandle"
219 direction: Direction.Upwards
220 enabled: root.shown && root.available
221 hintDisplacement: units.gu(3)
222 autoCompleteDragThreshold: maxTotalDragDistance / 6
224 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
226 onTouchSceneXChanged: {
227 if (root.state === "locked") {
228 d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
229 d.lastHideTouchSceneX = touchSceneX;
234 PanelVelocityCalculator {
235 id: yVelocityCalculator
236 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
237 trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
239 onVelocityAboveThresholdChanged: d.updateState()
243 target: showAnimation
245 if (showAnimation.running) {
246 root.state = "commit";
252 target: hideAnimation
254 if (hideAnimation.running) {
255 root.state = "initial";
262 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
263 property bool hasCommitted: false
264 property real lastHideTouchSceneX: 0
265 property real xDisplacementSinceLock: 0
266 onXDisplacementSinceLockChanged: d.updateState()
268 property real rowMappedLateralPosition: {
269 if (!d.activeDragHandle) return -1;
270 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
273 function updateState() {
274 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
275 if (unitProgress <= 0) {
276 root.state = "initial";
277 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
278 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
279 root.state = "locked";
281 root.state = "reveal";
290 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
296 yVelocityCalculator.reset();
297 // initial item selection
298 if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
299 d.hasCommitted = false;
305 // changes to lateral touch position effect which indicator is selected
306 lateralPosition: d.rowMappedLateralPosition
307 // vertical velocity determines if changes in lateral position has an effect
308 enableLateralChanges: d.activeDragHandle &&
309 !yVelocityCalculator.velocityAboveThreshold
311 // left scroll bar handling
315 if (!d.activeDragHandle) return -1;
316 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
320 // right scroll bar handling
322 target: rightScroller
324 if (!d.activeDragHandle) return -1;
325 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
334 d.xDisplacementSinceLock = 0;
335 d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
338 PropertyChanges { target: bar; expanded: true }
343 PropertyChanges { target: bar; interactive: true }
347 lastHideTouchSceneX: 0
348 xDisplacementSinceLock: 0
349 restoreEntryValues: false