2
* Copyright (C) 2014-2016 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
83
acceptedButtons: Qt.AllButtons
84
onWheel: wheel.accepted = true;
89
objectName: "menuContent"
96
height: openedHeight - bar.height - handle.height
97
indicatorsModel: root.indicatorsModel
98
visible: root.unitProgress > 0
99
currentMenuIndex: bar.currentItemIndex
108
bottom: parent.bottom
111
active: d.activeDragHandle ? true : false
113
//small shadow gradient at bottom of menu
120
height: units.gu(0.5)
122
GradientStop { position: 0.0; color: "transparent" }
123
GradientStop { position: 1.0; color: theme.palette.normal.background }
136
objectName: "indicatorsBar"
143
enableLateralChanges: false
145
unitProgress: root.unitProgress
147
height: expanded ? expandedPanelHeight : minimizedPanelHeight
148
Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
154
anchors.left: bar.left
157
forceScrollingPercentage: 0.33
158
stopScrollThreshold: units.gu(0.75)
159
direction: Qt.RightToLeft
162
onScroll: bar.addScrollOffset(-scrollAmount);
168
anchors.right: bar.right
171
forceScrollingPercentage: 0.33
172
stopScrollThreshold: units.gu(0.75)
173
direction: Qt.LeftToRight
176
onScroll: bar.addScrollOffset(scrollAmount);
180
anchors.bottom: parent.bottom
181
anchors.left: parent.left
182
anchors.right: parent.right
183
height: minimizedPanelHeight
184
enabled: __showDragHandle.enabled && showOnClick
186
bar.selectItemAt(mouseX)
193
objectName: "showDragHandle"
194
anchors.bottom: parent.bottom
195
anchors.left: parent.left
196
anchors.right: parent.right
197
height: minimizedPanelHeight
198
direction: Direction.Downwards
199
enabled: !root.shown && root.available
200
autoCompleteDragThreshold: maxTotalDragDistance / 2
205
touchPressTime = new Date().getTime();
207
var touchReleaseTime = new Date().getTime();
208
if (touchReleaseTime - touchPressTime <= 300) {
213
property var touchPressTime
215
// using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
216
overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
217
maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
218
hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
222
anchors.fill: __hideDragHandle
223
enabled: __hideDragHandle.enabled
224
onClicked: root.hide()
229
objectName: "hideDragHandle"
231
direction: Direction.Upwards
232
enabled: root.shown && root.available
233
hintDisplacement: units.gu(3)
234
autoCompleteDragThreshold: maxTotalDragDistance / 6
236
maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
238
onTouchPositionChanged: {
239
if (root.state === "locked") {
240
d.xDisplacementSinceLock += (touchPosition.x - d.lastHideTouchX)
241
d.lastHideTouchX = touchPosition.x;
246
PanelVelocityCalculator {
247
id: yVelocityCalculator
248
velocityThreshold: d.hasCommitted ? 0.1 : 0.3
249
trackedValue: d.activeDragHandle ?
250
(Direction.isPositive(d.activeDragHandle.direction) ?
251
d.activeDragHandle.distance :
252
-d.activeDragHandle.distance)
255
onVelocityAboveThresholdChanged: d.updateState()
259
target: showAnimation
261
if (showAnimation.running) {
262
root.state = "commit";
268
target: hideAnimation
270
if (hideAnimation.running) {
271
root.state = "initial";
278
property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
279
property bool hasCommitted: false
280
property real lastHideTouchX: 0
281
property real xDisplacementSinceLock: 0
282
onXDisplacementSinceLockChanged: d.updateState()
284
property real rowMappedLateralPosition: {
285
if (!d.activeDragHandle) return -1;
286
return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchPosition.x, 0).x;
289
function updateState() {
290
if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
291
if (unitProgress <= 0) {
292
root.state = "initial";
293
// lock indicator if we've been committed and aren't moving too much laterally or too fast up.
294
} else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
295
root.state = "locked";
297
root.state = "reveal";
306
PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
312
yVelocityCalculator.reset();
313
// initial item selection
314
if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchPosition.x : -1);
315
d.hasCommitted = false;
321
// changes to lateral touch position effect which indicator is selected
322
lateralPosition: d.rowMappedLateralPosition
323
// vertical velocity determines if changes in lateral position has an effect
324
enableLateralChanges: d.activeDragHandle &&
325
!yVelocityCalculator.velocityAboveThreshold
327
// left scroll bar handling
331
if (!d.activeDragHandle) return -1;
332
var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchPosition.x, 0);
336
// right scroll bar handling
338
target: rightScroller
340
if (!d.activeDragHandle) return -1;
341
var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchPosition.x, 0);
350
d.xDisplacementSinceLock = 0;
351
d.lastHideTouchX = hideDragHandle.touchPosition.x;
354
PropertyChanges { target: bar; expanded: true }
359
PropertyChanges { target: bar; interactive: true }
364
xDisplacementSinceLock: 0
365
restoreEntryValues: false