2 * Copyright (C) 2013 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 0.1
19import Ubuntu.Gestures 0.1
20import Unity.Indicators 0.1 as Indicators
23import "../Components/ListItems"
29 property real openedHeight: units.gu(71)
30 property int panelHeight: units.gu(3)
31 property alias overFlowWidth: indicatorRow.overFlowWidth
32 property alias showAll: indicatorRow.showAll
33 // TODO: This should be sourced by device type (eg "desktop", "tablet", "phone"...)
34 property string profile: indicatorProfile
36 readonly property real hintValue: panelHeight + menuContent.headerHeight
37 readonly property int lockThreshold: openedHeight / 2
38 property bool fullyOpened: height == openedHeight
39 property bool partiallyOpened: height > panelHeight && !fullyOpened
40 property bool contentEnabled: true
41 property bool initalizeItem: true
42 readonly property alias content: menuContent
43 property real unitProgress: (height - panelHeight) / (openedHeight - panelHeight)
44 property bool enableHint: true
45 property real showHintBottomMargin: 0
47 signal showTapped(point position)
49 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
50 // use its own values. Need to ask design about this.
51 showAnimation: StandardAnimation {
56 hideAnimation: StandardAnimation {
60 easing.type: Easing.OutCubic
63 onOpenedHeightChanged: {
64 if (showAnimation.running) {
65 showAnimation.restart();
66 } else if (indicators.shown) {
67 height = openedHeight;
72 onHeightChanged: updateRevealProgressState(indicators.height - panelHeight - showHintBottomMargin, true)
74 function updateRevealProgressState(revealProgress, enableRelease) {
75 if (!showAnimation.running && !hideAnimation.running) {
76 if (revealProgress === 0) {
77 indicators.state = "initial";
78 } else if (enableHint && revealProgress > 0 && revealProgress <= hintValue) {
79 indicators.state = "hint";
80 } else if ((!enableHint || revealProgress > hintValue) && revealProgress < lockThreshold) {
81 indicators.state = "reveal";
82 } else if (revealProgress >= lockThreshold && lockThreshold > 0) {
83 indicators.state = "locked";
87 if (enableRelease && revealProgress === 0) {
88 menuContent.releaseContent();
92 function calculateCurrentItem(xValue, useBuffer) {
96 var distanceFromRightEdge;
97 var bufferExceeded = false;
99 if (indicators.state == "commit" || indicators.state == "locked" || showAnimation.running || hideAnimation.running) return;
102 If user drags the indicator handle bar down a distance hintValue or less, this is 0.
103 If bar is dragged down a distance greater than or equal to lockThreshold, this is 1.
104 Otherwise it contains the bar's location as a fraction of the distance between hintValue (is 0) and lockThreshold (is 1).
106 var verticalProgress =
107 MathUtils.clamp((indicators.height - handle.height - hintValue) /
108 (lockThreshold - hintValue), 0, 1);
111 Vertical velocity check. Don't change the indicator if we're moving too quickly.
113 var verticalSpeed = Math.abs(yVelocityCalculator.calculate());
114 if (verticalSpeed >= 0.05 && !initalizeItem) {
119 Percentage of an indicator icon's width the user's press can stray horizontally from the
120 focused icon before we change focus to another icon. E.g. a value of 0.5 means you must
121 go right a distance of half an icon's width before focus moves to the icon on the right
123 var maxBufferThreshold = 0.5;
126 To help users find the indicator of their choice while opening the indicators, we add logic to add a
127 left/right buffer to each icon so it is harder for the focus to be moved accidentally to another icon,
128 as the user moves their finger down, but yet allows them to switch indicator if they want.
129 This buffer is wider the further the user's finger is from the top of the screen.
131 var effectiveBufferThreshold = maxBufferThreshold * verticalProgress;
133 rowCoordinates = indicatorRow.mapToItem(indicatorRow.row, xValue, 0);
134 // get the current delegate
135 currentItem = indicatorRow.row.itemAt(rowCoordinates.x, 0);
137 itemCoordinates = indicatorRow.row.mapToItem(currentItem, rowCoordinates.x, 0);
138 distanceFromRightEdge = (currentItem.width - itemCoordinates.x) / (currentItem.width);
139 if (currentItem != indicatorRow.currentItem) {
140 if (Math.abs(currentItem.ownIndex - indicatorRow.currentItemIndex) > 1) {
141 bufferExceeded = true;
143 if (indicatorRow.currentItemIndex < currentItem.ownIndex && distanceFromRightEdge < (1 - effectiveBufferThreshold)) {
144 bufferExceeded = true;
145 } else if (indicatorRow.currentItemIndex > currentItem.ownIndex && distanceFromRightEdge > effectiveBufferThreshold) {
146 bufferExceeded = true;
149 if ((!useBuffer || (useBuffer && bufferExceeded)) || indicatorRow.currentItemIndex < 0 || indicatorRow.currentItem == null) {
150 indicatorRow.setCurrentItem(currentItem);
153 // need to re-init the distanceFromRightEdge for offset calculation
154 itemCoordinates = indicatorRow.row.mapToItem(indicatorRow.currentItem, rowCoordinates.x, 0);
155 distanceFromRightEdge = (indicatorRow.currentItem.width - itemCoordinates.x) / (indicatorRow.currentItem.width);
157 indicatorRow.currentItemOffset = 1 - (distanceFromRightEdge * 2);
158 } else if (initalizeItem) {
159 indicatorRow.setDefaultItem();
160 indicatorRow.currentItemOffset = 0;
162 initalizeItem = indicatorRow.currentItem == null;
169 bottom: handle.bottom
176 id: visibleIndicators
181 objectName: "menuContent"
186 top: indicatorRow.bottom
189 indicatorsModel: visibleIndicators.model
190 clip: !indicators.fullyOpened
191 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
192 enabled: contentEnabled
194 //small shadow gradient at bottom of menu
199 bottom: parent.bottom
201 height: units.gu(0.5)
203 GradientStop { position: 0.0; color: "transparent" }
204 GradientStop { position: 1.0; color: "black" }
213 color: menuContent.backgroundColor
218 bottom: parent.bottom
220 height: Math.max(Math.min(handleImage.height, indicators.height - handleImage.height), 0)
221 clip: height < handleImage.height
225 source: "graphics/handle.sci"
230 bottom: parent.bottom
233 MouseArea { //prevent clicks passing through
240 objectName: "indicatorRow"
245 height: indicators.panelHeight
246 indicatorsModel: visibleIndicators.model
247 state: indicators.state
248 unitProgress: indicators.unitProgress
252 anchors.fill: indicatorRow
253 direction: Direction.Downwards
260 initalizeItem = true;
261 updateRevealProgressState(Math.max(touchSceneY - panelHeight, hintValue), false);
262 indicators.calculateCurrentItem(touchX, false);
264 indicators.state = "commit";
269 indicators.calculateCurrentItem(touchX, true);
271 onTouchSceneYChanged: {
272 updateRevealProgressState(Math.max(touchSceneY - panelHeight, hintValue), false);
273 yVelocityCalculator.trackedPosition = touchSceneY;
279 target: showAnimation
281 if (showAnimation.running) {
282 indicators.state = "commit";
283 indicatorRow.currentItemOffset = 0;
289 target: hideAnimation
291 if (hideAnimation.running) {
292 indicators.state = "initial";
293 initalizeItem = true;
294 indicatorRow.currentItemOffset = 0;
301 property bool enableIndexChangeSignal: true
302 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
307 onCurrentMenuIndexChanged: {
308 var oldActive = d.enableIndexChangeSignal;
309 if (!oldActive) return;
310 d.enableIndexChangeSignal = false;
312 indicatorRow.setCurrentItemIndex(menuContent.currentMenuIndex);
314 d.enableIndexChangeSignal = oldActive;
320 onCurrentItemIndexChanged: {
321 var oldActive = d.enableIndexChangeSignal;
322 if (!oldActive) return;
323 d.enableIndexChangeSignal = false;
325 menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex, fullyOpened || partiallyOpened);
327 d.enableIndexChangeSignal = oldActive;
330 // connections to the active drag handle
332 target: d.activeDragHandle
334 indicators.calculateCurrentItem(d.activeDragHandle.touchX, true);
336 onTouchSceneYChanged: {
337 yVelocityCalculator.trackedPosition = d.activeDragHandle.touchSceneY;
343 anchors.bottom: parent.bottom
344 // go beyond parent so that it stays reachable, at the top of the screen.
345 anchors.bottomMargin: showHintBottomMargin
346 anchors.left: parent.left
347 anchors.right: parent.right
349 direction: Direction.Downwards
350 enabled: !indicators.shown && indicators.available
351 hintDisplacement: enableHint ? indicators.hintValue : 0
352 autoCompleteDragThreshold: maxTotalDragDistance / 2
354 maxTotalDragDistance: openedHeight - panelHeight
355 distanceThreshold: panelHeight
358 if (status === DirectionalDragArea.Recognized) {
359 menuContent.activateContent();
363 onTapped: showTapped(Qt.point(touchSceneX, touchSceneY));
369 direction: Direction.Upwards
370 enabled: indicators.shown && indicators.available
371 hintDisplacement: indicators.hintValue
372 autoCompleteDragThreshold: maxTotalDragDistance / 6
374 maxTotalDragDistance: openedHeight - panelHeight
378 AxisVelocityCalculator {
379 id: yVelocityCalculator
390 if (d.activeDragHandle) {
391 calculateCurrentItem(d.activeDragHandle.touchX, false);
413 NumberAnimation {targets: [indicatorRow, menuContent]; property: "y"; duration: 300; easing.type: Easing.OutCubic}
417 Component.onCompleted: initialise();
418 function initialise() {
419 visibleIndicators.load(profile);
420 indicatorRow.setDefaultItem();
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