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