on bb09f86 help sign in
unity8/qml/Launcher/LauncherPanel.qml
930 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
38 readonly property bool quickListOpen: quickList.state === "open"
40 signal applicationSelected(string appId)
41 signal showDashHome()
42 signal kbdNavigationCancelled()
44 onXChanged: {
45 if (quickList.state === "open") {
46 quickList.state = ""
47 }
48 }
50 function highlightNext() {
51 highlightIndex++;
52 if (highlightIndex >= launcherListView.count) {
53 highlightIndex = -1;
54 }
55 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
56 }
57 function highlightPrevious() {
58 highlightIndex--;
59 if (highlightIndex <= -2) {
60 highlightIndex = launcherListView.count - 1;
61 }
62 launcherListView.moveToIndex(Math.max(highlightIndex, 0));
63 }
64 function openQuicklist(index) {
65 quickList.open(index);
66 quickList.selectedIndex = 0;
67 quickList.focus = true;
68 }
70 MouseArea {
71 id: mouseEventEater
72 anchors.fill: parent
73 acceptedButtons: Qt.AllButtons
74 onWheel: wheel.accepted = true;
75 }
77 Column {
78 id: mainColumn
79 anchors {
80 fill: parent
81 }
83 Rectangle {
84 id: bfb
85 objectName: "buttonShowDashHome"
86 width: parent.width
87 height: width * .9
88 color: UbuntuColors.orange
89 readonly property bool highlighted: root.highlightIndex == -1;
91 Image {
92 objectName: "dashItem"
93 width: parent.width * .6
94 height: width
95 anchors.centerIn: parent
96 source: "graphics/home.png"
97 rotation: root.rotation
98 }
99 AbstractButton {
100 id: dashItem
101 anchors.fill: parent
102 activeFocusOnPress: false
103 onClicked: root.showDashHome()
104 }
106 StyledItem {
107 styleName: "FocusShape"
108 anchors.fill: parent
109 anchors.margins: units.gu(.5)
110 StyleHints {
111 visible: bfb.highlighted
112 radius: 0
113 }
114 }
115 }
117 Item {
118 anchors.left: parent.left
119 anchors.right: parent.right
120 height: parent.height - dashItem.height - parent.spacing*2
122 Item {
123 id: launcherListViewItem
124 anchors.fill: parent
125 clip: true
127 ListView {
128 id: launcherListView
129 objectName: "launcherListView"
130 anchors {
131 fill: parent
132 topMargin: -extensionSize + width * .15
133 bottomMargin: -extensionSize + width * .15
134 }
135 topMargin: extensionSize
136 bottomMargin: extensionSize
137 height: parent.height - dashItem.height - parent.spacing*2
138 model: root.model
139 cacheBuffer: itemHeight * 3
140 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
141 highlightRangeMode: ListView.ApplyRange
142 preferredHighlightBegin: (height - itemHeight) / 2
143 preferredHighlightEnd: (height + itemHeight) / 2
145 // for the single peeking icon, when alert-state is set on delegate
146 property int peekingIndex: -1
148 // The size of the area the ListView is extended to make sure items are not
149 // destroyed when dragging them outside the list. This needs to be at least
150 // itemHeight to prevent folded items from disappearing and DragArea limits
151 // need to be smaller than this size to avoid breakage.
152 property int extensionSize: itemHeight * 3
154 // Workaround: The snap settings in the launcher, will always try to
155 // snap to what we told it to do. However, we want the initial position
156 // of the launcher to not be centered, but instead start with the topmost
157 // item unfolded completely. Lets wait for the ListView to settle after
158 // creation and then reposition it to 0.
159 // https://bugreports.qt-project.org/browse/QTBUG-32251
160 Component.onCompleted: {
161 initTimer.start();
162 }
163 Timer {
164 id: initTimer
165 interval: 1
166 onTriggered: {
167 launcherListView.moveToIndex(0)
168 }
169 }
171 // The height of the area where icons start getting folded
172 property int foldingStartHeight: itemHeight
173 // The height of the area where the items reach the final folding angle
174 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
175 property int itemWidth: width * .75
176 property int itemHeight: itemWidth * 15 / 16 + units.gu(1)
177 property int clickFlickSpeed: units.gu(60)
178 property int draggedIndex: dndArea.draggedIndex
179 property real realContentY: contentY - originY + topMargin
180 property int realItemHeight: itemHeight + spacing
182 // In case the start dragging transition is running, we need to delay the
183 // move because the displaced transition would clash with it and cause items
184 // to be moved to wrong places
185 property bool draggingTransitionRunning: false
186 property int scheduledMoveTo: -1
188 UbuntuNumberAnimation {
189 id: snapToBottomAnimation
190 target: launcherListView
191 property: "contentY"
192 to: launcherListView.originY + launcherListView.topMargin
193 }
195 UbuntuNumberAnimation {
196 id: snapToTopAnimation
197 target: launcherListView
198 property: "contentY"
199 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
200 }
202 UbuntuNumberAnimation {
203 id: moveAnimation
204 objectName: "moveAnimation"
205 target: launcherListView
206 property: "contentY"
207 function moveTo(contentY) {
208 from = launcherListView.contentY;
209 to = contentY;
210 restart();
211 }
212 }
213 function moveToIndex(index) {
214 var totalItemHeight = launcherListView.itemHeight + launcherListView.spacing
215 var itemPosition = index * totalItemHeight;
216 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
217 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : totalItemHeight
218 if (itemPosition + totalItemHeight + distanceToEnd > launcherListView.contentY + launcherListView.originY + launcherListView.topMargin + height) {
219 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd - launcherListView.originY);
220 } else if (itemPosition - distanceToEnd < launcherListView.contentY - launcherListView.originY + launcherListView.topMargin) {
221 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin + launcherListView.originY);
222 }
223 }
225 displaced: Transition {
226 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
227 }
229 delegate: FoldingLauncherDelegate {
230 id: launcherDelegate
231 objectName: "launcherDelegate" + index
232 // We need the appId in the delegate in order to find
233 // the right app when running autopilot tests for
234 // multiple apps.
235 readonly property string appId: model.appId
236 name: model.name
237 itemIndex: index
238 itemHeight: launcherListView.itemHeight
239 itemWidth: launcherListView.itemWidth
240 width: parent.width
241 height: itemHeight
242 iconName: model.icon
243 count: model.count
244 countVisible: model.countVisible
245 progress: model.progress
246 itemRunning: model.running
247 itemFocused: model.focused
248 inverted: root.inverted
249 alerting: model.alerting
250 highlighted: root.highlightIndex == index
251 shortcutHintShown: root.shortcutHintsShown && index <= 9
252 surfaceCount: model.surfaceCount
253 z: -Math.abs(offset)
254 maxAngle: 55
255 property bool dragging: false
257 SequentialAnimation {
258 id: peekingAnimation
260 // revealing
261 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
262 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
264 UbuntuNumberAnimation {
265 target: launcherDelegate
266 alwaysRunToEnd: true
267 loops: 1
268 properties: "x"
269 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
270 duration: UbuntuAnimation.BriskDuration
271 }
273 // hiding
274 UbuntuNumberAnimation {
275 target: launcherDelegate
276 alwaysRunToEnd: true
277 loops: 1
278 properties: "x"
279 to: 0
280 duration: UbuntuAnimation.BriskDuration
281 }
283 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
284 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
285 PropertyAction { target: launcherListView; property: "peekingIndex"; value: -1 }
286 }
288 onAlertingChanged: {
289 if(alerting) {
290 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
291 launcherListView.moveToIndex(index)
292 if (!dragging && launcher.state !== "visible") {
293 peekingAnimation.start()
294 }
295 }
297 if (launcherListView.peekingIndex === -1) {
298 launcherListView.peekingIndex = index
299 }
300 } else {
301 if (launcherListView.peekingIndex === index) {
302 launcherListView.peekingIndex = -1
303 }
304 }
305 }
307 Image {
308 id: dropIndicator
309 objectName: "dropIndicator"
310 anchors.centerIn: parent
311 height: visible ? units.dp(2) : 0
312 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
313 opacity: 0
314 source: "graphics/divider-line.png"
315 }
317 states: [
318 State {
319 name: "selected"
320 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
321 PropertyChanges {
322 target: launcherDelegate
323 itemOpacity: 0
324 }
325 },
326 State {
327 name: "dragging"
328 when: dragging
329 PropertyChanges {
330 target: launcherDelegate
331 height: units.gu(1)
332 itemOpacity: 0
333 }
334 PropertyChanges {
335 target: dropIndicator
336 opacity: 1
337 }
338 },
339 State {
340 name: "expanded"
341 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
342 PropertyChanges {
343 target: launcherDelegate
344 angle: 0
345 offset: 0
346 itemOpacity: 0.6
347 }
348 }
349 ]
351 transitions: [
352 Transition {
353 from: ""
354 to: "selected"
355 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
356 },
357 Transition {
358 from: "*"
359 to: "expanded"
360 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
361 UbuntuNumberAnimation { properties: "angle,offset" }
362 },
363 Transition {
364 from: "expanded"
365 to: ""
366 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
367 UbuntuNumberAnimation { properties: "angle,offset" }
368 },
369 Transition {
370 id: draggingTransition
371 from: "selected"
372 to: "dragging"
373 SequentialAnimation {
374 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
375 ParallelAnimation {
376 UbuntuNumberAnimation { properties: "height" }
377 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
378 }
379 ScriptAction {
380 script: {
381 if (launcherListView.scheduledMoveTo > -1) {
382 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
383 dndArea.draggedIndex = launcherListView.scheduledMoveTo
384 launcherListView.scheduledMoveTo = -1
385 }
386 }
387 }
388 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
389 }
390 },
391 Transition {
392 from: "dragging"
393 to: "*"
394 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
395 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
396 SequentialAnimation {
397 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
398 UbuntuNumberAnimation { properties: "height" }
399 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
400 PropertyAction { target: dndArea; property: "postDragging"; value: false }
401 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
402 }
403 }
404 ]
405 }
407 MouseArea {
408 id: dndArea
409 objectName: "dndArea"
410 acceptedButtons: Qt.LeftButton | Qt.RightButton
411 hoverEnabled: true
412 anchors {
413 fill: parent
414 topMargin: launcherListView.topMargin
415 bottomMargin: launcherListView.bottomMargin
416 }
417 drag.minimumY: -launcherListView.topMargin
418 drag.maximumY: height + launcherListView.bottomMargin
420 property int draggedIndex: -1
421 property var selectedItem
422 property bool preDragging: false
423 property bool dragging: !!selectedItem && selectedItem.dragging
424 property bool postDragging: false
425 property int startX
426 property int startY
428 // This is a workaround for some issue in the QML ListView:
429 // When calling moveToItem(0), the listview visually positions itself
430 // correctly to display the first item expanded. However, some internal
431 // state seems to not be valid, and the next time the user clicks on it,
432 // it snaps back to the snap boundries before executing the onClicked handler.
433 // This can cause the listview getting stuck in a snapped position where you can't
434 // launch things without first dragging the launcher manually. So lets read the item
435 // angle before that happens and use that angle instead of the one we get in onClicked.
436 property real pressedStartAngle: 0
437 onPressed: {
438 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
439 pressedStartAngle = clickedItem.angle;
440 processPress(mouse);
441 }
443 function processPress(mouse) {
444 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
445 }
447 onClicked: {
448 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
449 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
451 // Check if we actually clicked an item or only at the spacing in between
452 if (clickedItem === null) {
453 return;
454 }
456 if (mouse.button & Qt.RightButton) { // context menu
457 // Opening QuickList
458 quickList.open(index);
459 return;
460 }
462 Haptics.play();
464 // First/last item do the scrolling at more than 12 degrees
465 if (index == 0 || index == launcherListView.count - 1) {
466 launcherListView.moveToIndex(index);
467 if (pressedStartAngle <= 12 && pressedStartAngle >= -12) {
468 root.applicationSelected(LauncherModel.get(index).appId);
469 }
470 return;
471 }
473 // the rest launches apps up to an angle of 30 degrees
474 if (clickedItem.angle > 30 || clickedItem.angle < -30) {
475 launcherListView.moveToIndex(index);
476 } else {
477 root.applicationSelected(LauncherModel.get(index).appId);
478 }
479 }
481 onCanceled: {
482 endDrag(drag);
483 }
485 onReleased: {
486 endDrag(drag);
487 }
489 function endDrag(dragItem) {
490 var droppedIndex = draggedIndex;
491 if (dragging) {
492 postDragging = true;
493 } else {
494 draggedIndex = -1;
495 }
497 if (!selectedItem) {
498 return;
499 }
501 selectedItem.dragging = false;
502 selectedItem = undefined;
503 preDragging = false;
505 dragItem.target = undefined
507 progressiveScrollingTimer.stop();
508 launcherListView.interactive = true;
509 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
510 snapToBottomAnimation.start();
511 } else if (droppedIndex < 2 && postDragging) {
512 snapToTopAnimation.start();
513 }
514 }
516 onPressAndHold: {
517 processPressAndHold(mouse, drag);
518 }
520 function processPressAndHold(mouse, dragItem) {
521 if (Math.abs(selectedItem.angle) > 30) {
522 return;
523 }
525 Haptics.play();
527 draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
529 quickList.open(draggedIndex)
531 launcherListView.interactive = false
533 var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
535 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
536 fakeDragItem.x = units.gu(0.5)
537 fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
538 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
539 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
540 fakeDragItem.count = LauncherModel.get(draggedIndex).count
541 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
542 fakeDragItem.flatten()
543 dragItem.target = fakeDragItem
545 startX = mouse.x
546 startY = mouse.y
547 }
549 onPositionChanged: {
550 processPositionChanged(mouse)
551 }
553 function processPositionChanged(mouse) {
554 if (draggedIndex >= 0) {
555 if (!selectedItem.dragging) {
556 var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
557 if (!preDragging && distance > units.gu(1.5)) {
558 preDragging = true;
559 quickList.state = "";
560 }
561 if (distance > launcherListView.itemHeight) {
562 selectedItem.dragging = true
563 preDragging = false;
564 }
565 }
566 if (!selectedItem.dragging) {
567 return
568 }
570 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
572 // Move it down by the the missing size to compensate index calculation with only expanded items
573 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
575 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
576 progressiveScrollingTimer.downwards = false
577 progressiveScrollingTimer.start()
578 } else if (mouseY < launcherListView.realItemHeight) {
579 progressiveScrollingTimer.downwards = true
580 progressiveScrollingTimer.start()
581 } else {
582 progressiveScrollingTimer.stop()
583 }
585 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
587 if (newIndex > draggedIndex + 1) {
588 newIndex = draggedIndex + 1
589 } else if (newIndex < draggedIndex) {
590 newIndex = draggedIndex -1
591 } else {
592 return
593 }
595 if (newIndex >= 0 && newIndex < launcherListView.count) {
596 if (launcherListView.draggingTransitionRunning) {
597 launcherListView.scheduledMoveTo = newIndex
598 } else {
599 launcherListView.model.move(draggedIndex, newIndex)
600 draggedIndex = newIndex
601 }
602 }
603 }
604 }
605 }
606 Timer {
607 id: progressiveScrollingTimer
608 interval: 2
609 repeat: true
610 running: false
611 property bool downwards: true
612 onTriggered: {
613 if (downwards) {
614 var minY = -launcherListView.topMargin
615 if (launcherListView.contentY > minY) {
616 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
617 }
618 } else {
619 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
620 if (launcherListView.contentY < maxY) {
621 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
622 }
623 }
624 }
625 }
626 }
627 }
629 LauncherDelegate {
630 id: fakeDragItem
631 objectName: "fakeDragItem"
632 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
633 itemWidth: launcherListView.itemWidth
634 itemHeight: launcherListView.itemHeight
635 height: itemHeight
636 width: itemWidth
637 rotation: root.rotation
638 itemOpacity: 0.9
639 onVisibleChanged: if (!visible) iconName = "";
641 function flatten() {
642 fakeDragItemAnimation.start();
643 }
645 UbuntuNumberAnimation {
646 id: fakeDragItemAnimation
647 target: fakeDragItem;
648 properties: "angle,offset";
649 to: 0
650 }
651 }
652 }
653 }
655 UbuntuShape {
656 id: quickListShape
657 objectName: "quickListShape"
658 anchors.fill: quickList
659 opacity: quickList.state === "open" ? 0.95 : 0
660 visible: opacity > 0
661 rotation: root.rotation
662 aspect: UbuntuShape.Flat
664 Behavior on opacity {
665 UbuntuNumberAnimation {}
666 }
668 source: ShaderEffectSource {
669 sourceItem: quickList
670 hideSource: true
671 }
673 Image {
674 anchors {
675 right: parent.left
676 rightMargin: -units.dp(4)
677 verticalCenter: parent.verticalCenter
678 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
679 }
680 height: units.gu(1)
681 width: units.gu(2)
682 source: "graphics/quicklist_tooltip.png"
683 rotation: 90
684 }
685 }
687 InverseMouseArea {
688 anchors.fill: quickListShape
689 enabled: quickList.state == "open" || pressed
690 hoverEnabled: enabled
691 visible: enabled
693 onClicked: {
694 quickList.state = "";
695 quickList.focus = false;
696 root.kbdNavigationCancelled();
697 }
699 // Forward for dragging to work when quickList is open
701 onPressed: {
702 var m = mapToItem(dndArea, mouseX, mouseY)
703 dndArea.processPress(m)
704 }
706 onPressAndHold: {
707 var m = mapToItem(dndArea, mouseX, mouseY)
708 dndArea.processPressAndHold(m, drag)
709 }
711 onPositionChanged: {
712 var m = mapToItem(dndArea, mouseX, mouseY)
713 dndArea.processPositionChanged(m)
714 }
716 onCanceled: {
717 dndArea.endDrag(drag);
718 }
720 onReleased: {
721 dndArea.endDrag(drag);
722 }
723 }
725 Rectangle {
726 id: quickList
727 objectName: "quickList"
728 color: theme.palette.normal.background
729 // Because we're setting left/right anchors depending on orientation, it will break the
730 // width setting after rotating twice. This makes sure we also re-apply width on rotation
731 width: root.inverted ? units.gu(30) : units.gu(30)
732 height: quickListColumn.height
733 visible: quickListShape.visible
734 anchors {
735 left: root.inverted ? undefined : parent.right
736 right: root.inverted ? parent.left : undefined
737 margins: units.gu(1)
738 }
739 y: itemCenter - (height / 2) + offset
740 rotation: root.rotation
742 property var model
743 property string appId
744 property var item
745 property int selectedIndex: -1
747 Keys.onPressed: {
748 switch (event.key) {
749 case Qt.Key_Down:
750 selectedIndex++;
751 if (selectedIndex >= popoverRepeater.count) {
752 selectedIndex = 0;
753 }
754 event.accepted = true;
755 break;
756 case Qt.Key_Up:
757 selectedIndex--;
758 if (selectedIndex < 0) {
759 selectedIndex = popoverRepeater.count - 1;
760 }
761 event.accepted = true;
762 break;
763 case Qt.Key_Left:
764 case Qt.Key_Escape:
765 quickList.selectedIndex = -1;
766 quickList.focus = false;
767 quickList.state = ""
768 event.accepted = true;
769 break;
770 case Qt.Key_Enter:
771 case Qt.Key_Return:
772 case Qt.Key_Space:
773 if (quickList.selectedIndex >= 0) {
774 LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
775 }
776 quickList.selectedIndex = -1;
777 quickList.focus = false;
778 quickList.state = ""
779 root.kbdNavigationCancelled();
780 event.accepted = true;
781 break;
782 }
783 }
785 // internal
786 property int itemCenter: item ? root.mapFromItem(quickList.item, 0, 0).y + (item.height / 2) + quickList.item.offset : units.gu(1)
787 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
788 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
790 function open(index) {
791 var itemPosition = index * launcherListView.itemHeight;
792 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
793 item = launcherListView.itemAt(launcherListView.width / 2, itemPosition + launcherListView.itemHeight / 2);
794 quickList.model = launcherListView.model.get(index).quickList;
795 quickList.appId = launcherListView.model.get(index).appId;
796 quickList.state = "open";
797 root.highlightIndex = index;
798 quickList.forceActiveFocus();
799 }
801 Item {
802 width: parent.width
803 height: quickListColumn.height
805 Column {
806 id: quickListColumn
807 width: parent.width
808 height: childrenRect.height
810 Repeater {
811 id: popoverRepeater
812 model: quickList.model
814 ListItem {
815 objectName: "quickListEntry" + index
816 selected: index === quickList.selectedIndex
817 height: label.implicitHeight + label.anchors.topMargin + label.anchors.bottomMargin
818 color: model.clickable ? (selected ? theme.palette.highlighted.background : "transparent") : theme.palette.disabled.background
819 highlightColor: !model.clickable ? quickList.color : undefined // make disabled items visually unclickable
820 divider.colorFrom: UbuntuColors.inkstone
821 divider.colorTo: UbuntuColors.inkstone
822 divider.visible: model.hasSeparator
824 Label {
825 id: label
826 anchors.fill: parent
827 anchors.leftMargin: units.gu(3) // 2 GU for checkmark, 3 GU total
828 anchors.rightMargin: units.gu(2)
829 anchors.topMargin: units.gu(2)
830 anchors.bottomMargin: units.gu(2)
831 verticalAlignment: Label.AlignVCenter
832 text: model.label
833 fontSize: index == 0 ? "medium" : "small"
834 font.weight: index == 0 ? Font.Medium : Font.Light
835 color: model.clickable ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
836 }
838 onClicked: {
839 if (!model.clickable) {
840 return;
841 }
842 Haptics.play();
843 quickList.state = "";
844 // Unsetting model to prevent showing changing entries during fading out
845 // that may happen because of triggering an action.
846 LauncherModel.quickListActionInvoked(quickList.appId, index);
847 quickList.focus = false;
848 root.kbdNavigationCancelled();
849 quickList.model = undefined;
850 }
851 }
852 }
853 }
854 }
855 }
857 Tooltip {
858 id: tooltipShape
859 objectName: "tooltipShape"
861 visible: tooltipShownState.active
862 rotation: root.rotation
863 y: itemCenter - (height / 2)
865 anchors {
866 left: root.inverted ? undefined : parent.right
867 right: root.inverted ? parent.left : undefined
868 margins: units.gu(1)
869 }
871 readonly property var hoveredItem: dndArea.containsMouse ? launcherListView.itemAt(dndArea.mouseX, dndArea.mouseY + launcherListView.realContentY) : null
872 readonly property int itemCenter: !hoveredItem ? 0 : root.mapFromItem(hoveredItem, 0, 0).y + (hoveredItem.height / 2) + hoveredItem.offset
874 text: !hoveredItem ? "" : hoveredItem.name
875 }
877 DSM.StateMachine {
878 id: tooltipStateMachine
879 initialState: tooltipHiddenState
880 running: true
882 DSM.State {
883 id: tooltipHiddenState
885 DSM.SignalTransition {
886 targetState: tooltipShownState
887 signal: tooltipShape.hoveredItemChanged
888 // !dndArea.pressed allows us to filter out touch input events
889 guard: tooltipShape.hoveredItem !== null && !dndArea.pressed && !root.moving
890 }
891 }
893 DSM.State {
894 id: tooltipShownState
896 DSM.SignalTransition {
897 targetState: tooltipHiddenState
898 signal: tooltipShape.hoveredItemChanged
899 guard: tooltipShape.hoveredItem === null
900 }
902 DSM.SignalTransition {
903 targetState: tooltipDismissedState
904 signal: dndArea.onPressed
905 }
907 DSM.SignalTransition {
908 targetState: tooltipDismissedState
909 signal: quickList.stateChanged
910 guard: quickList.state === "open"
911 }
912 }
914 DSM.State {
915 id: tooltipDismissedState
917 DSM.SignalTransition {
918 targetState: tooltipHiddenState
919 signal: dndArea.positionChanged
920 guard: quickList.state != "open" && !dndArea.pressed && !dndArea.moving
921 }
923 DSM.SignalTransition {
924 targetState: tooltipHiddenState
925 signal: dndArea.exited
926 guard: quickList.state != "open"
927 }
928 }
929 }