2 * Copyright (C) 2013-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 QtQml.StateMachine 1.0 as DSM
19import Ubuntu.Components 1.3
20import Unity.Launcher 0.1
21import Ubuntu.Components.Popups 1.3
28 rotation: inverted ? 180 : 0
31 property bool inverted: false
32 property bool dragging: false
33 property bool moving: launcherListView.moving || launcherListView.flicking
34 property bool preventHiding: moving || dndArea.draggedIndex >= 0 || quickList.state === "open" || dndArea.pressed
35 || dndArea.containsMouse || dashItem.hovered
36 property int highlightIndex: -2
37 property bool shortcutHintsShown: false
38 readonly property bool quickListOpen: quickList.state === "open"
40 signal applicationSelected(string appId)
42 signal kbdNavigationCancelled()
45 if (quickList.state === "open") {
50 function highlightNext() {
52 if (highlightIndex >= launcherListView.count) {
55 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
57 function highlightPrevious() {
59 if (highlightIndex <= -2) {
60 highlightIndex = launcherListView.count - 1;
62 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
64 function openQuicklist(index) {
65 quickList.open(index);
66 quickList.selectedIndex = 0;
67 quickList.focus = true;
73 acceptedButtons: Qt.AllButtons
74 onWheel: wheel.accepted = true;
85 objectName: "buttonShowDashHome"
88 color: UbuntuColors.orange
89 readonly property bool highlighted: root.highlightIndex == -1;
92 objectName: "dashItem"
93 width: parent.width * .6
95 anchors.centerIn: parent
96 source: "graphics/home.png"
97 rotation: root.rotation
102 activeFocusOnPress: false
103 onClicked: root.showDashHome()
107 styleName: "FocusShape"
109 anchors.margins: units.gu(.5)
111 visible: bfb.highlighted
118 anchors.left: parent.left
119 anchors.right: parent.right
120 height: parent.height - dashItem.height - parent.spacing*2
123 id: launcherListViewItem
129 objectName: "launcherListView"
132 topMargin: -extensionSize + width * .15
133 bottomMargin: -extensionSize + width * .15
135 topMargin: extensionSize
136 bottomMargin: extensionSize
137 height: parent.height - dashItem.height - parent.spacing*2
139 cacheBuffer: itemHeight * 3
140 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
141 highlightRangeMode: ListView.ApplyRange
142 preferredHighlightBegin: (height - itemHeight) / 2
143 preferredHighlightEnd: (height + itemHeight) / 2
145 // for the single peeking icon, when alert-state is set on delegate
146 property int peekingIndex: -1
148 // The size of the area the ListView is extended to make sure items are not
149 // destroyed when dragging them outside the list. This needs to be at least
150 // itemHeight to prevent folded items from disappearing and DragArea limits
151 // need to be smaller than this size to avoid breakage.
152 property int extensionSize: itemHeight * 3
154 // Workaround: The snap settings in the launcher, will always try to
155 // snap to what we told it to do. However, we want the initial position
156 // of the launcher to not be centered, but instead start with the topmost
157 // item unfolded completely. Lets wait for the ListView to settle after
158 // creation and then reposition it to 0.
159 // https://bugreports.qt-project.org/browse/QTBUG-32251
160 Component.onCompleted: {
167 launcherListView.moveToIndex(0)
171 // The height of the area where icons start getting folded
172 property int foldingStartHeight: itemHeight
173 // The height of the area where the items reach the final folding angle
174 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
175 property int itemWidth: width * .75
176 property int itemHeight: itemWidth * 15 / 16 + units.gu(1)
177 property int clickFlickSpeed: units.gu(60)
178 property int draggedIndex: dndArea.draggedIndex
179 property real realContentY: contentY - originY + topMargin
180 property int realItemHeight: itemHeight + spacing
182 // In case the start dragging transition is running, we need to delay the
183 // move because the displaced transition would clash with it and cause items
184 // to be moved to wrong places
185 property bool draggingTransitionRunning: false
186 property int scheduledMoveTo: -1
188 UbuntuNumberAnimation {
189 id: snapToBottomAnimation
190 target: launcherListView
192 to: launcherListView.originY + launcherListView.topMargin
195 UbuntuNumberAnimation {
196 id: snapToTopAnimation
197 target: launcherListView
199 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
202 UbuntuNumberAnimation {
204 objectName: "moveAnimation"
205 target: launcherListView
207 function moveTo(contentY) {
208 from = launcherListView.contentY;
213 function moveToIndex(index) {
214 var totalItemHeight = launcherListView.itemHeight + launcherListView.spacing
215 var itemPosition = index * totalItemHeight;
216 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
217 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : totalItemHeight
218 if (itemPosition + totalItemHeight + distanceToEnd > launcherListView.contentY + launcherListView.originY + launcherListView.topMargin + height) {
219 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd - launcherListView.originY);
220 } else if (itemPosition - distanceToEnd < launcherListView.contentY - launcherListView.originY + launcherListView.topMargin) {
221 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin + launcherListView.originY);
225 displaced: Transition {
226 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
229 delegate: FoldingLauncherDelegate {
231 objectName: "launcherDelegate" + index
232 // We need the appId in the delegate in order to find
233 // the right app when running autopilot tests for
235 readonly property string appId: model.appId
238 itemHeight: launcherListView.itemHeight
239 itemWidth: launcherListView.itemWidth
244 countVisible: model.countVisible
245 progress: model.progress
246 itemRunning: model.running
247 itemFocused: model.focused
248 inverted: root.inverted
249 alerting: model.alerting
250 highlighted: root.highlightIndex == index
251 shortcutHintShown: root.shortcutHintsShown && index <= 9
252 surfaceCount: model.surfaceCount
255 property bool dragging: false
257 SequentialAnimation {
261 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
262 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
264 UbuntuNumberAnimation {
265 target: launcherDelegate
269 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
270 duration: UbuntuAnimation.BriskDuration
274 UbuntuNumberAnimation {
275 target: launcherDelegate
280 duration: UbuntuAnimation.BriskDuration
283 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
284 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
285 PropertyAction { target: launcherListView; property: "peekingIndex"; value: -1 }
290 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
291 launcherListView.moveToIndex(index)
292 if (!dragging && launcher.state !== "visible") {
293 peekingAnimation.start()
297 if (launcherListView.peekingIndex === -1) {
298 launcherListView.peekingIndex = index
301 if (launcherListView.peekingIndex === index) {
302 launcherListView.peekingIndex = -1
309 objectName: "dropIndicator"
310 anchors.centerIn: parent
311 height: visible ? units.dp(2) : 0
312 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
314 source: "graphics/divider-line.png"
320 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
322 target: launcherDelegate
330 target: launcherDelegate
335 target: dropIndicator
341 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
343 target: launcherDelegate
355 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
360 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
361 UbuntuNumberAnimation { properties: "angle,offset" }
366 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
367 UbuntuNumberAnimation { properties: "angle,offset" }
370 id: draggingTransition
373 SequentialAnimation {
374 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
376 UbuntuNumberAnimation { properties: "height" }
377 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
381 if (launcherListView.scheduledMoveTo > -1) {
382 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
383 dndArea.draggedIndex = launcherListView.scheduledMoveTo
384 launcherListView.scheduledMoveTo = -1
388 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
394 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
395 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
396 SequentialAnimation {
397 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
398 UbuntuNumberAnimation { properties: "height" }
399 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
400 PropertyAction { target: dndArea; property: "postDragging"; value: false }
401 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
409 objectName: "dndArea"
410 acceptedButtons: Qt.LeftButton | Qt.RightButton
414 topMargin: launcherListView.topMargin
415 bottomMargin: launcherListView.bottomMargin
417 drag.minimumY: -launcherListView.topMargin
418 drag.maximumY: height + launcherListView.bottomMargin
420 property int draggedIndex: -1
421 property var selectedItem
422 property bool preDragging: false
423 property bool dragging: !!selectedItem && selectedItem.dragging
424 property bool postDragging: false
428 // This is a workaround for some issue in the QML ListView:
429 // When calling moveToItem(0), the listview visually positions itself
430 // correctly to display the first item expanded. However, some internal
431 // state seems to not be valid, and the next time the user clicks on it,
432 // it snaps back to the snap boundries before executing the onClicked handler.
433 // This can cause the listview getting stuck in a snapped position where you can't
434 // launch things without first dragging the launcher manually. So lets read the item
435 // angle before that happens and use that angle instead of the one we get in onClicked.
436 property real pressedStartAngle: 0
438 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
439 pressedStartAngle = clickedItem.angle;
443 function processPress(mouse) {
444 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
448 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
449 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
451 // Check if we actually clicked an item or only at the spacing in between
452 if (clickedItem === null) {
456 if (mouse.button & Qt.RightButton) { // context menu
458 quickList.open(index);
464 // First/last item do the scrolling at more than 12 degrees
465 if (index == 0 || index == launcherListView.count - 1) {
466 launcherListView.moveToIndex(index);
467 if (pressedStartAngle <= 12 && pressedStartAngle >= -12) {
468 root.applicationSelected(LauncherModel.get(index).appId);
473 // the rest launches apps up to an angle of 30 degrees
474 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
475 launcherListView.moveToIndex(index);
477 root.applicationSelected(LauncherModel.get(index).appId);
489 function endDrag(dragItem) {
490 var droppedIndex = draggedIndex;
501 selectedItem.dragging = false;
502 selectedItem = undefined;
505 dragItem.target = undefined
507 progressiveScrollingTimer.stop();
508 launcherListView.interactive = true;
509 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
510 snapToBottomAnimation.start();
511 } else if (droppedIndex < 2 && postDragging) {
512 snapToTopAnimation.start();
517 processPressAndHold(mouse, drag);
520 function processPressAndHold(mouse, dragItem) {
521 if (Math.abs(selectedItem.angle) > 30) {
527 draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
529 quickList.open(draggedIndex)
531 launcherListView.interactive = false
533 var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
535 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
536 fakeDragItem.x = units.gu(0.5)
537 fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
538 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
539 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
540 fakeDragItem.count = LauncherModel.get(draggedIndex).count
541 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
542 fakeDragItem.flatten()
543 dragItem.target = fakeDragItem
550 processPositionChanged(mouse)
553 function processPositionChanged(mouse) {
554 if (draggedIndex >= 0) {
555 if (!selectedItem.dragging) {
556 var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
557 if (!preDragging && distance > units.gu(1.5)) {
559 quickList.state = "";
561 if (distance > launcherListView.itemHeight) {
562 selectedItem.dragging = true
566 if (!selectedItem.dragging) {
570 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
572 // Move it down by the the missing size to compensate index calculation with only expanded items
573 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
575 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
576 progressiveScrollingTimer.downwards = false
577 progressiveScrollingTimer.start()
578 } else if (mouseY < launcherListView.realItemHeight) {
579 progressiveScrollingTimer.downwards = true
580 progressiveScrollingTimer.start()
582 progressiveScrollingTimer.stop()
585 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
587 if (newIndex > draggedIndex + 1) {
588 newIndex = draggedIndex + 1
589 } else if (newIndex < draggedIndex) {
590 newIndex = draggedIndex -1
595 if (newIndex >= 0 && newIndex < launcherListView.count) {
596 if (launcherListView.draggingTransitionRunning) {
597 launcherListView.scheduledMoveTo = newIndex
599 launcherListView.model.move(draggedIndex, newIndex)
600 draggedIndex = newIndex
607 id: progressiveScrollingTimer
611 property bool downwards: true
614 var minY = -launcherListView.topMargin
615 if (launcherListView.contentY > minY) {
616 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
619 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
620 if (launcherListView.contentY < maxY) {
621 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
631 objectName: "fakeDragItem"
632 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
633 itemWidth: launcherListView.itemWidth
634 itemHeight: launcherListView.itemHeight
637 rotation: root.rotation
639 onVisibleChanged: if (!visible) iconName = "";
642 fakeDragItemAnimation.start();
645 UbuntuNumberAnimation {
646 id: fakeDragItemAnimation
647 target: fakeDragItem;
648 properties: "angle,offset";
657 objectName: "quickListShape"
658 anchors.fill: quickList
659 opacity: quickList.state === "open" ? 0.95 : 0
661 rotation: root.rotation
662 aspect: UbuntuShape.Flat
664 Behavior on opacity {
665 UbuntuNumberAnimation {}
668 source: ShaderEffectSource {
669 sourceItem: quickList
676 rightMargin: -units.dp(4)
677 verticalCenter: parent.verticalCenter
678 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
682 source: "graphics/quicklist_tooltip.png"
688 anchors.fill: quickListShape
689 enabled: quickList.state == "open" || pressed
690 hoverEnabled: enabled
694 quickList.state = "";
695 quickList.focus = false;
696 root.kbdNavigationCancelled();
699 // Forward for dragging to work when quickList is open
702 var m = mapToItem(dndArea, mouseX, mouseY)
703 dndArea.processPress(m)
707 var m = mapToItem(dndArea, mouseX, mouseY)
708 dndArea.processPressAndHold(m, drag)
712 var m = mapToItem(dndArea, mouseX, mouseY)
713 dndArea.processPositionChanged(m)
717 dndArea.endDrag(drag);
721 dndArea.endDrag(drag);
727 objectName: "quickList"
728 color: theme.palette.normal.background
729 // Because we're setting left/right anchors depending on orientation, it will break the
730 // width setting after rotating twice. This makes sure we also re-apply width on rotation
731 width: root.inverted ? units.gu(30) : units.gu(30)
732 height: quickListColumn.height
733 visible: quickListShape.visible
735 left: root.inverted ? undefined : parent.right
736 right: root.inverted ? parent.left : undefined
739 y: itemCenter - (height / 2) + offset
740 rotation: root.rotation
743 property string appId
745 property int selectedIndex: -1
751 if (selectedIndex >= popoverRepeater.count) {
754 event.accepted = true;
758 if (selectedIndex < 0) {
759 selectedIndex = popoverRepeater.count - 1;
761 event.accepted = true;
765 quickList.selectedIndex = -1;
766 quickList.focus = false;
768 event.accepted = true;
773 if (quickList.selectedIndex >= 0) {
774 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
776 quickList.selectedIndex = -1;
777 quickList.focus = false;
779 root.kbdNavigationCancelled();
780 event.accepted = true;
786 property int itemCenter: item ? root.mapFromItem(quickList.item, 0, 0).y + (item.height / 2) + quickList.item.offset : units.gu(1)
787 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
788 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
790 function open(index) {
791 var itemPosition = index * launcherListView.itemHeight;
792 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
793 item = launcherListView.itemAt(launcherListView.width / 2, itemPosition + launcherListView.itemHeight / 2);
794 quickList.model = launcherListView.model.get(index).quickList;
795 quickList.appId = launcherListView.model.get(index).appId;
796 quickList.state = "open";
797 root.highlightIndex = index;
798 quickList.forceActiveFocus();
803 height: quickListColumn.height
808 height: childrenRect.height
812 model: quickList.model
815 objectName: "quickListEntry" + index
816 selected: index === quickList.selectedIndex
817 height: label.implicitHeight + label.anchors.topMargin + label.anchors.bottomMargin
818 color: model.clickable ? (selected ? theme.palette.highlighted.background : "transparent") : theme.palette.disabled.background
819 highlightColor: !model.clickable ? quickList.color : undefined // make disabled items visually unclickable
820 divider.colorFrom: UbuntuColors.inkstone
821 divider.colorTo: UbuntuColors.inkstone
822 divider.visible: model.hasSeparator
827 anchors.leftMargin: units.gu(3) // 2 GU for checkmark, 3 GU total
828 anchors.rightMargin: units.gu(2)
829 anchors.topMargin: units.gu(2)
830 anchors.bottomMargin: units.gu(2)
831 verticalAlignment: Label.AlignVCenter
833 fontSize: index == 0 ? "medium" : "small"
834 font.weight: index == 0 ? Font.Medium : Font.Light
835 color: model.clickable ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
839 if (!model.clickable) {
843 quickList.state = "";
844 // Unsetting model to prevent showing changing entries during fading out
845 // that may happen because of triggering an action.
846 LauncherModel.quickListActionInvoked(quickList.appId, index);
847 quickList.focus = false;
848 root.kbdNavigationCancelled();
849 quickList.model = undefined;
859 objectName: "tooltipShape"
861 visible: tooltipShownState.active
862 rotation: root.rotation
863 y: itemCenter - (height / 2)
866 left: root.inverted ? undefined : parent.right
867 right: root.inverted ? parent.left : undefined
871 readonly property var hoveredItem: dndArea.containsMouse ? launcherListView.itemAt(dndArea.mouseX, dndArea.mouseY + launcherListView.realContentY) : null
872 readonly property int itemCenter: !hoveredItem ? 0 : root.mapFromItem(hoveredItem, 0, 0).y + (hoveredItem.height / 2) + hoveredItem.offset
874 text: !hoveredItem ? "" : hoveredItem.name
878 id: tooltipStateMachine
879 initialState: tooltipHiddenState
883 id: tooltipHiddenState
885 DSM.SignalTransition {
886 targetState: tooltipShownState
887 signal: tooltipShape.hoveredItemChanged
888 // !dndArea.pressed allows us to filter out touch input events
889 guard: tooltipShape.hoveredItem !== null && !dndArea.pressed && !root.moving
894 id: tooltipShownState
896 DSM.SignalTransition {
897 targetState: tooltipHiddenState
898 signal: tooltipShape.hoveredItemChanged
899 guard: tooltipShape.hoveredItem === null
902 DSM.SignalTransition {
903 targetState: tooltipDismissedState
904 signal: dndArea.onPressed
907 DSM.SignalTransition {
908 targetState: tooltipDismissedState
909 signal: quickList.stateChanged
910 guard: quickList.state === "open"
915 id: tooltipDismissedState
917 DSM.SignalTransition {
918 targetState: tooltipHiddenState
919 signal: dndArea.positionChanged
920 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
923 DSM.SignalTransition {
924 targetState: tooltipHiddenState
925 signal: dndArea.exited
926 guard: quickList.state != "open"
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