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