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