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
144 if (event.key === Qt.Key_Left) {
145 bar.setCurrentItemIndex(bar.currentItemIndex - 1);
146 event.accepted = true;
147 } else if (event.key === Qt.Key_Right) {
148 bar.setCurrentItemIndex(bar.currentItemIndex + 1);
149 event.accepted = true;
150 } else if (event.key === Qt.Key_Escape) {
152 event.accepted = true;
158 objectName: "indicatorsBar"
165 enableLateralChanges: false
167 unitProgress: root.unitProgress
169 height: expanded ? expandedPanelHeight : minimizedPanelHeight
170 Behavior on height { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing } }
176 anchors.left: bar.left
179 forceScrollingPercentage: 0.33
180 stopScrollThreshold: units.gu(0.75)
181 direction: Qt.RightToLeft
184 onScroll: bar.addScrollOffset(-scrollAmount);
190 anchors.right: bar.right
193 forceScrollingPercentage: 0.33
194 stopScrollThreshold: units.gu(0.75)
195 direction: Qt.LeftToRight
198 onScroll: bar.addScrollOffset(scrollAmount);
202 anchors.bottom: parent.bottom
203 anchors.left: alignment == Qt.AlignLeft ? parent.left : undefined
204 anchors.right: alignment == Qt.AlignRight ? parent.right : undefined
205 width: root.barWidth // show handle should only cover panel items.
206 height: minimizedPanelHeight
207 enabled: __showDragHandle.enabled && showOnClick
209 var barPosition = mapToItem(bar, mouseX, mouseY);
210 bar.selectItemAt(barPosition.x)
217 objectName: "showDragHandle"
218 anchors.bottom: parent.bottom
219 anchors.left: alignment == Qt.AlignLeft ? parent.left : undefined
220 anchors.right: alignment == Qt.AlignRight ? parent.right : undefined
221 width: root.barWidth // show handle should only cover panel items.
222 height: minimizedPanelHeight
223 direction: Direction.Downwards
224 enabled: !root.shown && root.available
225 autoCompleteDragThreshold: maxTotalDragDistance / 2
230 touchPressTime = new Date().getTime();
232 var touchReleaseTime = new Date().getTime();
233 if (touchReleaseTime - touchPressTime <= 300) {
238 property var touchPressTime
240 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
241 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
242 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
243 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
247 anchors.fill: __hideDragHandle
248 enabled: __hideDragHandle.enabled
249 onClicked: root.hide()
254 objectName: "hideDragHandle"
256 direction: Direction.Upwards
257 enabled: root.shown && root.available
258 hintDisplacement: units.gu(3)
259 autoCompleteDragThreshold: maxTotalDragDistance / 6
261 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
263 onTouchPositionChanged: {
264 if (root.state === "locked") {
265 d.xDisplacementSinceLock += (touchPosition.x - d.lastHideTouchX)
266 d.lastHideTouchX = touchPosition.x;
271 PanelVelocityCalculator {
272 id: yVelocityCalculator
273 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
274 trackedValue: d.activeDragHandle ?
275 (Direction.isPositive(d.activeDragHandle.direction) ?
276 d.activeDragHandle.distance :
277 -d.activeDragHandle.distance)
280 onVelocityAboveThresholdChanged: d.updateState()
284 target: showAnimation
286 if (showAnimation.running) {
287 root.state = "commit";
293 target: hideAnimation
295 if (hideAnimation.running) {
296 root.state = "initial";
303 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
304 property bool hasCommitted: false
305 property real lastHideTouchX: 0
306 property real xDisplacementSinceLock: 0
307 onXDisplacementSinceLockChanged: d.updateState()
309 property real rowMappedLateralPosition: {
310 if (!d.activeDragHandle) return -1;
311 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchPosition.x, 0).x;
314 function updateState() {
315 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
316 if (unitProgress <= 0) {
317 root.state = "initial";
318 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
319 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
320 root.state = "locked";
322 root.state = "reveal";
331 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
337 yVelocityCalculator.reset();
338 // initial item selection
339 if (!d.hasCommitted) bar.selectItemAt(d.rowMappedLateralPosition);
340 d.hasCommitted = false;
346 // changes to lateral touch position effect which indicator is selected
347 lateralPosition: d.rowMappedLateralPosition
348 // vertical velocity determines if changes in lateral position has an effect
349 enableLateralChanges: d.activeDragHandle &&
350 !yVelocityCalculator.velocityAboveThreshold
352 // left scroll bar handling
356 if (!d.activeDragHandle) return -1;
357 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchPosition.x, 0);
361 // right scroll bar handling
363 target: rightScroller
365 if (!d.activeDragHandle) return -1;
366 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchPosition.x, 0);
375 d.xDisplacementSinceLock = 0;
376 d.lastHideTouchX = hideDragHandle.touchPosition.x;
379 PropertyChanges { target: bar; expanded: true }
384 PropertyChanges { target: root; focus: true }
385 PropertyChanges { target: bar; interactive: true }
390 xDisplacementSinceLock: 0
391 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