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