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