on 563bcf4 help sign in
unity8/qml/Launcher/LauncherPanel.qml
927 lines 42 kB history raw
1/*
2 * Copyright (C) 2013-2016 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.4
18import QtQml.StateMachine 1.0 as DSM
19import Ubuntu.Components 1.3
20import Unity.Launcher 0.1
21import Ubuntu.Components.Popups 1.3
22import "../Components"
24Rectangle {
25 id: root
26 color: "#F2111111"
28 rotation: inverted ? 180 : 0
30 property var model
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)
40 signal showDashHome()
41 signal kbdNavigationCancelled()
43 onXChanged: {
44 if (quickList.state === "open") {
45 quickList.state = ""
46 }
47 }
49 function highlightNext() {
50 highlightIndex++;
51 if (highlightIndex >= launcherListView.count) {
52 highlightIndex = -1;
53 }
54 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
55 }
56 function highlightPrevious() {
57 highlightIndex--;
58 if (highlightIndex <= -2) {
59 highlightIndex = launcherListView.count - 1;
60 }
61 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
62 }
63 function openQuicklist(index) {
64 quickList.open(index);
65 quickList.selectedIndex = 0;
66 quickList.focus = true;
67 }
69 MouseArea {
70 id: mouseEventEater
71 anchors.fill: parent
72 acceptedButtons: Qt.AllButtons
73 onWheel: wheel.accepted = true;
74 }
76 Column {
77 id: mainColumn
78 anchors {
79 fill: parent
80 }
82 Rectangle {
83 id: bfb
84 objectName: "buttonShowDashHome"
85 width: parent.width
86 height: width * .9
87 color: UbuntuColors.orange
88 readonly property bool highlighted: root.highlightIndex == -1;
90 Image {
91 objectName: "dashItem"
92 width: parent.width * .6
93 height: width
94 anchors.centerIn: parent
95 source: "graphics/home.png"
96 rotation: root.rotation
97 }
98 AbstractButton {
99 id: dashItem
100 anchors.fill: parent
101 activeFocusOnPress: false
102 onClicked: root.showDashHome()
103 }
105 StyledItem {
106 styleName: "FocusShape"
107 anchors.fill: parent
108 anchors.margins: units.gu(.5)
109 StyleHints {
110 visible: bfb.highlighted
111 radius: 0
112 }
113 }
114 }
116 Item {
117 anchors.left: parent.left
118 anchors.right: parent.right
119 height: parent.height - dashItem.height - parent.spacing*2
121 Item {
122 id: launcherListViewItem
123 anchors.fill: parent
124 clip: true
126 ListView {
127 id: launcherListView
128 objectName: "launcherListView"
129 anchors {
130 fill: parent
131 topMargin: -extensionSize + width * .15
132 bottomMargin: -extensionSize + width * .15
133 }
134 topMargin: extensionSize
135 bottomMargin: extensionSize
136 height: parent.height - dashItem.height - parent.spacing*2
137 model: root.model
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: {
160 initTimer.start();
161 }
162 Timer {
163 id: initTimer
164 interval: 1
165 onTriggered: {
166 launcherListView.moveToIndex(0)
167 }
168 }
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
190 property: "contentY"
191 to: launcherListView.originY + launcherListView.topMargin
192 }
194 UbuntuNumberAnimation {
195 id: snapToTopAnimation
196 target: launcherListView
197 property: "contentY"
198 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
199 }
201 UbuntuNumberAnimation {
202 id: moveAnimation
203 objectName: "moveAnimation"
204 target: launcherListView
205 property: "contentY"
206 function moveTo(contentY) {
207 from = launcherListView.contentY;
208 to = contentY;
209 restart();
210 }
211 }
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);
221 }
222 }
224 displaced: Transition {
225 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
226 }
228 delegate: FoldingLauncherDelegate {
229 id: launcherDelegate
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
233 // multiple apps.
234 readonly property string appId: model.appId
235 name: model.name
236 itemIndex: index
237 itemHeight: launcherListView.itemHeight
238 itemWidth: launcherListView.itemWidth
239 width: parent.width
240 height: itemHeight
241 iconName: model.icon
242 count: model.count
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
252 z: -Math.abs(offset)
253 maxAngle: 55
254 property bool dragging: false
256 SequentialAnimation {
257 id: peekingAnimation
259 // revealing
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
265 alwaysRunToEnd: true
266 loops: 1
267 properties: "x"
268 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
269 duration: UbuntuAnimation.BriskDuration
270 }
272 // hiding
273 UbuntuNumberAnimation {
274 target: launcherDelegate
275 alwaysRunToEnd: true
276 loops: 1
277 properties: "x"
278 to: 0
279 duration: UbuntuAnimation.BriskDuration
280 }
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 }
285 }
287 onAlertingChanged: {
288 if(alerting) {
289 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
290 launcherListView.moveToIndex(index)
291 if (!dragging && launcher.state !== "visible") {
292 peekingAnimation.start()
293 }
294 }
296 if (launcherListView.peekingIndex === -1) {
297 launcherListView.peekingIndex = index
298 }
299 } else {
300 if (launcherListView.peekingIndex === index) {
301 launcherListView.peekingIndex = -1
302 }
303 }
304 }
306 Image {
307 id: dropIndicator
308 objectName: "dropIndicator"
309 anchors.centerIn: parent
310 height: visible ? units.dp(2) : 0
311 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
312 opacity: 0
313 source: "graphics/divider-line.png"
314 }
316 states: [
317 State {
318 name: "selected"
319 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
320 PropertyChanges {
321 target: launcherDelegate
322 itemOpacity: 0
323 }
324 },
325 State {
326 name: "dragging"
327 when: dragging
328 PropertyChanges {
329 target: launcherDelegate
330 height: units.gu(1)
331 itemOpacity: 0
332 }
333 PropertyChanges {
334 target: dropIndicator
335 opacity: 1
336 }
337 },
338 State {
339 name: "expanded"
340 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
341 PropertyChanges {
342 target: launcherDelegate
343 angle: 0
344 offset: 0
345 itemOpacity: 0.6
346 }
347 }
348 ]
350 transitions: [
351 Transition {
352 from: ""
353 to: "selected"
354 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
355 },
356 Transition {
357 from: "*"
358 to: "expanded"
359 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
360 UbuntuNumberAnimation { properties: "angle,offset" }
361 },
362 Transition {
363 from: "expanded"
364 to: ""
365 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
366 UbuntuNumberAnimation { properties: "angle,offset" }
367 },
368 Transition {
369 id: draggingTransition
370 from: "selected"
371 to: "dragging"
372 SequentialAnimation {
373 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
374 ParallelAnimation {
375 UbuntuNumberAnimation { properties: "height" }
376 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
377 }
378 ScriptAction {
379 script: {
380 if (launcherListView.scheduledMoveTo > -1) {
381 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
382 dndArea.draggedIndex = launcherListView.scheduledMoveTo
383 launcherListView.scheduledMoveTo = -1
384 }
385 }
386 }
387 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
388 }
389 },
390 Transition {
391 from: "dragging"
392 to: "*"
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 }
401 }
402 }
403 ]
404 }
406 MouseArea {
407 id: dndArea
408 objectName: "dndArea"
409 acceptedButtons: Qt.LeftButton | Qt.RightButton
410 hoverEnabled: true
411 anchors {
412 fill: parent
413 topMargin: launcherListView.topMargin
414 bottomMargin: launcherListView.bottomMargin
415 }
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
424 property int startX
425 property int startY
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
436 onPressed: {
437 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
438 pressedStartAngle = clickedItem.angle;
439 processPress(mouse);
440 }
442 function processPress(mouse) {
443 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
444 }
446 onClicked: {
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) {
452 return;
453 }
455 if (mouse.button & Qt.RightButton) { // context menu
456 // Opening QuickList
457 quickList.open(index);
458 return;
459 }
461 Haptics.play();
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);
468 }
469 return;
470 }
472 // the rest launches apps up to an angle of 30 degrees
473 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
474 launcherListView.moveToIndex(index);
475 } else {
476 root.applicationSelected(LauncherModel.get(index).appId);
477 }
478 }
480 onCanceled: {
481 endDrag(drag);
482 }
484 onReleased: {
485 endDrag(drag);
486 }
488 function endDrag(dragItem) {
489 var droppedIndex = draggedIndex;
490 if (dragging) {
491 postDragging = true;
492 } else {
493 draggedIndex = -1;
494 }
496 if (!selectedItem) {
497 return;
498 }
500 selectedItem.dragging = false;
501 selectedItem = undefined;
502 preDragging = false;
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();
512 }
513 }
515 onPressAndHold: {
516 processPressAndHold(mouse, drag);
517 }
519 function processPressAndHold(mouse, dragItem) {
520 if (Math.abs(selectedItem.angle) > 30) {
521 return;
522 }
524 Haptics.play();
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
544 startX = mouse.x
545 startY = mouse.y
546 }
548 onPositionChanged: {
549 processPositionChanged(mouse)
550 }
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)) {
557 preDragging = true;
558 quickList.state = "";
559 }
560 if (distance > launcherListView.itemHeight) {
561 selectedItem.dragging = true
562 preDragging = false;
563 }
564 }
565 if (!selectedItem.dragging) {
566 return
567 }
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()
580 } else {
581 progressiveScrollingTimer.stop()
582 }
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
590 } else {
591 return
592 }
594 if (newIndex >= 0 && newIndex < launcherListView.count) {
595 if (launcherListView.draggingTransitionRunning) {
596 launcherListView.scheduledMoveTo = newIndex
597 } else {
598 launcherListView.model.move(draggedIndex, newIndex)
599 draggedIndex = newIndex
600 }
601 }
602 }
603 }
604 }
605 Timer {
606 id: progressiveScrollingTimer
607 interval: 2
608 repeat: true
609 running: false
610 property bool downwards: true
611 onTriggered: {
612 if (downwards) {
613 var minY = -launcherListView.topMargin
614 if (launcherListView.contentY > minY) {
615 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
616 }
617 } else {
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)
621 }
622 }
623 }
624 }
625 }
626 }
628 LauncherDelegate {
629 id: fakeDragItem
630 objectName: "fakeDragItem"
631 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
632 itemWidth: launcherListView.itemWidth
633 itemHeight: launcherListView.itemHeight
634 height: itemHeight
635 width: itemWidth
636 rotation: root.rotation
637 itemOpacity: 0.9
638 onVisibleChanged: if (!visible) iconName = "";
640 function flatten() {
641 fakeDragItemAnimation.start();
642 }
644 UbuntuNumberAnimation {
645 id: fakeDragItemAnimation
646 target: fakeDragItem;
647 properties: "angle,offset";
648 to: 0
649 }
650 }
651 }
652 }
654 UbuntuShape {
655 id: quickListShape
656 objectName: "quickListShape"
657 anchors.fill: quickList
658 opacity: quickList.state === "open" ? 0.95 : 0
659 visible: opacity > 0
660 rotation: root.rotation
661 aspect: UbuntuShape.Flat
663 Behavior on opacity {
664 UbuntuNumberAnimation {}
665 }
667 source: ShaderEffectSource {
668 sourceItem: quickList
669 hideSource: true
670 }
672 Image {
673 anchors {
674 right: parent.left
675 rightMargin: -units.dp(4)
676 verticalCenter: parent.verticalCenter
677 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
678 }
679 height: units.gu(1)
680 width: units.gu(2)
681 source: "graphics/quicklist_tooltip.png"
682 rotation: 90
683 }
684 }
686 InverseMouseArea {
687 anchors.fill: quickListShape
688 enabled: quickList.state == "open" || pressed
690 onClicked: {
691 quickList.state = "";
692 quickList.focus = false;
693 root.kbdNavigationCancelled();
694 }
696 // Forward for dragging to work when quickList is open
698 onPressed: {
699 var m = mapToItem(dndArea, mouseX, mouseY)
700 dndArea.processPress(m)
701 }
703 onPressAndHold: {
704 var m = mapToItem(dndArea, mouseX, mouseY)
705 dndArea.processPressAndHold(m, drag)
706 }
708 onPositionChanged: {
709 var m = mapToItem(dndArea, mouseX, mouseY)
710 dndArea.processPositionChanged(m)
711 }
713 onCanceled: {
714 dndArea.endDrag(drag);
715 }
717 onReleased: {
718 dndArea.endDrag(drag);
719 }
720 }
722 Rectangle {
723 id: quickList
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
731 anchors {
732 left: root.inverted ? undefined : parent.right
733 right: root.inverted ? parent.left : undefined
734 margins: units.gu(1)
735 }
736 y: itemCenter - (height / 2) + offset
737 rotation: root.rotation
739 property var model
740 property string appId
741 property var item
742 property int selectedIndex: -1
744 Keys.onPressed: {
745 switch (event.key) {
746 case Qt.Key_Down:
747 selectedIndex++;
748 if (selectedIndex >= popoverRepeater.count) {
749 selectedIndex = 0;
750 }
751 event.accepted = true;
752 break;
753 case Qt.Key_Up:
754 selectedIndex--;
755 if (selectedIndex < 0) {
756 selectedIndex = popoverRepeater.count - 1;
757 }
758 event.accepted = true;
759 break;
760 case Qt.Key_Left:
761 case Qt.Key_Escape:
762 quickList.selectedIndex = -1;
763 quickList.focus = false;
764 quickList.state = ""
765 event.accepted = true;
766 break;
767 case Qt.Key_Enter:
768 case Qt.Key_Return:
769 case Qt.Key_Space:
770 if (quickList.selectedIndex >= 0) {
771 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
772 }
773 quickList.selectedIndex = -1;
774 quickList.focus = false;
775 quickList.state = ""
776 root.kbdNavigationCancelled();
777 event.accepted = true;
778 break;
779 }
780 }
782 // internal
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();
796 }
798 Item {
799 width: parent.width
800 height: quickListColumn.height
802 Column {
803 id: quickListColumn
804 width: parent.width
805 height: childrenRect.height
807 Repeater {
808 id: popoverRepeater
809 model: quickList.model
811 ListItem {
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
821 Label {
822 id: label
823 anchors.fill: parent
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
829 text: model.label
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
833 }
835 onClicked: {
836 if (!model.clickable) {
837 return;
838 }
839 Haptics.play();
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;
847 }
848 }
849 }
850 }
851 }
852 }
854 Tooltip {
855 id: tooltipShape
856 objectName: "tooltipShape"
858 visible: tooltipShownState.active
859 rotation: root.rotation
860 y: itemCenter - (height / 2)
862 anchors {
863 left: root.inverted ? undefined : parent.right
864 right: root.inverted ? parent.left : undefined
865 margins: units.gu(1)
866 }
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
872 }
874 DSM.StateMachine {
875 id: tooltipStateMachine
876 initialState: tooltipHiddenState
877 running: true
879 DSM.State {
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
887 }
888 }
890 DSM.State {
891 id: tooltipShownState
893 DSM.SignalTransition {
894 targetState: tooltipHiddenState
895 signal: tooltipShape.hoveredItemChanged
896 guard: tooltipShape.hoveredItem === null
897 }
899 DSM.SignalTransition {
900 targetState: tooltipDismissedState
901 signal: dndArea.onPressed
902 }
904 DSM.SignalTransition {
905 targetState: tooltipDismissedState
906 signal: quickList.stateChanged
907 guard: quickList.state === "open"
908 }
909 }
911 DSM.State {
912 id: tooltipDismissedState
914 DSM.SignalTransition {
915 targetState: tooltipHiddenState
916 signal: dndArea.positionChanged
917 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
918 }
920 DSM.SignalTransition {
921 targetState: tooltipHiddenState
922 signal: dndArea.exited
923 guard: quickList.state != "open"
924 }
925 }
926 }