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: itemHeight * 3
115 // The height of the area where icons start getting folded
116 property int foldingStartHeight: units.gu(6.5)
117 // The height of the area where the items reach the final folding angle
118 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
119 property int itemWidth: units.gu(7)
120 property int itemHeight: units.gu(6.5)
121 property int clickFlickSpeed: units.gu(60)
122 property int draggedIndex: dndArea.draggedIndex
123 property real realContentY: contentY - originY + topMargin
124 property int realItemHeight: itemHeight + spacing
126 // In case the start dragging transition is running, we need to delay the
127 // move because the displaced transition would clash with it and cause items
128 // to be moved to wrong places
129 property bool draggingTransitionRunning: false
130 property int scheduledMoveTo: -1
132 displaced: Transition {
133 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
136 delegate: FoldingLauncherDelegate {
138 objectName: "launcherDelegate" + index
139 itemHeight: launcherListView.itemHeight
140 itemWidth: launcherListView.itemWidth
145 progress: model.progress
146 inverted: root.inverted
149 property bool dragging: false
153 objectName: "dropIndicator"
154 anchors.centerIn: parent
155 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
162 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
164 target: launcherDelegate
172 target: launcherDelegate
177 target: dropIndicator
183 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
185 target: launcherDelegate
197 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
202 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
203 UbuntuNumberAnimation { properties: "angle,offset" }
208 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
209 UbuntuNumberAnimation { properties: "angle,offset" }
212 id: draggingTransition
215 SequentialAnimation {
216 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
218 UbuntuNumberAnimation { properties: "height" }
219 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
223 if (launcherListView.scheduledMoveTo > -1) {
224 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
225 dndArea.draggedIndex = launcherListView.scheduledMoveTo
226 launcherListView.scheduledMoveTo = -1
230 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
236 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
237 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
238 SequentialAnimation {
239 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
240 UbuntuNumberAnimation { properties: "height" }
241 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
242 PropertyAction { target: dndArea; property: "postDragging"; value: false }
243 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
251 objectName: "dndArea"
254 topMargin: launcherListView.topMargin
255 bottomMargin: launcherListView.bottomMargin
257 drag.minimumY: -launcherListView.topMargin
258 drag.maximumY: height + launcherListView.bottomMargin
260 property int draggedIndex: -1
261 property var selectedItem
262 property bool preDragging: false
263 property bool dragging: selectedItem !== undefined && selectedItem !== null && selectedItem.dragging
264 property bool postDragging: false
267 property var quickListPopover: null
270 selectedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
274 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
275 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
277 // Check if we actually clicked an item or only at the spacing in between
278 if (clickedItem === null) {
282 // First/last item do the scrolling at more than 12 degrees
283 if (index == 0 || index == launcherListView.count - 1) {
284 if (clickedItem.angle > 12) {
285 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
286 } else if (clickedItem.angle < -12) {
287 launcherListView.flick(0, launcherListView.clickFlickSpeed);
289 root.applicationSelected(LauncherModel.get(index).desktopFile);
294 // the rest launches apps up to an angle of 30 degrees
295 if (clickedItem.angle > 30) {
296 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
297 } else if (clickedItem.angle < -30) {
298 launcherListView.flick(0, launcherListView.clickFlickSpeed);
300 root.applicationSelected(LauncherModel.get(index).desktopFile);
305 selectedItem = undefined;
307 postDragging = false;
311 var droppedIndex = draggedIndex;
322 selectedItem.dragging = false;
323 selectedItem = undefined;
326 drag.target = undefined
328 progressiveScrollingTimer.stop();
329 launcherListView.interactive = true;
330 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
331 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
333 if (droppedIndex == 0 && postDragging) {
334 launcherListView.flick(0, launcherListView.clickFlickSpeed);
339 if (Math.abs(selectedItem.angle) > 30) {
343 draggedIndex = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
346 var quickListModel = launcherListView.model.get(draggedIndex).quickList
347 var quickListAppId = launcherListView.model.get(draggedIndex).appId
349 quickListPopover = PopupUtils.open(popoverComponent, selectedItem,
350 {model: quickListModel, appId: quickListAppId})
352 launcherListView.interactive = false
354 var yOffset = draggedIndex > 0 ? (mouseY + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouseY + launcherListView.realContentY
356 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
358 fakeDragItem.y = mouseY - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
359 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
360 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
361 fakeDragItem.count = LauncherModel.get(draggedIndex).count
362 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
363 fakeDragItem.flatten()
364 drag.target = fakeDragItem
371 if (draggedIndex >= 0) {
372 if (!selectedItem.dragging) {
373 var distance = Math.max(Math.abs(mouseX - startX), Math.abs(mouseY - startY))
374 if (!preDragging && distance > units.gu(1.5)) {
376 PopupUtils.close(quickListPopover)
378 if (distance > launcherListView.itemHeight) {
379 selectedItem.dragging = true
383 if (!selectedItem.dragging) {
387 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
389 // Move it down by the the missing size to compensate index calculation with only expanded items
390 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
392 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
393 progressiveScrollingTimer.downwards = false
394 progressiveScrollingTimer.start()
395 } else if (mouseY < launcherListView.realItemHeight) {
396 progressiveScrollingTimer.downwards = true
397 progressiveScrollingTimer.start()
399 progressiveScrollingTimer.stop()
402 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
404 if (newIndex > draggedIndex + 1) {
405 newIndex = draggedIndex + 1
406 } else if (newIndex < draggedIndex) {
407 newIndex = draggedIndex -1
412 if (newIndex >= 0 && newIndex < launcherListView.count) {
413 if (launcherListView.draggingTransitionRunning) {
414 launcherListView.scheduledMoveTo = newIndex
416 launcherListView.model.move(draggedIndex, newIndex)
417 draggedIndex = newIndex
424 id: progressiveScrollingTimer
428 property bool downwards: true
431 var minY = -launcherListView.topMargin
432 if (launcherListView.contentY > minY) {
433 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
436 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
437 if (launcherListView.contentY < maxY) {
438 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
448 objectName: "fakeDragItem"
449 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
450 itemWidth: launcherListView.itemWidth
451 itemHeight: launcherListView.itemHeight
454 rotation: root.rotation
458 fakeDragItemAnimation.start();
461 UbuntuNumberAnimation {
462 id: fakeDragItemAnimation
463 target: fakeDragItem;
464 properties: "angle,offset";
477 property string appId
478 contentWidth: quickListColumn.width
479 foregroundStyle: QuicklistForegroundStyle {}
481 // FIXME: There's a bug in the Popover positioning that it covers the item in case it is rotated.
482 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1204470
483 // For now, let's move the Popover around with callerMargin.
484 // Remove popupMargin once the bug is fixed.
485 property int popupMargin: root.inverted ? launcherListView.itemHeight : 0;
487 callerMargin: units.gu(1) + popupMargin
492 height: childrenRect.height
499 objectName: "quickListEntry" + index
500 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
501 highlightWhenPressed: model.clickable
503 if (!model.clickable) {
506 PopupUtils.close(popover);
507 // Unsetting model to prevent showing changing entries during fading out
508 // that may happen because of triggering an action.
509 LauncherModel.quickListActionInvoked(appId, index);
510 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