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 color panelColor: "black"
41 signal showTapped(point position)
43 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
44 // use its own values. Need to ask design about this.
45 showAnimation: StandardAnimation {
48 duration: UbuntuAnimation.BriskDuration
49 easing.type: Easing.OutCubic
52 hideAnimation: StandardAnimation {
54 to: minimizedPanelHeight
55 duration: UbuntuAnimation.BriskDuration
56 easing.type: Easing.OutCubic
59 height: minimizedPanelHeight
61 onUnitProgressChanged: d.updateState()
62 clip: root.partiallyOpened
75 objectName: "menuContent"
82 height: openedHeight - bar.height - handle.height
83 indicatorsModel: root.indicatorsModel
84 visible: root.unitProgress > 0
85 enabled: contentEnabled
86 currentMenuIndex: bar.currentItemIndex
97 active: d.activeDragHandle ? true : false
99 //small shadow gradient at bottom of menu
106 height: units.gu(0.5)
108 GradientStop { position: 0.0; color: "transparent" }
109 GradientStop { position: 1.0; color: "black" }
122 objectName: "indicatorsBar"
129 enableLateralChanges: false
131 unitProgress: root.unitProgress
133 height: expanded ? expandedPanelHeight : minimizedPanelHeight
134 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
140 anchors.left: bar.left
143 forceScrollingPercentage: 0.33
144 stopScrollThreshold: units.gu(0.75)
145 direction: Qt.RightToLeft
148 onScroll: bar.addScrollOffset(-scrollAmount);
154 anchors.right: bar.right
157 forceScrollingPercentage: 0.33
158 stopScrollThreshold: units.gu(0.75)
159 direction: Qt.LeftToRight
162 onScroll: bar.addScrollOffset(scrollAmount);
167 anchors.bottom: parent.bottom
168 anchors.left: parent.left
169 anchors.right: parent.right
170 height: minimizedPanelHeight
171 direction: Direction.Downwards
172 enabled: !root.shown && root.available
173 autoCompleteDragThreshold: maxTotalDragDistance / 2
175 distanceThreshold: enableHint ? 0 : minimizedPanelHeight
177 onTapped: showTapped(Qt.point(touchSceneX, touchSceneY));
179 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
180 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
181 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
182 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
188 direction: Direction.Upwards
189 enabled: root.shown && root.available
190 hintDisplacement: units.gu(3)
191 autoCompleteDragThreshold: maxTotalDragDistance / 6
193 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
195 onTouchSceneXChanged: {
196 if (root.state === "locked") {
197 d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
198 d.lastHideTouchSceneX = touchSceneX;
203 PanelVelocityCalculator {
204 id: yVelocityCalculator
205 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
206 trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
208 onVelocityAboveThresholdChanged: d.updateState()
212 target: showAnimation
214 if (showAnimation.running) {
215 root.state = "commit";
221 target: hideAnimation
223 if (hideAnimation.running) {
224 root.state = "initial";
231 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
232 property bool hasCommitted: false
233 property real lastHideTouchSceneX: 0
234 property real xDisplacementSinceLock: 0
235 onXDisplacementSinceLockChanged: d.updateState()
237 property real rowMappedLateralPosition: {
238 if (!d.activeDragHandle) return -1;
239 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
242 function updateState() {
243 if (!showAnimation.running && !hideAnimation.running) {
244 if (unitProgress <= 0) {
245 root.state = "initial";
246 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
247 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
248 root.state = "locked";
250 root.state = "reveal";
259 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
265 yVelocityCalculator.reset();
266 // initial item selection
267 if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
268 d.hasCommitted = false;
274 // changes to lateral touch position effect which indicator is selected
275 lateralPosition: d.rowMappedLateralPosition
276 // vertical velocity determines if changes in lateral position has an effect
277 enableLateralChanges: d.activeDragHandle &&
278 !yVelocityCalculator.velocityAboveThreshold
280 // left scroll bar handling
284 if (!d.activeDragHandle) return -1;
285 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
289 // right scroll bar handling
291 target: rightScroller
293 if (!d.activeDragHandle) return -1;
294 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
303 d.xDisplacementSinceLock = 0;
304 d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
307 PropertyChanges { target: bar; expanded: true }
312 PropertyChanges { target: bar; interactive: true }
316 lastHideTouchSceneX: 0
317 xDisplacementSinceLock: 0
318 restoreEntryValues: false