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"
24
property alias indicatorsModel: bar.indicatorsModel
25
property alias showDragHandle: __showDragHandle
26
property alias hideDragHandle: __hideDragHandle
27
property alias overFlowWidth: bar.overFlowWidth
28
property alias verticalVelocityThreshold: yVelocityCalculator.velocityThreshold
29
property int minimizedPanelHeight: units.gu(3)
30
property int expandedPanelHeight: units.gu(7)
31
property real openedHeight: units.gu(71)
32
readonly property real unitProgress: Math.max(0, (height - minimizedPanelHeight) / (openedHeight - minimizedPanelHeight))
33
readonly property bool fullyOpened: unitProgress >= 1
34
readonly property bool partiallyOpened: unitProgress > 0 && unitProgress < 1.0
35
readonly property bool fullyClosed: unitProgress == 0
36
property bool enableHint: true
37
property bool contentEnabled: true
38
property color panelColor: "black"
40
signal showTapped(point position)
42
// TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
43
// use its own values. Need to ask design about this.
44
showAnimation: StandardAnimation {
47
duration: UbuntuAnimation.BriskDuration
48
easing.type: Easing.OutCubic
51
hideAnimation: StandardAnimation {
53
to: minimizedPanelHeight
54
duration: UbuntuAnimation.BriskDuration
55
easing.type: Easing.OutCubic
58
height: minimizedPanelHeight
60
onUnitProgressChanged: d.updateState()
61
clip: root.partiallyOpened
70
objectName: "menuContent"
77
height: openedHeight - bar.height - handle.height
78
indicatorsModel: root.indicatorsModel
79
visible: root.unitProgress > 0
80
enabled: contentEnabled
81
currentMenuIndex: bar.currentItemIndex
92
active: d.activeDragHandle ? true : false
94
//small shadow gradient at bottom of menu
101
height: units.gu(0.5)
103
GradientStop { position: 0.0; color: "transparent" }
104
GradientStop { position: 1.0; color: "black" }
117
objectName: "indicatorsBar"
124
enableLateralChanges: false
126
unitProgress: root.unitProgress
128
height: expanded ? expandedPanelHeight : minimizedPanelHeight
129
Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
135
anchors.left: bar.left
138
forceScrollingPercentage: 0.33
139
stopScrollThreshold: units.gu(0.75)
140
direction: Qt.RightToLeft
143
onScroll: bar.addScrollOffset(-scrollAmount);
149
anchors.right: bar.right
152
forceScrollingPercentage: 0.33
153
stopScrollThreshold: units.gu(0.75)
154
direction: Qt.LeftToRight
157
onScroll: bar.addScrollOffset(scrollAmount);
162
anchors.bottom: parent.bottom
163
anchors.left: parent.left
164
anchors.right: parent.right
165
height: minimizedPanelHeight
166
direction: Direction.Downwards
167
enabled: !root.shown && root.available
168
autoCompleteDragThreshold: maxTotalDragDistance / 2
170
distanceThreshold: enableHint ? 0 : minimizedPanelHeight
172
onTapped: showTapped(Qt.point(touchSceneX, touchSceneY));
174
// using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
175
overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
176
maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
177
hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
183
direction: Direction.Upwards
184
enabled: root.shown && root.available
185
hintDisplacement: units.gu(3)
186
autoCompleteDragThreshold: maxTotalDragDistance / 6
188
maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
190
onTouchSceneXChanged: {
191
if (root.state === "locked") {
192
d.xDisplacementSinceLock += (touchSceneX - d.lastHideTouchSceneX)
193
d.lastHideTouchSceneX = touchSceneX;
198
PanelVelocityCalculator {
199
id: yVelocityCalculator
200
velocityThreshold: d.hasCommitted ? 0.1 : 0.3
201
trackedValue: d.activeDragHandle ? d.activeDragHandle.touchSceneY : 0
203
onVelocityAboveThresholdChanged: d.updateState()
207
target: showAnimation
209
if (showAnimation.running) {
210
root.state = "commit";
216
target: hideAnimation
218
if (hideAnimation.running) {
219
root.state = "initial";
226
property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
227
property bool hasCommitted: false
228
property real lastHideTouchSceneX: 0
229
property real xDisplacementSinceLock: 0
230
onXDisplacementSinceLockChanged: d.updateState()
232
property real rowMappedLateralPosition: {
233
if (!d.activeDragHandle) return -1;
234
return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchX, 0).x;
237
function updateState() {
238
if (!showAnimation.running && !hideAnimation.running) {
239
if (unitProgress <= 0) {
240
root.state = "initial";
241
// lock indicator if we've been committed and aren't moving too much laterally or too fast up.
242
} else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
243
root.state = "locked";
245
root.state = "reveal";
254
PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
260
yVelocityCalculator.reset();
261
// initial item selection
262
if (!d.hasCommitted) bar.selectItemAt(d.activeDragHandle ? d.activeDragHandle.touchX : -1);
263
d.hasCommitted = false;
269
// changes to lateral touch position effect which indicator is selected
270
lateralPosition: d.rowMappedLateralPosition
271
// vertical velocity determines if changes in lateral position has an effect
272
enableLateralChanges: d.activeDragHandle &&
273
!yVelocityCalculator.velocityAboveThreshold
275
// left scroll bar handling
279
if (!d.activeDragHandle) return -1;
280
var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchX, 0);
284
// right scroll bar handling
286
target: rightScroller
288
if (!d.activeDragHandle) return -1;
289
var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchX, 0);
298
d.xDisplacementSinceLock = 0;
299
d.lastHideTouchSceneX = hideDragHandle.touchSceneX;
302
PropertyChanges { target: bar; expanded: true }
307
PropertyChanges { target: bar; interactive: true }
311
lastHideTouchSceneX: 0
312
xDisplacementSinceLock: 0
313
restoreEntryValues: false