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 foldingAreaHeight: itemHeight * 0.75
117 property int itemWidth: width
118 property int itemHeight: width * 7.5 / 8
119 property int clickFlickSpeed: units.gu(60)
120 property int draggedIndex: dndArea.draggedIndex
121 property real realContentY: contentY - originY + topMargin
122 property int realItemHeight: itemHeight + spacing
124 displaced: Transition {
125 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
128 delegate: FoldingLauncherDelegate {
130 objectName: "launcherDelegate" + index
131 itemHeight: launcherListView.itemHeight
132 itemWidth: launcherListView.itemWidth
137 progress: model.progress
138 inverted: root.inverted
139 highlighted: dragging && index === root.highlightIndex
142 property bool dragging: false
146 objectName: "dropIndicator"
147 anchors.centerIn: parent
148 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
155 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
157 target: launcherDelegate
165 target: launcherDelegate
170 target: dropIndicator
176 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
178 target: launcherDelegate
190 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
195 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
196 UbuntuNumberAnimation { properties: "angle,offset" }
201 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
202 UbuntuNumberAnimation { properties: "angle,offset" }
207 UbuntuNumberAnimation { properties: "height" }
208 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
213 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
214 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
215 SequentialAnimation {
216 UbuntuNumberAnimation { properties: "height" }
217 PropertyAction { target: dndArea; property: "postDragging"; value: false }
218 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
226 objectName: "dndArea"
229 topMargin: launcherListView.topMargin
230 bottomMargin: launcherListView.bottomMargin
232 drag.minimumY: -launcherListView.topMargin
233 drag.maximumY: height + launcherListView.bottomMargin
235 property int draggedIndex: -1
236 property var selectedItem
237 property bool preDragging: false
238 property bool dragging: selectedItem !== undefined && selectedItem.dragging
239 property bool postDragging: false
242 property var quickListPopover: null
245 selectedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
246 selectedItem.highlighted = true
250 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
251 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
253 // First/last item do the scrolling at more than 12 degrees
254 if (index == 0 || index == launcherListView.count - 1) {
255 if (clickedItem.angle > 12) {
256 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
257 } else if (clickedItem.angle < -12) {
258 launcherListView.flick(0, launcherListView.clickFlickSpeed);
260 root.applicationSelected(LauncherModel.get(index).desktopFile);
265 // the rest launches apps up to an angle of 30 degrees
266 if (clickedItem.angle > 30) {
267 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
268 } else if (clickedItem.angle < -30) {
269 launcherListView.flick(0, launcherListView.clickFlickSpeed);
271 root.applicationSelected(LauncherModel.get(index).desktopFile);
276 selectedItem.highlighted = false
277 selectedItem = undefined;
279 postDragging = false;
283 var droppedIndex = draggedIndex;
290 selectedItem.highlighted = false
291 selectedItem.dragging = false;
292 selectedItem = undefined;
295 drag.target = undefined
297 progressiveScrollingTimer.stop();
298 launcherListView.interactive = true;
299 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
300 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
305 if (Math.abs(selectedItem.angle) > 30) {
309 draggedIndex = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
312 var quickListModel = launcherListView.model.get(draggedIndex).quickList
313 var quickListAppId = launcherListView.model.get(draggedIndex).appId
315 quickListPopover = PopupUtils.open(popoverComponent, selectedItem,
316 {model: quickListModel, appId: quickListAppId})
318 launcherListView.interactive = false
320 var yOffset = draggedIndex > 0 ? (mouseY + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouseY + launcherListView.realContentY
322 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
324 fakeDragItem.y = mouseY - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
325 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
326 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
327 fakeDragItem.count = LauncherModel.get(draggedIndex).count
328 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
329 fakeDragItem.flatten()
330 drag.target = fakeDragItem
337 if (draggedIndex >= 0) {
338 if (!selectedItem.dragging) {
339 var distance = Math.max(Math.abs(mouseX - startX), Math.abs(mouseY - startY))
340 if (!preDragging && distance > units.gu(1.5)) {
342 PopupUtils.close(quickListPopover)
344 if (distance > launcherListView.itemHeight) {
345 selectedItem.dragging = true
349 if (!selectedItem.dragging) {
353 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
355 // Move it down by the the missing size to compensate index calculation with only expanded items
356 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
358 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
359 progressiveScrollingTimer.downwards = false
360 progressiveScrollingTimer.start()
361 } else if (mouseY < launcherListView.realItemHeight) {
362 progressiveScrollingTimer.downwards = true
363 progressiveScrollingTimer.start()
365 progressiveScrollingTimer.stop()
368 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
370 if (newIndex > draggedIndex + 1) {
371 newIndex = draggedIndex + 1
372 } else if (newIndex < draggedIndex) {
373 newIndex = draggedIndex -1
378 if (newIndex >= 0 && newIndex < launcherListView.count) {
379 launcherListView.model.move(draggedIndex, newIndex)
380 draggedIndex = newIndex
386 id: progressiveScrollingTimer
390 property bool downwards: true
393 var minY = -launcherListView.topMargin
394 if (launcherListView.contentY > minY) {
395 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
398 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
399 if (launcherListView.contentY < maxY) {
400 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
410 objectName: "fakeDragItem"
411 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
412 itemWidth: launcherListView.itemWidth
413 itemHeight: launcherListView.itemHeight
416 rotation: root.rotation
421 fakeDragItemAnimation.start();
424 UbuntuNumberAnimation {
425 id: fakeDragItemAnimation
426 target: fakeDragItem;
427 properties: "angle,offset";
440 property string appId
441 contentWidth: quickListColumn.width
443 // FIXME: There's a bug in the Popover positioning that it covers the item in case it is rotated.
444 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1204470
445 // For now, let's move the Popover around with callerMargin.
446 // Remove popupMargin once the bug is fixed.
447 property int popupMargin: root.inverted ? launcherListView.itemHeight : 0;
449 callerMargin: units.gu(1) + popupMargin
454 height: childrenRect.height
460 objectName: "quickListEntry" + index
461 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
462 highlightWhenPressed: model.clickable
464 if (!model.clickable) {
467 LauncherModel.quickListActionInvoked(appId, index);
468 PopupUtils.close(popover);
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