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
39 signal applicationSelected(string appId)
41 signal kbdNavigationCancelled()
44 if (quickList.state === "open") {
49 function highlightNext() {
51 if (highlightIndex >= launcherListView.count) {
54 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
56 function highlightPrevious() {
58 if (highlightIndex <= -2) {
59 highlightIndex = launcherListView.count - 1;
61 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
63 function openQuicklist(index) {
64 quickList.open(index);
65 quickList.selectedIndex = 0;
66 quickList.focus = true;
72 acceptedButtons: Qt.AllButtons
73 onWheel: wheel.accepted = true;
84 objectName: "buttonShowDashHome"
87 color: UbuntuColors.orange
88 readonly property bool highlighted: root.highlightIndex == -1;
91 objectName: "dashItem"
92 width: parent.width * .6
94 anchors.centerIn: parent
95 source: "graphics/home.png"
96 rotation: root.rotation
101 activeFocusOnPress: false
102 onClicked: root.showDashHome()
106 styleName: "FocusShape"
108 anchors.margins: units.gu(.5)
110 visible: bfb.highlighted
117 anchors.left: parent.left
118 anchors.right: parent.right
119 height: parent.height - dashItem.height - parent.spacing*2
122 id: launcherListViewItem
128 objectName: "launcherListView"
131 topMargin: -extensionSize + width * .15
132 bottomMargin: -extensionSize + width * .15
134 topMargin: extensionSize
135 bottomMargin: extensionSize
136 height: parent.height - dashItem.height - parent.spacing*2
138 cacheBuffer: itemHeight * 3
139 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
140 highlightRangeMode: ListView.ApplyRange
141 preferredHighlightBegin: (height - itemHeight) / 2
142 preferredHighlightEnd: (height + itemHeight) / 2
144 // for the single peeking icon, when alert-state is set on delegate
145 property int peekingIndex: -1
147 // The size of the area the ListView is extended to make sure items are not
148 // destroyed when dragging them outside the list. This needs to be at least
149 // itemHeight to prevent folded items from disappearing and DragArea limits
150 // need to be smaller than this size to avoid breakage.
151 property int extensionSize: itemHeight * 3
153 // Workaround: The snap settings in the launcher, will always try to
154 // snap to what we told it to do. However, we want the initial position
155 // of the launcher to not be centered, but instead start with the topmost
156 // item unfolded completely. Lets wait for the ListView to settle after
157 // creation and then reposition it to 0.
158 // https://bugreports.qt-project.org/browse/QTBUG-32251
159 Component.onCompleted: {
166 launcherListView.moveToIndex(0)
170 // The height of the area where icons start getting folded
171 property int foldingStartHeight: itemHeight
172 // The height of the area where the items reach the final folding angle
173 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
174 property int itemWidth: width * .75
175 property int itemHeight: itemWidth * 15 / 16 + units.gu(1)
176 property int clickFlickSpeed: units.gu(60)
177 property int draggedIndex: dndArea.draggedIndex
178 property real realContentY: contentY - originY + topMargin
179 property int realItemHeight: itemHeight + spacing
181 // In case the start dragging transition is running, we need to delay the
182 // move because the displaced transition would clash with it and cause items
183 // to be moved to wrong places
184 property bool draggingTransitionRunning: false
185 property int scheduledMoveTo: -1
187 UbuntuNumberAnimation {
188 id: snapToBottomAnimation
189 target: launcherListView
191 to: launcherListView.originY + launcherListView.topMargin
194 UbuntuNumberAnimation {
195 id: snapToTopAnimation
196 target: launcherListView
198 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
201 UbuntuNumberAnimation {
203 objectName: "moveAnimation"
204 target: launcherListView
206 function moveTo(contentY) {
207 from = launcherListView.contentY;
212 function moveToIndex(index) {
213 var totalItemHeight = launcherListView.itemHeight + launcherListView.spacing
214 var itemPosition = index * totalItemHeight;
215 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
216 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : totalItemHeight
217 if (itemPosition + totalItemHeight + distanceToEnd > launcherListView.contentY + launcherListView.originY + launcherListView.topMargin + height) {
218 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd - launcherListView.originY);
219 } else if (itemPosition - distanceToEnd < launcherListView.contentY - launcherListView.originY + launcherListView.topMargin) {
220 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin + launcherListView.originY);
224 displaced: Transition {
225 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
228 delegate: FoldingLauncherDelegate {
230 objectName: "launcherDelegate" + index
231 // We need the appId in the delegate in order to find
232 // the right app when running autopilot tests for
234 readonly property string appId: model.appId
237 itemHeight: launcherListView.itemHeight
238 itemWidth: launcherListView.itemWidth
243 countVisible: model.countVisible
244 progress: model.progress
245 itemRunning: model.running
246 itemFocused: model.focused
247 inverted: root.inverted
248 alerting: model.alerting
249 highlighted: root.highlightIndex == index
250 shortcutHintShown: root.shortcutHintsShown && index <= 9
251 surfaceCount: model.surfaceCount
254 property bool dragging: false
256 SequentialAnimation {
260 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
261 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
263 UbuntuNumberAnimation {
264 target: launcherDelegate
268 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
269 duration: UbuntuAnimation.BriskDuration
273 UbuntuNumberAnimation {
274 target: launcherDelegate
279 duration: UbuntuAnimation.BriskDuration
282 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
283 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
284 PropertyAction { target: launcherListView; property: "peekingIndex"; value: -1 }
289 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
290 launcherListView.moveToIndex(index)
291 if (!dragging && launcher.state !== "visible") {
292 peekingAnimation.start()
296 if (launcherListView.peekingIndex === -1) {
297 launcherListView.peekingIndex = index
300 if (launcherListView.peekingIndex === index) {
301 launcherListView.peekingIndex = -1
308 objectName: "dropIndicator"
309 anchors.centerIn: parent
310 height: visible ? units.dp(2) : 0
311 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
313 source: "graphics/divider-line.png"
319 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
321 target: launcherDelegate
329 target: launcherDelegate
334 target: dropIndicator
340 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
342 target: launcherDelegate
354 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
359 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
360 UbuntuNumberAnimation { properties: "angle,offset" }
365 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
366 UbuntuNumberAnimation { properties: "angle,offset" }
369 id: draggingTransition
372 SequentialAnimation {
373 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
375 UbuntuNumberAnimation { properties: "height" }
376 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
380 if (launcherListView.scheduledMoveTo > -1) {
381 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
382 dndArea.draggedIndex = launcherListView.scheduledMoveTo
383 launcherListView.scheduledMoveTo = -1
387 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
393 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
394 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
395 SequentialAnimation {
396 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
397 UbuntuNumberAnimation { properties: "height" }
398 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
399 PropertyAction { target: dndArea; property: "postDragging"; value: false }
400 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
408 objectName: "dndArea"
409 acceptedButtons: Qt.LeftButton | Qt.RightButton
413 topMargin: launcherListView.topMargin
414 bottomMargin: launcherListView.bottomMargin
416 drag.minimumY: -launcherListView.topMargin
417 drag.maximumY: height + launcherListView.bottomMargin
419 property int draggedIndex: -1
420 property var selectedItem
421 property bool preDragging: false
422 property bool dragging: !!selectedItem && selectedItem.dragging
423 property bool postDragging: false
427 // This is a workaround for some issue in the QML ListView:
428 // When calling moveToItem(0), the listview visually positions itself
429 // correctly to display the first item expanded. However, some internal
430 // state seems to not be valid, and the next time the user clicks on it,
431 // it snaps back to the snap boundries before executing the onClicked handler.
432 // This can cause the listview getting stuck in a snapped position where you can't
433 // launch things without first dragging the launcher manually. So lets read the item
434 // angle before that happens and use that angle instead of the one we get in onClicked.
435 property real pressedStartAngle: 0
437 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
438 pressedStartAngle = clickedItem.angle;
442 function processPress(mouse) {
443 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
447 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
448 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
450 // Check if we actually clicked an item or only at the spacing in between
451 if (clickedItem === null) {
455 if (mouse.button & Qt.RightButton) { // context menu
457 quickList.open(index);
463 // First/last item do the scrolling at more than 12 degrees
464 if (index == 0 || index == launcherListView.count - 1) {
465 launcherListView.moveToIndex(index);
466 if (pressedStartAngle <= 12 && pressedStartAngle >= -12) {
467 root.applicationSelected(LauncherModel.get(index).appId);
472 // the rest launches apps up to an angle of 30 degrees
473 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
474 launcherListView.moveToIndex(index);
476 root.applicationSelected(LauncherModel.get(index).appId);
488 function endDrag(dragItem) {
489 var droppedIndex = draggedIndex;
500 selectedItem.dragging = false;
501 selectedItem = undefined;
504 dragItem.target = undefined
506 progressiveScrollingTimer.stop();
507 launcherListView.interactive = true;
508 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
509 snapToBottomAnimation.start();
510 } else if (droppedIndex < 2 && postDragging) {
511 snapToTopAnimation.start();
516 processPressAndHold(mouse, drag);
519 function processPressAndHold(mouse, dragItem) {
520 if (Math.abs(selectedItem.angle) > 30) {
526 draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
528 quickList.open(draggedIndex)
530 launcherListView.interactive = false
532 var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
534 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
535 fakeDragItem.x = units.gu(0.5)
536 fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
537 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
538 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
539 fakeDragItem.count = LauncherModel.get(draggedIndex).count
540 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
541 fakeDragItem.flatten()
542 dragItem.target = fakeDragItem
549 processPositionChanged(mouse)
552 function processPositionChanged(mouse) {
553 if (draggedIndex >= 0) {
554 if (!selectedItem.dragging) {
555 var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
556 if (!preDragging && distance > units.gu(1.5)) {
558 quickList.state = "";
560 if (distance > launcherListView.itemHeight) {
561 selectedItem.dragging = true
565 if (!selectedItem.dragging) {
569 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
571 // Move it down by the the missing size to compensate index calculation with only expanded items
572 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
574 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
575 progressiveScrollingTimer.downwards = false
576 progressiveScrollingTimer.start()
577 } else if (mouseY < launcherListView.realItemHeight) {
578 progressiveScrollingTimer.downwards = true
579 progressiveScrollingTimer.start()
581 progressiveScrollingTimer.stop()
584 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
586 if (newIndex > draggedIndex + 1) {
587 newIndex = draggedIndex + 1
588 } else if (newIndex < draggedIndex) {
589 newIndex = draggedIndex -1
594 if (newIndex >= 0 && newIndex < launcherListView.count) {
595 if (launcherListView.draggingTransitionRunning) {
596 launcherListView.scheduledMoveTo = newIndex
598 launcherListView.model.move(draggedIndex, newIndex)
599 draggedIndex = newIndex
606 id: progressiveScrollingTimer
610 property bool downwards: true
613 var minY = -launcherListView.topMargin
614 if (launcherListView.contentY > minY) {
615 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
618 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
619 if (launcherListView.contentY < maxY) {
620 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
630 objectName: "fakeDragItem"
631 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
632 itemWidth: launcherListView.itemWidth
633 itemHeight: launcherListView.itemHeight
636 rotation: root.rotation
638 onVisibleChanged: if (!visible) iconName = "";
641 fakeDragItemAnimation.start();
644 UbuntuNumberAnimation {
645 id: fakeDragItemAnimation
646 target: fakeDragItem;
647 properties: "angle,offset";
656 objectName: "quickListShape"
657 anchors.fill: quickList
658 opacity: quickList.state === "open" ? 0.95 : 0
660 rotation: root.rotation
661 aspect: UbuntuShape.Flat
663 Behavior on opacity {
664 UbuntuNumberAnimation {}
667 source: ShaderEffectSource {
668 sourceItem: quickList
675 rightMargin: -units.dp(4)
676 verticalCenter: parent.verticalCenter
677 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
681 source: "graphics/quicklist_tooltip.png"
687 anchors.fill: quickListShape
688 enabled: quickList.state == "open" || pressed
691 quickList.state = "";
692 quickList.focus = false;
693 root.kbdNavigationCancelled();
696 // Forward for dragging to work when quickList is open
699 var m = mapToItem(dndArea, mouseX, mouseY)
700 dndArea.processPress(m)
704 var m = mapToItem(dndArea, mouseX, mouseY)
705 dndArea.processPressAndHold(m, drag)
709 var m = mapToItem(dndArea, mouseX, mouseY)
710 dndArea.processPositionChanged(m)
714 dndArea.endDrag(drag);
718 dndArea.endDrag(drag);
724 objectName: "quickList"
725 color: theme.palette.normal.background
726 // Because we're setting left/right anchors depending on orientation, it will break the
727 // width setting after rotating twice. This makes sure we also re-apply width on rotation
728 width: root.inverted ? units.gu(30) : units.gu(30)
729 height: quickListColumn.height
730 visible: quickListShape.visible
732 left: root.inverted ? undefined : parent.right
733 right: root.inverted ? parent.left : undefined
736 y: itemCenter - (height / 2) + offset
737 rotation: root.rotation
740 property string appId
742 property int selectedIndex: -1
748 if (selectedIndex >= popoverRepeater.count) {
751 event.accepted = true;
755 if (selectedIndex < 0) {
756 selectedIndex = popoverRepeater.count - 1;
758 event.accepted = true;
762 quickList.selectedIndex = -1;
763 quickList.focus = false;
765 event.accepted = true;
770 if (quickList.selectedIndex >= 0) {
771 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
773 quickList.selectedIndex = -1;
774 quickList.focus = false;
776 root.kbdNavigationCancelled();
777 event.accepted = true;
783 property int itemCenter: item ? root.mapFromItem(quickList.item, 0, 0).y + (item.height / 2) + quickList.item.offset : units.gu(1)
784 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
785 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
787 function open(index) {
788 var itemPosition = index * launcherListView.itemHeight;
789 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
790 item = launcherListView.itemAt(launcherListView.width / 2, itemPosition + launcherListView.itemHeight / 2);
791 quickList.model = launcherListView.model.get(index).quickList;
792 quickList.appId = launcherListView.model.get(index).appId;
793 quickList.state = "open";
794 root.highlightIndex = index;
795 quickList.forceActiveFocus();
800 height: quickListColumn.height
805 height: childrenRect.height
809 model: quickList.model
812 objectName: "quickListEntry" + index
813 selected: index === quickList.selectedIndex
814 height: label.implicitHeight + label.anchors.topMargin + label.anchors.bottomMargin
815 color: model.clickable ? (selected ? theme.palette.highlighted.background : "transparent") : theme.palette.disabled.background
816 highlightColor: !model.clickable ? quickList.color : undefined // make disabled items visually unclickable
817 divider.colorFrom: UbuntuColors.inkstone
818 divider.colorTo: UbuntuColors.inkstone
819 divider.visible: model.hasSeparator
824 anchors.leftMargin: units.gu(3) // 2 GU for checkmark, 3 GU total
825 anchors.rightMargin: units.gu(2)
826 anchors.topMargin: units.gu(2)
827 anchors.bottomMargin: units.gu(2)
828 verticalAlignment: Label.AlignVCenter
830 fontSize: index == 0 ? "medium" : "small"
831 font.weight: index == 0 ? Font.Medium : Font.Light
832 color: model.clickable ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
836 if (!model.clickable) {
840 quickList.state = "";
841 // Unsetting model to prevent showing changing entries during fading out
842 // that may happen because of triggering an action.
843 LauncherModel.quickListActionInvoked(quickList.appId, index);
844 quickList.focus = false;
845 root.kbdNavigationCancelled();
846 quickList.model = undefined;
856 objectName: "tooltipShape"
858 visible: tooltipShownState.active
859 rotation: root.rotation
860 y: itemCenter - (height / 2)
863 left: root.inverted ? undefined : parent.right
864 right: root.inverted ? parent.left : undefined
868 readonly property var hoveredItem: dndArea.containsMouse ? launcherListView.itemAt(dndArea.mouseX, dndArea.mouseY + launcherListView.realContentY) : null
869 readonly property int itemCenter: !hoveredItem ? 0 : root.mapFromItem(hoveredItem, 0, 0).y + (hoveredItem.height / 2) + hoveredItem.offset
871 text: !hoveredItem ? "" : hoveredItem.name
875 id: tooltipStateMachine
876 initialState: tooltipHiddenState
880 id: tooltipHiddenState
882 DSM.SignalTransition {
883 targetState: tooltipShownState
884 signal: tooltipShape.hoveredItemChanged
885 // !dndArea.pressed allows us to filter out touch input events
886 guard: tooltipShape.hoveredItem !== null && !dndArea.pressed && !root.moving
891 id: tooltipShownState
893 DSM.SignalTransition {
894 targetState: tooltipHiddenState
895 signal: tooltipShape.hoveredItemChanged
896 guard: tooltipShape.hoveredItem === null
899 DSM.SignalTransition {
900 targetState: tooltipDismissedState
901 signal: dndArea.onPressed
904 DSM.SignalTransition {
905 targetState: tooltipDismissedState
906 signal: quickList.stateChanged
907 guard: quickList.state === "open"
912 id: tooltipDismissedState
914 DSM.SignalTransition {
915 targetState: tooltipHiddenState
916 signal: dndArea.positionChanged
917 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
920 DSM.SignalTransition {
921 targetState: tooltipHiddenState
922 signal: dndArea.exited
923 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