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