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"
24import "../Components/"
29 rotation: inverted ? 180 : 0
32 property bool inverted: true
33 property bool dragging: false
34 property bool moving: launcherListView.moving || launcherListView.flicking
35 property bool preventHiding: moving || dndArea.draggedIndex >= 0 || quickList.state === "open" || dndArea.pressed
36 property int highlightIndex: -1
38 signal applicationSelected(string appId)
39 signal dashItemSelected(int index)
43 source: "graphics/launcher_bg.sci"
45 anchors.rightMargin: root.inverted ? 0 : -units.gu(1)
46 anchors.leftMargin: root.inverted ? -units.gu(1) : 0
47 rotation: root.rotation
60 onClicked: root.dashItemSelected(0)
63 objectName: "dashItem"
66 anchors.centerIn: parent
67 source: "graphics/home.png"
68 rotation: root.rotation
75 margins: -mainColumn.anchors.leftMargin
77 rotation: root.rotation
81 anchors.left: parent.left
82 anchors.right: parent.right
83 height: parent.height - dashItem.height - parent.spacing*2
91 objectName: "launcherListView"
94 topMargin: -extensionSize + units.gu(0.5)
95 bottomMargin: -extensionSize + units.gu(1)
96 leftMargin: units.gu(0.5)
97 rightMargin: units.gu(0.5)
99 topMargin: extensionSize
100 bottomMargin: extensionSize
101 height: parent.height - dashItem.height - parent.spacing*2
103 cacheBuffer: itemHeight * 3
104 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
105 highlightRangeMode: ListView.ApplyRange
106 preferredHighlightBegin: (height - itemHeight) / 2
107 preferredHighlightEnd: (height + itemHeight) / 2
108 spacing: units.gu(0.5)
110 // The size of the area the ListView is extended to make sure items are not
111 // destroyed when dragging them outside the list. This needs to be at least
112 // itemHeight to prevent folded items from disappearing and DragArea limits
113 // need to be smaller than this size to avoid breakage.
114 property int extensionSize: 0
116 // Setting extensionSize after the list has been populated because it has
117 // the potential to mess up with the intial positioning in combination
118 // with snapping to the center of the list. This catches all the cases
119 // where the item would be outside the list for more than itemHeight / 2.
120 // For the rest, give it a flick to scroll to the beginning. Note that
121 // the flicking alone isn't enough because in some cases it's not strong
122 // enough to overcome the snapping.
123 // https://bugreports.qt-project.org/browse/QTBUG-32251
124 Component.onCompleted: {
125 extensionSize = itemHeight * 3
126 flick(0, clickFlickSpeed)
129 // The height of the area where icons start getting folded
130 property int foldingStartHeight: units.gu(6.5)
131 // The height of the area where the items reach the final folding angle
132 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
133 property int itemWidth: units.gu(7)
134 property int itemHeight: units.gu(6.5)
135 property int clickFlickSpeed: units.gu(60)
136 property int draggedIndex: dndArea.draggedIndex
137 property real realContentY: contentY - originY + topMargin
138 property int realItemHeight: itemHeight + spacing
140 // In case the start dragging transition is running, we need to delay the
141 // move because the displaced transition would clash with it and cause items
142 // to be moved to wrong places
143 property bool draggingTransitionRunning: false
144 property int scheduledMoveTo: -1
146 displaced: Transition {
147 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
150 delegate: FoldingLauncherDelegate {
152 objectName: "launcherDelegate" + index
153 itemHeight: launcherListView.itemHeight
154 itemWidth: launcherListView.itemWidth
159 progress: model.progress
160 itemFocused: model.focused
161 inverted: root.inverted
164 property bool dragging: false
168 objectName: "dropIndicator"
169 anchors.centerIn: parent
170 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
177 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
179 target: launcherDelegate
187 target: launcherDelegate
192 target: dropIndicator
198 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
200 target: launcherDelegate
212 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
217 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
218 UbuntuNumberAnimation { properties: "angle,offset" }
223 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
224 UbuntuNumberAnimation { properties: "angle,offset" }
227 id: draggingTransition
230 SequentialAnimation {
231 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
233 UbuntuNumberAnimation { properties: "height" }
234 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
238 if (launcherListView.scheduledMoveTo > -1) {
239 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
240 dndArea.draggedIndex = launcherListView.scheduledMoveTo
241 launcherListView.scheduledMoveTo = -1
245 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
251 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
252 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
253 SequentialAnimation {
254 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
255 UbuntuNumberAnimation { properties: "height" }
256 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
257 PropertyAction { target: dndArea; property: "postDragging"; value: false }
258 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
266 objectName: "dndArea"
269 topMargin: launcherListView.topMargin
270 bottomMargin: launcherListView.bottomMargin
272 drag.minimumY: -launcherListView.topMargin
273 drag.maximumY: height + launcherListView.bottomMargin
275 property int draggedIndex: -1
276 property var selectedItem
277 property bool preDragging: false
278 property bool dragging: selectedItem !== undefined && selectedItem !== null && selectedItem.dragging
279 property bool postDragging: false
284 selectedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
288 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
289 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
291 // Check if we actually clicked an item or only at the spacing in between
292 if (clickedItem === null) {
296 // First/last item do the scrolling at more than 12 degrees
297 if (index == 0 || index == launcherListView.count - 1) {
298 if (clickedItem.angle > 12) {
299 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
300 } else if (clickedItem.angle < -12) {
301 launcherListView.flick(0, launcherListView.clickFlickSpeed);
303 root.applicationSelected(LauncherModel.get(index).appId);
308 // the rest launches apps up to an angle of 30 degrees
309 if (clickedItem.angle > 30) {
310 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
311 } else if (clickedItem.angle < -30) {
312 launcherListView.flick(0, launcherListView.clickFlickSpeed);
314 root.applicationSelected(LauncherModel.get(index).appId);
319 selectedItem = undefined;
321 postDragging = false;
325 var droppedIndex = draggedIndex;
336 selectedItem.dragging = false;
337 selectedItem = undefined;
340 drag.target = undefined
342 progressiveScrollingTimer.stop();
343 launcherListView.interactive = true;
344 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
345 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
347 if (droppedIndex == 0 && postDragging) {
348 launcherListView.flick(0, launcherListView.clickFlickSpeed);
353 if (Math.abs(selectedItem.angle) > 30) {
357 draggedIndex = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
360 quickList.item = selectedItem;
361 quickList.model = launcherListView.model.get(draggedIndex).quickList;
362 quickList.appId = launcherListView.model.get(draggedIndex).appId;
363 quickList.state = "open";
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 quickList.state = "";
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";
486 objectName: "quickListShape"
487 anchors.fill: quickList
488 opacity: quickList.state === "open" ? 0.8 : 0
490 rotation: root.rotation
492 Behavior on opacity {
493 UbuntuNumberAnimation {}
501 rightMargin: -units.dp(4)
502 verticalCenter: parent.verticalCenter
503 verticalCenterOffset: -quickList.offset
507 source: "graphics/quicklist_tooltip.png"
513 enabled: quickList.state == "open"
523 objectName: "quickList"
526 height: quickListColumn.height
528 left: root.inverted ? undefined : parent.right
529 right: root.inverted ? parent.left : undefined
533 y: itemCenter - (height / 2) + offset
534 rotation: root.rotation
537 property string appId
541 property int itemCenter: item ? root.mapFromItem(quickList.item).y + (item.height / 2) : units.gu(1)
542 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
543 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
548 height: childrenRect.height
552 model: quickList.model
555 objectName: "quickListEntry" + index
556 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
557 highlightWhenPressed: model.clickable
559 // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
560 // ListItems don't know that they are sitting in a themed Popover where the color
561 // needs to be inverted.
562 __foregroundColor: Theme.palette.selected.backgroundText
565 if (!model.clickable) {
568 quickList.state = "";
569 // Unsetting model to prevent showing changing entries during fading out
570 // that may happen because of triggering an action.
571 LauncherModel.quickListActionInvoked(quickList.appId, index);
572 quickList.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