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/>.
18import Ubuntu.Components 1.3
19import Ubuntu.Gestures 0.1
25 property alias model: bar.model
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 property bool enableHint: true
34 property bool showOnClick: true
35 property color panelColor: theme.palette.normal.background
37 property alias alignment: bar.alignment
38 property alias rowTitle: bar.rowTitle
39 property alias showRowTitle: bar.showRowTitle
40 property alias rowItemDelegate: bar.rowItemDelegate
41 property alias pageDelegate: content.pageDelegate
43 readonly property real unitProgress: Math.max(0, (height - minimizedPanelHeight) / (openedHeight - minimizedPanelHeight))
44 readonly property bool fullyOpened: unitProgress >= 1
45 readonly property bool partiallyOpened: unitProgress > 0 && unitProgress < 1.0
46 readonly property bool fullyClosed: unitProgress == 0
47 readonly property alias expanded: bar.expanded
48 readonly property int barWidth: Math.min(bar.width, bar.implicitWidth)
52 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
53 // use its own values. Need to ask design about this.
54 showAnimation: SequentialAnimation {
59 duration: UbuntuAnimation.BriskDuration
60 easing.type: Easing.OutCubic
62 // set binding in case units.gu changes while menu open, so height correctly adjusted to fit
63 ScriptAction { script: root.height = Qt.binding( function(){ return root.openedHeight; } ) }
66 hideAnimation: SequentialAnimation {
70 to: minimizedPanelHeight
71 duration: UbuntuAnimation.BriskDuration
72 easing.type: Easing.OutCubic
74 // set binding in case units.gu changes while menu closed, so menu adjusts to fit
75 ScriptAction { script: root.height = Qt.binding( function(){ return root.minimizedPanelHeight; } ) }
79 height: minimizedPanelHeight
80 clip: root.partiallyOpened
82 onUnitProgressChanged: d.updateState()
88 acceptedButtons: Qt.AllButtons
89 onWheel: wheel.accepted = true;
90 enabled: root.state != "initial"
91 visible: content.visible
96 objectName: "menuContent"
103 height: openedHeight - bar.height - handle.height
105 visible: root.unitProgress > 0
106 currentMenuIndex: bar.currentItemIndex
115 bottom: parent.bottom
118 active: d.activeDragHandle ? true : false
119 visible: !root.fullyClosed
121 //small shadow gradient at bottom of menu
128 height: units.gu(0.5)
130 GradientStop { position: 0.0; color: "transparent" }
131 GradientStop { position: 1.0; color: theme.palette.normal.background }
140 visible: !root.fullyClosed
145 objectName: "indicatorsBar"
152 enableLateralChanges: false
154 unitProgress: root.unitProgress
156 height: expanded ? expandedPanelHeight : minimizedPanelHeight
157 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
163 anchors.left: bar.left
166 forceScrollingPercentage: 0.33
167 stopScrollThreshold: units.gu(0.75)
168 direction: Qt.RightToLeft
171 onScroll: bar.addScrollOffset(-scrollAmount);
177 anchors.right: bar.right
180 forceScrollingPercentage: 0.33
181 stopScrollThreshold: units.gu(0.75)
182 direction: Qt.LeftToRight
185 onScroll: bar.addScrollOffset(scrollAmount);
189 anchors.bottom: parent.bottom
190 anchors.left: alignment == Qt.AlignLeft ? parent.left : undefined
191 anchors.right: alignment == Qt.AlignRight ? parent.right : undefined
192 width: root.barWidth // show handle should only cover panel items.
193 height: minimizedPanelHeight
194 enabled: __showDragHandle.enabled && showOnClick
196 var barPosition = mapToItem(bar, mouseX, mouseY);
197 bar.selectItemAt(barPosition.x)
204 objectName: "showDragHandle"
205 anchors.bottom: parent.bottom
206 anchors.left: alignment == Qt.AlignLeft ? parent.left : undefined
207 anchors.right: alignment == Qt.AlignRight ? parent.right : undefined
208 width: root.barWidth // show handle should only cover panel items.
209 height: minimizedPanelHeight
210 direction: Direction.Downwards
211 enabled: !root.shown && root.available
212 autoCompleteDragThreshold: maxTotalDragDistance / 2
217 touchPressTime = new Date().getTime();
219 var touchReleaseTime = new Date().getTime();
220 if (touchReleaseTime - touchPressTime <= 300) {
225 property var touchPressTime
227 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
228 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
229 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
230 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
234 anchors.fill: __hideDragHandle
235 enabled: __hideDragHandle.enabled
236 onClicked: root.hide()
241 objectName: "hideDragHandle"
243 direction: Direction.Upwards
244 enabled: root.shown && root.available
245 hintDisplacement: units.gu(3)
246 autoCompleteDragThreshold: maxTotalDragDistance / 6
248 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
250 onTouchPositionChanged: {
251 if (root.state === "locked") {
252 d.xDisplacementSinceLock += (touchPosition.x - d.lastHideTouchX)
253 d.lastHideTouchX = touchPosition.x;
258 PanelVelocityCalculator {
259 id: yVelocityCalculator
260 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
261 trackedValue: d.activeDragHandle ?
262 (Direction.isPositive(d.activeDragHandle.direction) ?
263 d.activeDragHandle.distance :
264 -d.activeDragHandle.distance)
267 onVelocityAboveThresholdChanged: d.updateState()
271 target: showAnimation
273 if (showAnimation.running) {
274 root.state = "commit";
280 target: hideAnimation
282 if (hideAnimation.running) {
283 root.state = "initial";
290 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
291 property bool hasCommitted: false
292 property real lastHideTouchX: 0
293 property real xDisplacementSinceLock: 0
294 onXDisplacementSinceLockChanged: d.updateState()
296 property real rowMappedLateralPosition: {
297 if (!d.activeDragHandle) return -1;
298 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchPosition.x, 0).x;
301 function updateState() {
302 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
303 if (unitProgress <= 0) {
304 root.state = "initial";
305 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
306 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
307 root.state = "locked";
309 root.state = "reveal";
318 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
324 yVelocityCalculator.reset();
325 // initial item selection
326 if (!d.hasCommitted) bar.selectItemAt(d.rowMappedLateralPosition);
327 d.hasCommitted = false;
333 // changes to lateral touch position effect which indicator is selected
334 lateralPosition: d.rowMappedLateralPosition
335 // vertical velocity determines if changes in lateral position has an effect
336 enableLateralChanges: d.activeDragHandle &&
337 !yVelocityCalculator.velocityAboveThreshold
339 // left scroll bar handling
343 if (!d.activeDragHandle) return -1;
344 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchPosition.x, 0);
348 // right scroll bar handling
350 target: rightScroller
352 if (!d.activeDragHandle) return -1;
353 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchPosition.x, 0);
362 d.xDisplacementSinceLock = 0;
363 d.lastHideTouchX = hideDragHandle.touchPosition.x;
366 PropertyChanges { target: bar; expanded: true }
371 PropertyChanges { target: bar; interactive: true }
376 xDisplacementSinceLock: 0
377 restoreEntryValues: false
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list