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