Unity 8
LauncherPanel.qml
1 /*
2  * Copyright (C) 2013 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 Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3 as ListItems
20 import Unity.Launcher 0.1
21 import Ubuntu.Components.Popups 1.3
22 import GlobalShortcut 1.0
23 import "../Components/ListItems"
24 import "../Components/"
25 
26 Rectangle {
27  id: root
28  color: "#E0292929"
29 
30  rotation: inverted ? 180 : 0
31 
32  property var model
33  property bool inverted: 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  || mouseEventEater.containsMouse || dashItem.hovered
38  property int highlightIndex: -2
39  property bool shortcutHintsShown: false
40 
41  signal applicationSelected(string appId)
42  signal showDashHome()
43  signal kbdNavigationCancelled()
44 
45  onXChanged: {
46  if (quickList.state == "open") {
47  quickList.state = ""
48  }
49  }
50 
51  function highlightNext() {
52  highlightIndex++;
53  if (highlightIndex >= launcherListView.count) {
54  highlightIndex = -1;
55  }
56  launcherListView.moveToIndex(Math.max(highlightIndex, 0));
57  }
58  function highlightPrevious() {
59  highlightIndex--;
60  if (highlightIndex <= -2) {
61  highlightIndex = launcherListView.count - 1;
62  }
63  launcherListView.moveToIndex(Math.max(highlightIndex, 0));
64  }
65  function openQuicklist(index) {
66  quickList.open(index);
67  quickList.selectedIndex = 0;
68  quickList.focus = true;
69  }
70 
71  MouseArea {
72  id: mouseEventEater
73  anchors.fill: parent
74  hoverEnabled: true
75  }
76 
77  Column {
78  id: mainColumn
79  anchors {
80  fill: parent
81  }
82 
83  Rectangle {
84  objectName: "buttonShowDashHome"
85  width: parent.width
86  height: width * .9
87  color: UbuntuColors.orange
88  readonly property bool highlighted: root.highlightIndex == -1;
89 
90  Image {
91  objectName: "dashItem"
92  width: parent.width * .6
93  height: width
94  anchors.centerIn: parent
95  source: "graphics/home.png"
96  rotation: root.rotation
97  }
98  AbstractButton {
99  id: dashItem
100  anchors.fill: parent
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  itemIndex: index
229  itemHeight: launcherListView.itemHeight
230  itemWidth: launcherListView.itemWidth
231  width: parent.width
232  height: itemHeight
233  iconName: model.icon
234  count: model.count
235  countVisible: model.countVisible
236  progress: model.progress
237  itemRunning: model.running
238  itemFocused: model.focused
239  inverted: root.inverted
240  alerting: model.alerting
241  highlighted: root.highlightIndex == index
242  shortcutHintShown: root.shortcutHintsShown && index <= 9
243  z: -Math.abs(offset)
244  maxAngle: 55
245  property bool dragging: false
246 
247  SequentialAnimation {
248  id: peekingAnimation
249 
250  // revealing
251  PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
252  PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
253 
254  UbuntuNumberAnimation {
255  target: launcherDelegate
256  alwaysRunToEnd: true
257  loops: 1
258  properties: "x"
259  to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
260  duration: UbuntuAnimation.BriskDuration
261  }
262 
263  // hiding
264  UbuntuNumberAnimation {
265  target: launcherDelegate
266  alwaysRunToEnd: true
267  loops: 1
268  properties: "x"
269  to: 0
270  duration: UbuntuAnimation.BriskDuration
271  }
272 
273  PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
274  PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
275  }
276 
277  onAlertingChanged: {
278  if(alerting) {
279  if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
280  launcherListView.moveToIndex(index)
281  if (!dragging && launcher.state !== "visible") {
282  peekingAnimation.start()
283  }
284  }
285 
286  if (launcherListView.peekingIndex === -1) {
287  launcherListView.peekingIndex = index
288  }
289  } else {
290  if (launcherListView.peekingIndex === index) {
291  launcherListView.peekingIndex = -1
292  }
293  }
294  }
295 
296  ThinDivider {
297  id: dropIndicator
298  objectName: "dropIndicator"
299  anchors.centerIn: parent
300  width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
301  opacity: 0
302  source: "graphics/divider-line.png"
303  }
304 
305  states: [
306  State {
307  name: "selected"
308  when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
309  PropertyChanges {
310  target: launcherDelegate
311  itemOpacity: 0
312  }
313  },
314  State {
315  name: "dragging"
316  when: dragging
317  PropertyChanges {
318  target: launcherDelegate
319  height: units.gu(1)
320  itemOpacity: 0
321  }
322  PropertyChanges {
323  target: dropIndicator
324  opacity: 1
325  }
326  },
327  State {
328  name: "expanded"
329  when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
330  PropertyChanges {
331  target: launcherDelegate
332  angle: 0
333  offset: 0
334  itemOpacity: 0.6
335  }
336  }
337  ]
338 
339  transitions: [
340  Transition {
341  from: ""
342  to: "selected"
343  NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
344  },
345  Transition {
346  from: "*"
347  to: "expanded"
348  NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
349  UbuntuNumberAnimation { properties: "angle,offset" }
350  },
351  Transition {
352  from: "expanded"
353  to: ""
354  NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
355  UbuntuNumberAnimation { properties: "angle,offset" }
356  },
357  Transition {
358  id: draggingTransition
359  from: "selected"
360  to: "dragging"
361  SequentialAnimation {
362  PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
363  ParallelAnimation {
364  UbuntuNumberAnimation { properties: "height" }
365  NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
366  }
367  ScriptAction {
368  script: {
369  if (launcherListView.scheduledMoveTo > -1) {
370  launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
371  dndArea.draggedIndex = launcherListView.scheduledMoveTo
372  launcherListView.scheduledMoveTo = -1
373  }
374  }
375  }
376  PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
377  }
378  },
379  Transition {
380  from: "dragging"
381  to: "*"
382  NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
383  NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
384  SequentialAnimation {
385  ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
386  UbuntuNumberAnimation { properties: "height" }
387  ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
388  PropertyAction { target: dndArea; property: "postDragging"; value: false }
389  PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
390  }
391  }
392  ]
393  }
394 
395  MouseArea {
396  id: dndArea
397  objectName: "dndArea"
398  acceptedButtons: Qt.LeftButton | Qt.RightButton
399  anchors {
400  fill: parent
401  topMargin: launcherListView.topMargin
402  bottomMargin: launcherListView.bottomMargin
403  }
404  drag.minimumY: -launcherListView.topMargin
405  drag.maximumY: height + launcherListView.bottomMargin
406 
407  property int draggedIndex: -1
408  property var selectedItem
409  property bool preDragging: false
410  property bool dragging: !!selectedItem && selectedItem.dragging
411  property bool postDragging: false
412  property int startX
413  property int startY
414 
415  onPressed: {
416  processPress(mouse);
417  }
418 
419  function processPress(mouse) {
420  selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
421  }
422 
423  onClicked: {
424  var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
425  var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
426 
427  // Check if we actually clicked an item or only at the spacing in between
428  if (clickedItem === null) {
429  return;
430  }
431 
432  if (mouse.button & Qt.RightButton) { // context menu
433  // Opening QuickList
434  quickList.open(index);
435  return;
436  }
437 
438  Haptics.play();
439 
440  // First/last item do the scrolling at more than 12 degrees
441  if (index == 0 || index == launcherListView.count - 1) {
442  if (clickedItem.angle > 12 || clickedItem.angle < -12) {
443  launcherListView.moveToIndex(index);
444  } else {
445  root.applicationSelected(LauncherModel.get(index).appId);
446  }
447  return;
448  }
449 
450  // the rest launches apps up to an angle of 30 degrees
451  if (clickedItem.angle > 30 || clickedItem.angle < -30) {
452  launcherListView.moveToIndex(index);
453  } else {
454  root.applicationSelected(LauncherModel.get(index).appId);
455  }
456  }
457 
458  onCanceled: {
459  endDrag(drag);
460  }
461 
462  onReleased: {
463  endDrag(drag);
464  }
465 
466  function endDrag(dragItem) {
467  var droppedIndex = draggedIndex;
468  if (dragging) {
469  postDragging = true;
470  } else {
471  draggedIndex = -1;
472  }
473 
474  if (!selectedItem) {
475  return;
476  }
477 
478  selectedItem.dragging = false;
479  selectedItem = undefined;
480  preDragging = false;
481 
482  dragItem.target = undefined
483 
484  progressiveScrollingTimer.stop();
485  launcherListView.interactive = true;
486  if (droppedIndex >= launcherListView.count - 2 && postDragging) {
487  snapToBottomAnimation.start();
488  } else if (droppedIndex < 2 && postDragging) {
489  snapToTopAnimation.start();
490  }
491  }
492 
493  onPressAndHold: {
494  processPressAndHold(mouse, drag);
495  }
496 
497  function processPressAndHold(mouse, dragItem) {
498  if (Math.abs(selectedItem.angle) > 30) {
499  return;
500  }
501 
502  Haptics.play();
503 
504  draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
505 
506  quickList.open(draggedIndex)
507 
508  launcherListView.interactive = false
509 
510  var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
511 
512  fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
513  fakeDragItem.x = units.gu(0.5)
514  fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
515  fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
516  fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
517  fakeDragItem.count = LauncherModel.get(draggedIndex).count
518  fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
519  fakeDragItem.flatten()
520  dragItem.target = fakeDragItem
521 
522  startX = mouse.x
523  startY = mouse.y
524  }
525 
526  onPositionChanged: {
527  processPositionChanged(mouse)
528  }
529 
530  function processPositionChanged(mouse) {
531  if (draggedIndex >= 0) {
532  if (!selectedItem.dragging) {
533  var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
534  if (!preDragging && distance > units.gu(1.5)) {
535  preDragging = true;
536  quickList.state = "";
537  }
538  if (distance > launcherListView.itemHeight) {
539  selectedItem.dragging = true
540  preDragging = false;
541  }
542  }
543  if (!selectedItem.dragging) {
544  return
545  }
546 
547  var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
548 
549  // Move it down by the the missing size to compensate index calculation with only expanded items
550  itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
551 
552  if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
553  progressiveScrollingTimer.downwards = false
554  progressiveScrollingTimer.start()
555  } else if (mouseY < launcherListView.realItemHeight) {
556  progressiveScrollingTimer.downwards = true
557  progressiveScrollingTimer.start()
558  } else {
559  progressiveScrollingTimer.stop()
560  }
561 
562  var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
563 
564  if (newIndex > draggedIndex + 1) {
565  newIndex = draggedIndex + 1
566  } else if (newIndex < draggedIndex) {
567  newIndex = draggedIndex -1
568  } else {
569  return
570  }
571 
572  if (newIndex >= 0 && newIndex < launcherListView.count) {
573  if (launcherListView.draggingTransitionRunning) {
574  launcherListView.scheduledMoveTo = newIndex
575  } else {
576  launcherListView.model.move(draggedIndex, newIndex)
577  draggedIndex = newIndex
578  }
579  }
580  }
581  }
582  }
583  Timer {
584  id: progressiveScrollingTimer
585  interval: 2
586  repeat: true
587  running: false
588  property bool downwards: true
589  onTriggered: {
590  if (downwards) {
591  var minY = -launcherListView.topMargin
592  if (launcherListView.contentY > minY) {
593  launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
594  }
595  } else {
596  var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
597  if (launcherListView.contentY < maxY) {
598  launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
599  }
600  }
601  }
602  }
603  }
604  }
605 
606  LauncherDelegate {
607  id: fakeDragItem
608  objectName: "fakeDragItem"
609  visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
610  itemWidth: launcherListView.itemWidth
611  itemHeight: launcherListView.itemHeight
612  height: itemHeight
613  width: itemWidth
614  rotation: root.rotation
615  itemOpacity: 0.9
616  onVisibleChanged: if (!visible) iconName = "";
617 
618  function flatten() {
619  fakeDragItemAnimation.start();
620  }
621 
622  UbuntuNumberAnimation {
623  id: fakeDragItemAnimation
624  target: fakeDragItem;
625  properties: "angle,offset";
626  to: 0
627  }
628  }
629  }
630  }
631 
632  UbuntuShapeForItem {
633  id: quickListShape
634  objectName: "quickListShape"
635  anchors.fill: quickList
636  opacity: quickList.state === "open" ? 0.8 : 0
637  visible: opacity > 0
638  rotation: root.rotation
639 
640  Behavior on opacity {
641  UbuntuNumberAnimation {}
642  }
643 
644  image: quickList
645 
646  Image {
647  anchors {
648  right: parent.left
649  rightMargin: -units.dp(4)
650  verticalCenter: parent.verticalCenter
651  verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
652  }
653  height: units.gu(1)
654  width: units.gu(2)
655  source: "graphics/quicklist_tooltip.png"
656  rotation: 90
657  }
658  }
659 
660  InverseMouseArea {
661  anchors.fill: quickListShape
662  enabled: quickList.state == "open" || pressed
663 
664  onClicked: {
665  quickList.state = "";
666  quickList.focus = false;
667  root.kbdNavigationCancelled();
668  }
669 
670  // Forward for dragging to work when quickList is open
671 
672  onPressed: {
673  var m = mapToItem(dndArea, mouseX, mouseY)
674  dndArea.processPress(m)
675  }
676 
677  onPressAndHold: {
678  var m = mapToItem(dndArea, mouseX, mouseY)
679  dndArea.processPressAndHold(m, drag)
680  }
681 
682  onPositionChanged: {
683  var m = mapToItem(dndArea, mouseX, mouseY)
684  dndArea.processPositionChanged(m)
685  }
686 
687  onCanceled: {
688  dndArea.endDrag(drag);
689  }
690 
691  onReleased: {
692  dndArea.endDrag(drag);
693  }
694  }
695 
696  Rectangle {
697  id: quickList
698  objectName: "quickList"
699  color: "#f5f5f5"
700  // Because we're setting left/right anchors depending on orientation, it will break the
701  // width setting after rotating twice. This makes sure we also re-apply width on rotation
702  width: root.inverted ? units.gu(30) : units.gu(30)
703  height: quickListColumn.height
704  visible: quickListShape.visible
705  anchors {
706  left: root.inverted ? undefined : parent.right
707  right: root.inverted ? parent.left : undefined
708  margins: units.gu(1)
709  }
710  y: itemCenter - (height / 2) + offset
711  rotation: root.rotation
712 
713  property var model
714  property string appId
715  property var item
716  property int selectedIndex: -1
717 
718  Keys.onPressed: {
719  switch (event.key) {
720  case Qt.Key_Down:
721  selectedIndex++;
722  if (selectedIndex >= popoverRepeater.count) {
723  selectedIndex = 0;
724  }
725  event.accepted = true;
726  break;
727  case Qt.Key_Up:
728  selectedIndex--;
729  if (selectedIndex < 0) {
730  selectedIndex = popoverRepeater.count - 1;
731  }
732  event.accepted = true;
733  break;
734  case Qt.Key_Left:
735  case Qt.Key_Escape:
736  quickList.selectedIndex = -1;
737  quickList.focus = false;
738  quickList.state = ""
739  event.accepted = true;
740  break;
741  case Qt.Key_Enter:
742  case Qt.Key_Return:
743  case Qt.Key_Space:
744  if (quickList.selectedIndex >= 0) {
745  LauncherModel.quickListActionInvoked(quickList.appId, quickList.selectedIndex)
746  }
747  quickList.selectedIndex = -1;
748  quickList.focus = false;
749  quickList.state = ""
750  root.kbdNavigationCancelled();
751  event.accepted = true;
752  break;
753  }
754  }
755 
756  // internal
757  property int itemCenter: item ? root.mapFromItem(quickList.item).y + (item.height / 2) + quickList.item.offset : units.gu(1)
758  property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
759  itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
760 
761  function open(index) {
762  var itemPosition = index * launcherListView.itemHeight;
763  var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
764  item = launcherListView.itemAt(launcherListView.width / 2, itemPosition + launcherListView.itemHeight / 2);
765  quickList.model = launcherListView.model.get(index).quickList;
766  quickList.appId = launcherListView.model.get(index).appId;
767  quickList.state = "open";
768  }
769 
770  Column {
771  id: quickListColumn
772  width: parent.width
773  height: childrenRect.height
774 
775  Repeater {
776  id: popoverRepeater
777  model: quickList.model
778 
779  ListItems.Standard {
780  objectName: "quickListEntry" + index
781  text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
782  highlightWhenPressed: model.clickable
783  selected: index === quickList.selectedIndex
784 
785  // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
786  // ListItems don't know that they are sitting in a themed Popover where the color
787  // needs to be inverted.
788  __foregroundColor: "black"
789 
790  onClicked: {
791  if (!model.clickable) {
792  return;
793  }
794  Haptics.play();
795  quickList.state = "";
796  // Unsetting model to prevent showing changing entries during fading out
797  // that may happen because of triggering an action.
798  LauncherModel.quickListActionInvoked(quickList.appId, index);
799  quickList.focus = false;
800  root.kbdNavigationCancelled();
801  quickList.model = undefined;
802  }
803  }
804  }
805  }
806  }
807 }