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;
83 objectName: "buttonShowDashHome"
86 color: UbuntuColors.orange
87 readonly property bool highlighted: root.highlightIndex == -1;
90 objectName: "dashItem"
91 width: parent.width * .6
93 anchors.centerIn: parent
94 source: "graphics/home.png"
95 rotation: root.rotation
100 activeFocusOnPress: false
101 onClicked: root.showDashHome()
104 objectName: "bfbFocusHighlight"
106 border.color: "white"
107 border.width: units.dp(1)
109 visible: parent.highlighted
114 anchors.left: parent.left
115 anchors.right: parent.right
116 height: parent.height - dashItem.height - parent.spacing*2
119 id: launcherListViewItem
125 objectName: "launcherListView"
128 topMargin: -extensionSize + width * .15
129 bottomMargin: -extensionSize + width * .15
131 topMargin: extensionSize
132 bottomMargin: extensionSize
133 height: parent.height - dashItem.height - parent.spacing*2
135 cacheBuffer: itemHeight * 3
136 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
137 highlightRangeMode: ListView.ApplyRange
138 preferredHighlightBegin: (height - itemHeight) / 2
139 preferredHighlightEnd: (height + itemHeight) / 2
141 // for the single peeking icon, when alert-state is set on delegate
142 property int peekingIndex: -1
144 // The size of the area the ListView is extended to make sure items are not
145 // destroyed when dragging them outside the list. This needs to be at least
146 // itemHeight to prevent folded items from disappearing and DragArea limits
147 // need to be smaller than this size to avoid breakage.
148 property int extensionSize: itemHeight * 3
150 // Workaround: The snap settings in the launcher, will always try to
151 // snap to what we told it to do. However, we want the initial position
152 // of the launcher to not be centered, but instead start with the topmost
153 // item unfolded completely. Lets wait for the ListView to settle after
154 // creation and then reposition it to 0.
155 // https://bugreports.qt-project.org/browse/QTBUG-32251
156 Component.onCompleted: {
163 launcherListView.moveToIndex(0)
167 // The height of the area where icons start getting folded
168 property int foldingStartHeight: itemHeight
169 // The height of the area where the items reach the final folding angle
170 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
171 property int itemWidth: width * .75
172 property int itemHeight: itemWidth * 15 / 16 + units.gu(1)
173 property int clickFlickSpeed: units.gu(60)
174 property int draggedIndex: dndArea.draggedIndex
175 property real realContentY: contentY - originY + topMargin
176 property int realItemHeight: itemHeight + spacing
178 // In case the start dragging transition is running, we need to delay the
179 // move because the displaced transition would clash with it and cause items
180 // to be moved to wrong places
181 property bool draggingTransitionRunning: false
182 property int scheduledMoveTo: -1
184 UbuntuNumberAnimation {
185 id: snapToBottomAnimation
186 target: launcherListView
188 to: launcherListView.originY + launcherListView.topMargin
191 UbuntuNumberAnimation {
192 id: snapToTopAnimation
193 target: launcherListView
195 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
198 UbuntuNumberAnimation {
200 objectName: "moveAnimation"
201 target: launcherListView
203 function moveTo(contentY) {
204 from = launcherListView.contentY;
209 function moveToIndex(index) {
210 var totalItemHeight = launcherListView.itemHeight + launcherListView.spacing
211 var itemPosition = index * totalItemHeight;
212 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
213 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : totalItemHeight
214 if (itemPosition + totalItemHeight + distanceToEnd > launcherListView.contentY + launcherListView.originY + launcherListView.topMargin + height) {
215 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd - launcherListView.originY);
216 } else if (itemPosition - distanceToEnd < launcherListView.contentY - launcherListView.originY + launcherListView.topMargin) {
217 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin + launcherListView.originY);
221 displaced: Transition {
222 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
225 delegate: FoldingLauncherDelegate {
227 objectName: "launcherDelegate" + index
228 // We need the appId in the delegate in order to find
229 // the right app when running autopilot tests for
231 readonly property string appId: model.appId
234 itemHeight: launcherListView.itemHeight
235 itemWidth: launcherListView.itemWidth
240 countVisible: model.countVisible
241 progress: model.progress
242 itemRunning: model.running
243 itemFocused: model.focused
244 inverted: root.inverted
245 alerting: model.alerting
246 highlighted: root.highlightIndex == index
247 shortcutHintShown: root.shortcutHintsShown && index <= 9
248 surfaceCount: model.surfaceCount
251 property bool dragging: false
253 SequentialAnimation {
257 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
258 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
260 UbuntuNumberAnimation {
261 target: launcherDelegate
265 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
266 duration: UbuntuAnimation.BriskDuration
270 UbuntuNumberAnimation {
271 target: launcherDelegate
276 duration: UbuntuAnimation.BriskDuration
279 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
280 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
281 PropertyAction { target: launcherListView; property: "peekingIndex"; value: -1 }
286 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
287 launcherListView.moveToIndex(index)
288 if (!dragging && launcher.state !== "visible") {
289 peekingAnimation.start()
293 if (launcherListView.peekingIndex === -1) {
294 launcherListView.peekingIndex = index
297 if (launcherListView.peekingIndex === index) {
298 launcherListView.peekingIndex = -1
305 objectName: "dropIndicator"
306 anchors.centerIn: parent
307 height: visible ? units.dp(2) : 0
308 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
310 source: "graphics/divider-line.png"
316 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
318 target: launcherDelegate
326 target: launcherDelegate
331 target: dropIndicator
337 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
339 target: launcherDelegate
351 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
356 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
357 UbuntuNumberAnimation { properties: "angle,offset" }
362 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
363 UbuntuNumberAnimation { properties: "angle,offset" }
366 id: draggingTransition
369 SequentialAnimation {
370 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
372 UbuntuNumberAnimation { properties: "height" }
373 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
377 if (launcherListView.scheduledMoveTo > -1) {
378 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
379 dndArea.draggedIndex = launcherListView.scheduledMoveTo
380 launcherListView.scheduledMoveTo = -1
384 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
390 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
391 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
392 SequentialAnimation {
393 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
394 UbuntuNumberAnimation { properties: "height" }
395 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
396 PropertyAction { target: dndArea; property: "postDragging"; value: false }
397 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
405 objectName: "dndArea"
406 acceptedButtons: Qt.LeftButton | Qt.RightButton
410 topMargin: launcherListView.topMargin
411 bottomMargin: launcherListView.bottomMargin
413 drag.minimumY: -launcherListView.topMargin
414 drag.maximumY: height + launcherListView.bottomMargin
416 property int draggedIndex: -1
417 property var selectedItem
418 property bool preDragging: false
419 property bool dragging: !!selectedItem && selectedItem.dragging
420 property bool postDragging: false
424 // This is a workaround for some issue in the QML ListView:
425 // When calling moveToItem(0), the listview visually positions itself
426 // correctly to display the first item expanded. However, some internal
427 // state seems to not be valid, and the next time the user clicks on it,
428 // it snaps back to the snap boundries before executing the onClicked handler.
429 // This can cause the listview getting stuck in a snapped position where you can't
430 // launch things without first dragging the launcher manually. So lets read the item
431 // angle before that happens and use that angle instead of the one we get in onClicked.
432 property real pressedStartAngle: 0
434 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
435 pressedStartAngle = clickedItem.angle;
439 function processPress(mouse) {
440 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
444 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
445 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
447 // Check if we actually clicked an item or only at the spacing in between
448 if (clickedItem === null) {
452 if (mouse.button & Qt.RightButton) { // context menu
454 quickList.open(index);
460 // First/last item do the scrolling at more than 12 degrees
461 if (index == 0 || index == launcherListView.count - 1) {
462 launcherListView.moveToIndex(index);
463 if (pressedStartAngle <= 12 && pressedStartAngle >= -12) {
464 root.applicationSelected(LauncherModel.get(index).appId);
469 // the rest launches apps up to an angle of 30 degrees
470 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
471 launcherListView.moveToIndex(index);
473 root.applicationSelected(LauncherModel.get(index).appId);
485 function endDrag(dragItem) {
486 var droppedIndex = draggedIndex;
497 selectedItem.dragging = false;
498 selectedItem = undefined;
501 dragItem.target = undefined
503 progressiveScrollingTimer.stop();
504 launcherListView.interactive = true;
505 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
506 snapToBottomAnimation.start();
507 } else if (droppedIndex < 2 && postDragging) {
508 snapToTopAnimation.start();
513 processPressAndHold(mouse, drag);
516 function processPressAndHold(mouse, dragItem) {
517 if (Math.abs(selectedItem.angle) > 30) {
523 draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
525 quickList.open(draggedIndex)
527 launcherListView.interactive = false
529 var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
531 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
532 fakeDragItem.x = units.gu(0.5)
533 fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
534 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
535 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
536 fakeDragItem.count = LauncherModel.get(draggedIndex).count
537 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
538 fakeDragItem.flatten()
539 dragItem.target = fakeDragItem
546 processPositionChanged(mouse)
549 function processPositionChanged(mouse) {
550 if (draggedIndex >= 0) {
551 if (!selectedItem.dragging) {
552 var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
553 if (!preDragging && distance > units.gu(1.5)) {
555 quickList.state = "";
557 if (distance > launcherListView.itemHeight) {
558 selectedItem.dragging = true
562 if (!selectedItem.dragging) {
566 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
568 // Move it down by the the missing size to compensate index calculation with only expanded items
569 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
571 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
572 progressiveScrollingTimer.downwards = false
573 progressiveScrollingTimer.start()
574 } else if (mouseY < launcherListView.realItemHeight) {
575 progressiveScrollingTimer.downwards = true
576 progressiveScrollingTimer.start()
578 progressiveScrollingTimer.stop()
581 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
583 if (newIndex > draggedIndex + 1) {
584 newIndex = draggedIndex + 1
585 } else if (newIndex < draggedIndex) {
586 newIndex = draggedIndex -1
591 if (newIndex >= 0 && newIndex < launcherListView.count) {
592 if (launcherListView.draggingTransitionRunning) {
593 launcherListView.scheduledMoveTo = newIndex
595 launcherListView.model.move(draggedIndex, newIndex)
596 draggedIndex = newIndex
603 id: progressiveScrollingTimer
607 property bool downwards: true
610 var minY = -launcherListView.topMargin
611 if (launcherListView.contentY > minY) {
612 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
615 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
616 if (launcherListView.contentY < maxY) {
617 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
627 objectName: "fakeDragItem"
628 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
629 itemWidth: launcherListView.itemWidth
630 itemHeight: launcherListView.itemHeight
633 rotation: root.rotation
635 onVisibleChanged: if (!visible) iconName = "";
638 fakeDragItemAnimation.start();
641 UbuntuNumberAnimation {
642 id: fakeDragItemAnimation
643 target: fakeDragItem;
644 properties: "angle,offset";
653 objectName: "quickListShape"
654 anchors.fill: quickList
655 opacity: quickList.state === "open" ? 0.95 : 0
657 rotation: root.rotation
658 aspect: UbuntuShape.Flat
660 Behavior on opacity {
661 UbuntuNumberAnimation {}
664 source: ShaderEffectSource {
665 sourceItem: quickList
672 rightMargin: -units.dp(4)
673 verticalCenter: parent.verticalCenter
674 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
678 source: "graphics/quicklist_tooltip.png"
684 anchors.fill: quickListShape
685 enabled: quickList.state == "open" || pressed
688 quickList.state = "";
689 quickList.focus = false;
690 root.kbdNavigationCancelled();
693 // Forward for dragging to work when quickList is open
696 var m = mapToItem(dndArea, mouseX, mouseY)
697 dndArea.processPress(m)
701 var m = mapToItem(dndArea, mouseX, mouseY)
702 dndArea.processPressAndHold(m, drag)
706 var m = mapToItem(dndArea, mouseX, mouseY)
707 dndArea.processPositionChanged(m)
711 dndArea.endDrag(drag);
715 dndArea.endDrag(drag);
721 objectName: "quickList"
722 color: theme.palette.normal.background
723 // Because we're setting left/right anchors depending on orientation, it will break the
724 // width setting after rotating twice. This makes sure we also re-apply width on rotation
725 width: root.inverted ? units.gu(30) : units.gu(30)
726 height: quickListColumn.height
727 visible: quickListShape.visible
729 left: root.inverted ? undefined : parent.right
730 right: root.inverted ? parent.left : undefined
733 y: itemCenter - (height / 2) + offset
734 rotation: root.rotation
737 property string appId
739 property int selectedIndex: -1
745 if (selectedIndex >= popoverRepeater.count) {
748 event.accepted = true;
752 if (selectedIndex < 0) {
753 selectedIndex = popoverRepeater.count - 1;
755 event.accepted = true;
759 quickList.selectedIndex = -1;
760 quickList.focus = false;
762 event.accepted = true;
767 if (quickList.selectedIndex >= 0) {
768 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
770 quickList.selectedIndex = -1;
771 quickList.focus = false;
773 root.kbdNavigationCancelled();
774 event.accepted = true;
780 property int itemCenter: item ? root.mapFromItem(quickList.item, 0, 0).y + (item.height / 2) + quickList.item.offset : units.gu(1)
781 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
782 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
784 function open(index) {
785 var itemPosition = index * launcherListView.itemHeight;
786 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
787 item = launcherListView.itemAt(launcherListView.width / 2, itemPosition + launcherListView.itemHeight / 2);
788 quickList.model = launcherListView.model.get(index).quickList;
789 quickList.appId = launcherListView.model.get(index).appId;
790 quickList.state = "open";
795 height: quickListColumn.height
800 height: childrenRect.height
804 model: quickList.model
807 objectName: "quickListEntry" + index
808 selected: index === quickList.selectedIndex
809 height: label.implicitHeight + label.anchors.topMargin + label.anchors.bottomMargin
810 color: model.clickable ? (selected ? theme.palette.highlighted.background : "transparent") : theme.palette.disabled.background
811 highlightColor: !model.clickable ? quickList.color : undefined // make disabled items visually unclickable
812 divider.colorFrom: UbuntuColors.inkstone
813 divider.colorTo: UbuntuColors.inkstone
814 divider.visible: model.hasSeparator
819 anchors.leftMargin: units.gu(3) // 2 GU for checkmark, 3 GU total
820 anchors.rightMargin: units.gu(2)
821 anchors.topMargin: units.gu(2)
822 anchors.bottomMargin: units.gu(2)
823 verticalAlignment: Label.AlignVCenter
825 fontSize: index == 0 ? "medium" : "small"
826 font.weight: index == 0 ? Font.Medium : Font.Light
827 color: model.clickable ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
831 if (!model.clickable) {
835 quickList.state = "";
836 // Unsetting model to prevent showing changing entries during fading out
837 // that may happen because of triggering an action.
838 LauncherModel.quickListActionInvoked(quickList.appId, index);
839 quickList.focus = false;
840 root.kbdNavigationCancelled();
841 quickList.model = undefined;
851 objectName: "tooltipShape"
853 visible: tooltipShownState.active
854 rotation: root.rotation
855 y: itemCenter - (height / 2)
858 left: root.inverted ? undefined : parent.right
859 right: root.inverted ? parent.left : undefined
863 readonly property var hoveredItem: dndArea.containsMouse ? launcherListView.itemAt(dndArea.mouseX, dndArea.mouseY + launcherListView.realContentY) : null
864 readonly property int itemCenter: !hoveredItem ? 0 : root.mapFromItem(hoveredItem, 0, 0).y + (hoveredItem.height / 2) + hoveredItem.offset
866 text: !hoveredItem ? "" : hoveredItem.name
870 id: tooltipStateMachine
871 initialState: tooltipHiddenState
875 id: tooltipHiddenState
877 DSM.SignalTransition {
878 targetState: tooltipShownState
879 signal: tooltipShape.hoveredItemChanged
880 // !dndArea.pressed allows us to filter out touch input events
881 guard: tooltipShape.hoveredItem !== null && !dndArea.pressed && !root.moving
886 id: tooltipShownState
888 DSM.SignalTransition {
889 targetState: tooltipHiddenState
890 signal: tooltipShape.hoveredItemChanged
891 guard: tooltipShape.hoveredItem === null
894 DSM.SignalTransition {
895 targetState: tooltipDismissedState
896 signal: dndArea.onPressed
899 DSM.SignalTransition {
900 targetState: tooltipDismissedState
901 signal: quickList.stateChanged
902 guard: quickList.state === "open"
907 id: tooltipDismissedState
909 DSM.SignalTransition {
910 targetState: tooltipHiddenState
911 signal: dndArea.positionChanged
912 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
915 DSM.SignalTransition {
916 targetState: tooltipHiddenState
917 signal: dndArea.exited
918 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