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