2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18import Ubuntu.Components 0.1
19import Ubuntu.Components.ListItems 0.1 as ListItems
21import Unity.Launcher 0.1
22import Ubuntu.Components.Popups 0.1
23import "../Components/ListItems"
28 rotation: inverted ? 180 : 0
31 property bool inverted: true
32 property bool dragging: false
33 property bool moving: launcherListView.moving || launcherListView.flicking
34 property bool preventHiding: moving || dndArea.draggedIndex >= 0 || dndArea.quickListPopover !== null || dndArea.pressed
35 property int highlightIndex: -1
37 signal applicationSelected(string desktopFile)
38 signal dashItemSelected(int index)
42 source: "graphics/launcher_bg.sci"
44 anchors.rightMargin: root.inverted ? 0 : -units.gu(1)
45 anchors.leftMargin: root.inverted ? -units.gu(1) : 0
46 rotation: root.rotation
53 leftMargin: units.gu(0.5)
54 rightMargin: units.gu(0.5)
61 onClicked: root.dashItemSelected(0)
64 objectName: "dashItem"
67 anchors.centerIn: parent
68 source: "graphics/home.png"
69 rotation: root.rotation
76 margins: -mainColumn.anchors.leftMargin
78 rotation: root.rotation
82 anchors.left: parent.left
83 anchors.right: parent.right
84 height: parent.height - dashItem.height - parent.spacing*2
92 objectName: "launcherListView"
95 topMargin: -extensionSize + units.gu(0.5)
96 bottomMargin: -extensionSize + units.gu(1)
98 topMargin: extensionSize
99 bottomMargin: extensionSize
100 height: parent.height - dashItem.height - parent.spacing*2
102 cacheBuffer: itemHeight * 3
103 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
104 highlightRangeMode: ListView.ApplyRange
105 preferredHighlightBegin: (height - itemHeight) / 2
106 preferredHighlightEnd: (height + itemHeight) / 2
107 spacing: units.gu(0.5)
109 // The size of the area the ListView is extended to make sure items are not
110 // destroyed when dragging them outside the list. This needs to be at least
111 // itemHeight to prevent folded items from disappearing and DragArea limits
112 // need to be smaller than this size to avoid breakage.
113 property int extensionSize: 0
115 // Setting extensionSize after the list has been populated because it has
116 // the potential to mess up with the intial positioning in combination
117 // with snapping to the center of the list. This catches all the cases
118 // where the item would be outside the list for more than itemHeight / 2.
119 // For the rest, give it a flick to scroll to the beginning. Note that
120 // the flicking alone isn't enough because in some cases it's not strong
121 // enough to overcome the snapping.
122 // https://bugreports.qt-project.org/browse/QTBUG-32251
123 Component.onCompleted: {
124 extensionSize = itemHeight * 3
125 flick(0, clickFlickSpeed)
128 // The height of the area where icons start getting folded
129 property int foldingStartHeight: units.gu(6.5)
130 // The height of the area where the items reach the final folding angle
131 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
132 property int itemWidth: units.gu(7)
133 property int itemHeight: units.gu(6.5)
134 property int clickFlickSpeed: units.gu(60)
135 property int draggedIndex: dndArea.draggedIndex
136 property real realContentY: contentY - originY + topMargin
137 property int realItemHeight: itemHeight + spacing
139 // In case the start dragging transition is running, we need to delay the
140 // move because the displaced transition would clash with it and cause items
141 // to be moved to wrong places
142 property bool draggingTransitionRunning: false
143 property int scheduledMoveTo: -1
145 displaced: Transition {
146 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
149 delegate: FoldingLauncherDelegate {
151 objectName: "launcherDelegate" + index
152 itemHeight: launcherListView.itemHeight
153 itemWidth: launcherListView.itemWidth
158 progress: model.progress
159 inverted: root.inverted
162 property bool dragging: false
166 objectName: "dropIndicator"
167 anchors.centerIn: parent
168 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
175 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
177 target: launcherDelegate
185 target: launcherDelegate
190 target: dropIndicator
196 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
198 target: launcherDelegate
210 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
215 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
216 UbuntuNumberAnimation { properties: "angle,offset" }
221 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
222 UbuntuNumberAnimation { properties: "angle,offset" }
225 id: draggingTransition
228 SequentialAnimation {
229 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
231 UbuntuNumberAnimation { properties: "height" }
232 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
236 if (launcherListView.scheduledMoveTo > -1) {
237 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
238 dndArea.draggedIndex = launcherListView.scheduledMoveTo
239 launcherListView.scheduledMoveTo = -1
243 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
249 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
250 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
251 SequentialAnimation {
252 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
253 UbuntuNumberAnimation { properties: "height" }
254 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
255 PropertyAction { target: dndArea; property: "postDragging"; value: false }
256 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
264 objectName: "dndArea"
267 topMargin: launcherListView.topMargin
268 bottomMargin: launcherListView.bottomMargin
270 drag.minimumY: -launcherListView.topMargin
271 drag.maximumY: height + launcherListView.bottomMargin
273 property int draggedIndex: -1
274 property var selectedItem
275 property bool preDragging: false
276 property bool dragging: selectedItem !== undefined && selectedItem !== null && selectedItem.dragging
277 property bool postDragging: false
280 property var quickListPopover: null
283 selectedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
287 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
288 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
290 // Check if we actually clicked an item or only at the spacing in between
291 if (clickedItem === null) {
295 // First/last item do the scrolling at more than 12 degrees
296 if (index == 0 || index == launcherListView.count - 1) {
297 if (clickedItem.angle > 12) {
298 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
299 } else if (clickedItem.angle < -12) {
300 launcherListView.flick(0, launcherListView.clickFlickSpeed);
302 root.applicationSelected(LauncherModel.get(index).desktopFile);
307 // the rest launches apps up to an angle of 30 degrees
308 if (clickedItem.angle > 30) {
309 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
310 } else if (clickedItem.angle < -30) {
311 launcherListView.flick(0, launcherListView.clickFlickSpeed);
313 root.applicationSelected(LauncherModel.get(index).desktopFile);
318 selectedItem = undefined;
320 postDragging = false;
324 var droppedIndex = draggedIndex;
335 selectedItem.dragging = false;
336 selectedItem = undefined;
339 drag.target = undefined
341 progressiveScrollingTimer.stop();
342 launcherListView.interactive = true;
343 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
344 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
346 if (droppedIndex == 0 && postDragging) {
347 launcherListView.flick(0, launcherListView.clickFlickSpeed);
352 if (Math.abs(selectedItem.angle) > 30) {
356 draggedIndex = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
359 var quickListModel = launcherListView.model.get(draggedIndex).quickList
360 var quickListAppId = launcherListView.model.get(draggedIndex).appId
362 quickListPopover = PopupUtils.open(popoverComponent, selectedItem,
363 {model: quickListModel, appId: quickListAppId})
365 launcherListView.interactive = false
367 var yOffset = draggedIndex > 0 ? (mouseY + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouseY + launcherListView.realContentY
369 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
371 fakeDragItem.y = mouseY - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
372 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
373 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
374 fakeDragItem.count = LauncherModel.get(draggedIndex).count
375 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
376 fakeDragItem.flatten()
377 drag.target = fakeDragItem
384 if (draggedIndex >= 0) {
385 if (!selectedItem.dragging) {
386 var distance = Math.max(Math.abs(mouseX - startX), Math.abs(mouseY - startY))
387 if (!preDragging && distance > units.gu(1.5)) {
389 PopupUtils.close(quickListPopover)
391 if (distance > launcherListView.itemHeight) {
392 selectedItem.dragging = true
396 if (!selectedItem.dragging) {
400 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
402 // Move it down by the the missing size to compensate index calculation with only expanded items
403 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
405 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
406 progressiveScrollingTimer.downwards = false
407 progressiveScrollingTimer.start()
408 } else if (mouseY < launcherListView.realItemHeight) {
409 progressiveScrollingTimer.downwards = true
410 progressiveScrollingTimer.start()
412 progressiveScrollingTimer.stop()
415 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
417 if (newIndex > draggedIndex + 1) {
418 newIndex = draggedIndex + 1
419 } else if (newIndex < draggedIndex) {
420 newIndex = draggedIndex -1
425 if (newIndex >= 0 && newIndex < launcherListView.count) {
426 if (launcherListView.draggingTransitionRunning) {
427 launcherListView.scheduledMoveTo = newIndex
429 launcherListView.model.move(draggedIndex, newIndex)
430 draggedIndex = newIndex
437 id: progressiveScrollingTimer
441 property bool downwards: true
444 var minY = -launcherListView.topMargin
445 if (launcherListView.contentY > minY) {
446 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
449 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
450 if (launcherListView.contentY < maxY) {
451 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
461 objectName: "fakeDragItem"
462 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
463 itemWidth: launcherListView.itemWidth
464 itemHeight: launcherListView.itemHeight
467 rotation: root.rotation
471 fakeDragItemAnimation.start();
474 UbuntuNumberAnimation {
475 id: fakeDragItemAnimation
476 target: fakeDragItem;
477 properties: "angle,offset";
490 property string appId
491 contentWidth: quickListColumn.width
492 foregroundStyle: QuicklistForegroundStyle {}
494 // FIXME: There's a bug in the Popover positioning that it covers the item in case it is rotated.
495 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1204470
496 // For now, let's move the Popover around with callerMargin.
497 // Remove popupMargin once the bug is fixed.
498 property int popupMargin: root.inverted ? launcherListView.itemHeight : 0;
500 callerMargin: units.gu(1) + popupMargin
505 height: childrenRect.height
512 objectName: "quickListEntry" + index
513 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
514 highlightWhenPressed: model.clickable
516 // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
517 // ListItems don't know that they are sitting in a themed Popover where the color
518 // needs to be inverted.
519 __foregroundColor: Theme.palette.selected.backgroundText
522 if (!model.clickable) {
525 PopupUtils.close(popover);
526 // Unsetting model to prevent showing changing entries during fading out
527 // that may happen because of triggering an action.
528 LauncherModel.quickListActionInvoked(appId, index);
529 popoverRepeater.model = undefined;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list