on e1659ca help sign in
unity8/qml/Launcher/LauncherPanel.qml
922 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 objectName: "buttonShowDashHome"
84 width: parent.width
85 height: width * .9
86 color: UbuntuColors.orange
87 readonly property bool highlighted: root.highlightIndex == -1;
89 Image {
90 objectName: "dashItem"
91 width: parent.width * .6
92 height: width
93 anchors.centerIn: parent
94 source: "graphics/home.png"
95 rotation: root.rotation
96 }
97 AbstractButton {
98 id: dashItem
99 anchors.fill: parent
100 activeFocusOnPress: false
101 onClicked: root.showDashHome()
102 }
103 Rectangle {
104 objectName: "bfbFocusHighlight"
105 anchors.fill: parent
106 border.color: "white"
107 border.width: units.dp(1)
108 color: "transparent"
109 visible: parent.highlighted
110 }
111 }
113 Item {
114 anchors.left: parent.left
115 anchors.right: parent.right
116 height: parent.height - dashItem.height - parent.spacing*2
118 Item {
119 id: launcherListViewItem
120 anchors.fill: parent
121 clip: true
123 ListView {
124 id: launcherListView
125 objectName: "launcherListView"
126 anchors {
127 fill: parent
128 topMargin: -extensionSize + width * .15
129 bottomMargin: -extensionSize + width * .15
130 }
131 topMargin: extensionSize
132 bottomMargin: extensionSize
133 height: parent.height - dashItem.height - parent.spacing*2
134 model: root.model
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: {
157 initTimer.start();
158 }
159 Timer {
160 id: initTimer
161 interval: 1
162 onTriggered: {
163 launcherListView.moveToIndex(0)
164 }
165 }
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
187 property: "contentY"
188 to: launcherListView.originY + launcherListView.topMargin
189 }
191 UbuntuNumberAnimation {
192 id: snapToTopAnimation
193 target: launcherListView
194 property: "contentY"
195 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
196 }
198 UbuntuNumberAnimation {
199 id: moveAnimation
200 objectName: "moveAnimation"
201 target: launcherListView
202 property: "contentY"
203 function moveTo(contentY) {
204 from = launcherListView.contentY;
205 to = contentY;
206 restart();
207 }
208 }
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);
218 }
219 }
221 displaced: Transition {
222 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
223 }
225 delegate: FoldingLauncherDelegate {
226 id: launcherDelegate
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
230 // multiple apps.
231 readonly property string appId: model.appId
232 name: model.name
233 itemIndex: index
234 itemHeight: launcherListView.itemHeight
235 itemWidth: launcherListView.itemWidth
236 width: parent.width
237 height: itemHeight
238 iconName: model.icon
239 count: model.count
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
249 z: -Math.abs(offset)
250 maxAngle: 55
251 property bool dragging: false
253 SequentialAnimation {
254 id: peekingAnimation
256 // revealing
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
262 alwaysRunToEnd: true
263 loops: 1
264 properties: "x"
265 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
266 duration: UbuntuAnimation.BriskDuration
267 }
269 // hiding
270 UbuntuNumberAnimation {
271 target: launcherDelegate
272 alwaysRunToEnd: true
273 loops: 1
274 properties: "x"
275 to: 0
276 duration: UbuntuAnimation.BriskDuration
277 }
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 }
282 }
284 onAlertingChanged: {
285 if(alerting) {
286 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
287 launcherListView.moveToIndex(index)
288 if (!dragging && launcher.state !== "visible") {
289 peekingAnimation.start()
290 }
291 }
293 if (launcherListView.peekingIndex === -1) {
294 launcherListView.peekingIndex = index
295 }
296 } else {
297 if (launcherListView.peekingIndex === index) {
298 launcherListView.peekingIndex = -1
299 }
300 }
301 }
303 Image {
304 id: dropIndicator
305 objectName: "dropIndicator"
306 anchors.centerIn: parent
307 height: visible ? units.dp(2) : 0
308 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
309 opacity: 0
310 source: "graphics/divider-line.png"
311 }
313 states: [
314 State {
315 name: "selected"
316 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
317 PropertyChanges {
318 target: launcherDelegate
319 itemOpacity: 0
320 }
321 },
322 State {
323 name: "dragging"
324 when: dragging
325 PropertyChanges {
326 target: launcherDelegate
327 height: units.gu(1)
328 itemOpacity: 0
329 }
330 PropertyChanges {
331 target: dropIndicator
332 opacity: 1
333 }
334 },
335 State {
336 name: "expanded"
337 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
338 PropertyChanges {
339 target: launcherDelegate
340 angle: 0
341 offset: 0
342 itemOpacity: 0.6
343 }
344 }
345 ]
347 transitions: [
348 Transition {
349 from: ""
350 to: "selected"
351 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
352 },
353 Transition {
354 from: "*"
355 to: "expanded"
356 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
357 UbuntuNumberAnimation { properties: "angle,offset" }
358 },
359 Transition {
360 from: "expanded"
361 to: ""
362 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
363 UbuntuNumberAnimation { properties: "angle,offset" }
364 },
365 Transition {
366 id: draggingTransition
367 from: "selected"
368 to: "dragging"
369 SequentialAnimation {
370 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
371 ParallelAnimation {
372 UbuntuNumberAnimation { properties: "height" }
373 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
374 }
375 ScriptAction {
376 script: {
377 if (launcherListView.scheduledMoveTo > -1) {
378 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
379 dndArea.draggedIndex = launcherListView.scheduledMoveTo
380 launcherListView.scheduledMoveTo = -1
381 }
382 }
383 }
384 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
385 }
386 },
387 Transition {
388 from: "dragging"
389 to: "*"
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 }
398 }
399 }
400 ]
401 }
403 MouseArea {
404 id: dndArea
405 objectName: "dndArea"
406 acceptedButtons: Qt.LeftButton | Qt.RightButton
407 hoverEnabled: true
408 anchors {
409 fill: parent
410 topMargin: launcherListView.topMargin
411 bottomMargin: launcherListView.bottomMargin
412 }
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
421 property int startX
422 property int startY
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
433 onPressed: {
434 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
435 pressedStartAngle = clickedItem.angle;
436 processPress(mouse);
437 }
439 function processPress(mouse) {
440 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
441 }
443 onClicked: {
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) {
449 return;
450 }
452 if (mouse.button & Qt.RightButton) { // context menu
453 // Opening QuickList
454 quickList.open(index);
455 return;
456 }
458 Haptics.play();
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);
465 }
466 return;
467 }
469 // the rest launches apps up to an angle of 30 degrees
470 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
471 launcherListView.moveToIndex(index);
472 } else {
473 root.applicationSelected(LauncherModel.get(index).appId);
474 }
475 }
477 onCanceled: {
478 endDrag(drag);
479 }
481 onReleased: {
482 endDrag(drag);
483 }
485 function endDrag(dragItem) {
486 var droppedIndex = draggedIndex;
487 if (dragging) {
488 postDragging = true;
489 } else {
490 draggedIndex = -1;
491 }
493 if (!selectedItem) {
494 return;
495 }
497 selectedItem.dragging = false;
498 selectedItem = undefined;
499 preDragging = false;
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();
509 }
510 }
512 onPressAndHold: {
513 processPressAndHold(mouse, drag);
514 }
516 function processPressAndHold(mouse, dragItem) {
517 if (Math.abs(selectedItem.angle) > 30) {
518 return;
519 }
521 Haptics.play();
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
541 startX = mouse.x
542 startY = mouse.y
543 }
545 onPositionChanged: {
546 processPositionChanged(mouse)
547 }
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)) {
554 preDragging = true;
555 quickList.state = "";
556 }
557 if (distance > launcherListView.itemHeight) {
558 selectedItem.dragging = true
559 preDragging = false;
560 }
561 }
562 if (!selectedItem.dragging) {
563 return
564 }
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()
577 } else {
578 progressiveScrollingTimer.stop()
579 }
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
587 } else {
588 return
589 }
591 if (newIndex >= 0 && newIndex < launcherListView.count) {
592 if (launcherListView.draggingTransitionRunning) {
593 launcherListView.scheduledMoveTo = newIndex
594 } else {
595 launcherListView.model.move(draggedIndex, newIndex)
596 draggedIndex = newIndex
597 }
598 }
599 }
600 }
601 }
602 Timer {
603 id: progressiveScrollingTimer
604 interval: 2
605 repeat: true
606 running: false
607 property bool downwards: true
608 onTriggered: {
609 if (downwards) {
610 var minY = -launcherListView.topMargin
611 if (launcherListView.contentY > minY) {
612 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
613 }
614 } else {
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)
618 }
619 }
620 }
621 }
622 }
623 }
625 LauncherDelegate {
626 id: fakeDragItem
627 objectName: "fakeDragItem"
628 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
629 itemWidth: launcherListView.itemWidth
630 itemHeight: launcherListView.itemHeight
631 height: itemHeight
632 width: itemWidth
633 rotation: root.rotation
634 itemOpacity: 0.9
635 onVisibleChanged: if (!visible) iconName = "";
637 function flatten() {
638 fakeDragItemAnimation.start();
639 }
641 UbuntuNumberAnimation {
642 id: fakeDragItemAnimation
643 target: fakeDragItem;
644 properties: "angle,offset";
645 to: 0
646 }
647 }
648 }
649 }
651 UbuntuShape {
652 id: quickListShape
653 objectName: "quickListShape"
654 anchors.fill: quickList
655 opacity: quickList.state === "open" ? 0.95 : 0
656 visible: opacity > 0
657 rotation: root.rotation
658 aspect: UbuntuShape.Flat
660 Behavior on opacity {
661 UbuntuNumberAnimation {}
662 }
664 source: ShaderEffectSource {
665 sourceItem: quickList
666 hideSource: true
667 }
669 Image {
670 anchors {
671 right: parent.left
672 rightMargin: -units.dp(4)
673 verticalCenter: parent.verticalCenter
674 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
675 }
676 height: units.gu(1)
677 width: units.gu(2)
678 source: "graphics/quicklist_tooltip.png"
679 rotation: 90
680 }
681 }
683 InverseMouseArea {
684 anchors.fill: quickListShape
685 enabled: quickList.state == "open" || pressed
687 onClicked: {
688 quickList.state = "";
689 quickList.focus = false;
690 root.kbdNavigationCancelled();
691 }
693 // Forward for dragging to work when quickList is open
695 onPressed: {
696 var m = mapToItem(dndArea, mouseX, mouseY)
697 dndArea.processPress(m)
698 }
700 onPressAndHold: {
701 var m = mapToItem(dndArea, mouseX, mouseY)
702 dndArea.processPressAndHold(m, drag)
703 }
705 onPositionChanged: {
706 var m = mapToItem(dndArea, mouseX, mouseY)
707 dndArea.processPositionChanged(m)
708 }
710 onCanceled: {
711 dndArea.endDrag(drag);
712 }
714 onReleased: {
715 dndArea.endDrag(drag);
716 }
717 }
719 Rectangle {
720 id: quickList
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
728 anchors {
729 left: root.inverted ? undefined : parent.right
730 right: root.inverted ? parent.left : undefined
731 margins: units.gu(1)
732 }
733 y: itemCenter - (height / 2) + offset
734 rotation: root.rotation
736 property var model
737 property string appId
738 property var item
739 property int selectedIndex: -1
741 Keys.onPressed: {
742 switch (event.key) {
743 case Qt.Key_Down:
744 selectedIndex++;
745 if (selectedIndex >= popoverRepeater.count) {
746 selectedIndex = 0;
747 }
748 event.accepted = true;
749 break;
750 case Qt.Key_Up:
751 selectedIndex--;
752 if (selectedIndex < 0) {
753 selectedIndex = popoverRepeater.count - 1;
754 }
755 event.accepted = true;
756 break;
757 case Qt.Key_Left:
758 case Qt.Key_Escape:
759 quickList.selectedIndex = -1;
760 quickList.focus = false;
761 quickList.state = ""
762 event.accepted = true;
763 break;
764 case Qt.Key_Enter:
765 case Qt.Key_Return:
766 case Qt.Key_Space:
767 if (quickList.selectedIndex >= 0) {
768 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
769 }
770 quickList.selectedIndex = -1;
771 quickList.focus = false;
772 quickList.state = ""
773 root.kbdNavigationCancelled();
774 event.accepted = true;
775 break;
776 }
777 }
779 // internal
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";
791 }
793 Item {
794 width: parent.width
795 height: quickListColumn.height
797 Column {
798 id: quickListColumn
799 width: parent.width
800 height: childrenRect.height
802 Repeater {
803 id: popoverRepeater
804 model: quickList.model
806 ListItem {
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
816 Label {
817 id: label
818 anchors.fill: parent
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
824 text: model.label
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
828 }
830 onClicked: {
831 if (!model.clickable) {
832 return;
833 }
834 Haptics.play();
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;
842 }
843 }
844 }
845 }
846 }
847 }
849 Tooltip {
850 id: tooltipShape
851 objectName: "tooltipShape"
853 visible: tooltipShownState.active
854 rotation: root.rotation
855 y: itemCenter - (height / 2)
857 anchors {
858 left: root.inverted ? undefined : parent.right
859 right: root.inverted ? parent.left : undefined
860 margins: units.gu(1)
861 }
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
867 }
869 DSM.StateMachine {
870 id: tooltipStateMachine
871 initialState: tooltipHiddenState
872 running: true
874 DSM.State {
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
882 }
883 }
885 DSM.State {
886 id: tooltipShownState
888 DSM.SignalTransition {
889 targetState: tooltipHiddenState
890 signal: tooltipShape.hoveredItemChanged
891 guard: tooltipShape.hoveredItem === null
892 }
894 DSM.SignalTransition {
895 targetState: tooltipDismissedState
896 signal: dndArea.onPressed
897 }
899 DSM.SignalTransition {
900 targetState: tooltipDismissedState
901 signal: quickList.stateChanged
902 guard: quickList.state === "open"
903 }
904 }
906 DSM.State {
907 id: tooltipDismissedState
909 DSM.SignalTransition {
910 targetState: tooltipHiddenState
911 signal: dndArea.positionChanged
912 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
913 }
915 DSM.SignalTransition {
916 targetState: tooltipHiddenState
917 signal: dndArea.exited
918 guard: quickList.state != "open"
919 }
920 }
921 }