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
20import Unity.Launcher 0.1
21import Ubuntu.Components.Popups 0.1
22import "../Components/ListItems"
23import "../Components/"
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 || quickList.state === "open" || dndArea.pressed
35 property int highlightIndex: -1
37 signal applicationSelected(string appId)
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
59 onClicked: root.dashItemSelected(0)
62 objectName: "dashItem"
65 anchors.centerIn: parent
66 source: "graphics/home.png"
67 rotation: root.rotation
74 margins: -mainColumn.anchors.leftMargin
76 rotation: root.rotation
80 anchors.left: parent.left
81 anchors.right: parent.right
82 height: parent.height - dashItem.height - parent.spacing*2
90 objectName: "launcherListView"
93 topMargin: -extensionSize + units.gu(0.5)
94 bottomMargin: -extensionSize + units.gu(1)
95 leftMargin: units.gu(0.5)
96 rightMargin: units.gu(0.5)
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 itemFocused: model.focused
160 inverted: root.inverted
163 property bool dragging: false
167 objectName: "dropIndicator"
168 anchors.centerIn: parent
169 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
176 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
178 target: launcherDelegate
186 target: launcherDelegate
191 target: dropIndicator
197 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
199 target: launcherDelegate
211 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
216 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
217 UbuntuNumberAnimation { properties: "angle,offset" }
222 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
223 UbuntuNumberAnimation { properties: "angle,offset" }
226 id: draggingTransition
229 SequentialAnimation {
230 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
232 UbuntuNumberAnimation { properties: "height" }
233 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
237 if (launcherListView.scheduledMoveTo > -1) {
238 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
239 dndArea.draggedIndex = launcherListView.scheduledMoveTo
240 launcherListView.scheduledMoveTo = -1
244 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
250 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
251 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
252 SequentialAnimation {
253 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
254 UbuntuNumberAnimation { properties: "height" }
255 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
256 PropertyAction { target: dndArea; property: "postDragging"; value: false }
257 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
265 objectName: "dndArea"
268 topMargin: launcherListView.topMargin
269 bottomMargin: launcherListView.bottomMargin
271 drag.minimumY: -launcherListView.topMargin
272 drag.maximumY: height + launcherListView.bottomMargin
274 property int draggedIndex: -1
275 property var selectedItem
276 property bool preDragging: false
277 property bool dragging: selectedItem !== undefined && selectedItem !== null && selectedItem.dragging
278 property bool postDragging: false
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).appId);
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).appId);
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 quickList.item = selectedItem;
360 quickList.model = launcherListView.model.get(draggedIndex).quickList;
361 quickList.appId = launcherListView.model.get(draggedIndex).appId;
362 quickList.state = "open";
364 launcherListView.interactive = false
366 var yOffset = draggedIndex > 0 ? (mouseY + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouseY + launcherListView.realContentY
368 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
369 fakeDragItem.x = units.gu(0.5)
370 fakeDragItem.y = mouseY - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
371 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
372 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
373 fakeDragItem.count = LauncherModel.get(draggedIndex).count
374 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
375 fakeDragItem.flatten()
376 drag.target = fakeDragItem
383 if (draggedIndex >= 0) {
384 if (!selectedItem.dragging) {
385 var distance = Math.max(Math.abs(mouseX - startX), Math.abs(mouseY - startY))
386 if (!preDragging && distance > units.gu(1.5)) {
388 quickList.state = "";
390 if (distance > launcherListView.itemHeight) {
391 selectedItem.dragging = true
395 if (!selectedItem.dragging) {
399 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
401 // Move it down by the the missing size to compensate index calculation with only expanded items
402 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
404 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
405 progressiveScrollingTimer.downwards = false
406 progressiveScrollingTimer.start()
407 } else if (mouseY < launcherListView.realItemHeight) {
408 progressiveScrollingTimer.downwards = true
409 progressiveScrollingTimer.start()
411 progressiveScrollingTimer.stop()
414 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
416 if (newIndex > draggedIndex + 1) {
417 newIndex = draggedIndex + 1
418 } else if (newIndex < draggedIndex) {
419 newIndex = draggedIndex -1
424 if (newIndex >= 0 && newIndex < launcherListView.count) {
425 if (launcherListView.draggingTransitionRunning) {
426 launcherListView.scheduledMoveTo = newIndex
428 launcherListView.model.move(draggedIndex, newIndex)
429 draggedIndex = newIndex
436 id: progressiveScrollingTimer
440 property bool downwards: true
443 var minY = -launcherListView.topMargin
444 if (launcherListView.contentY > minY) {
445 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
448 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
449 if (launcherListView.contentY < maxY) {
450 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
460 objectName: "fakeDragItem"
461 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
462 itemWidth: launcherListView.itemWidth
463 itemHeight: launcherListView.itemHeight
466 rotation: root.rotation
470 fakeDragItemAnimation.start();
473 UbuntuNumberAnimation {
474 id: fakeDragItemAnimation
475 target: fakeDragItem;
476 properties: "angle,offset";
485 objectName: "quickListShape"
486 anchors.fill: quickList
487 opacity: quickList.state === "open" ? 0.8 : 0
489 rotation: root.rotation
491 Behavior on opacity {
492 UbuntuNumberAnimation {}
500 rightMargin: -units.dp(4)
501 verticalCenter: parent.verticalCenter
502 verticalCenterOffset: -quickList.offset
506 source: "graphics/quicklist_tooltip.png"
512 enabled: quickList.state == "open"
522 objectName: "quickList"
525 height: quickListColumn.height
527 left: root.inverted ? undefined : parent.right
528 right: root.inverted ? parent.left : undefined
532 y: itemCenter - (height / 2) + offset
533 rotation: root.rotation
536 property string appId
540 property int itemCenter: item ? root.mapFromItem(quickList.item).y + (item.height / 2) : units.gu(1)
541 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
542 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
547 height: childrenRect.height
551 model: quickList.model
554 objectName: "quickListEntry" + index
555 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
556 highlightWhenPressed: model.clickable
558 // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
559 // ListItems don't know that they are sitting in a themed Popover where the color
560 // needs to be inverted.
561 __foregroundColor: Theme.palette.selected.backgroundText
564 if (!model.clickable) {
567 quickList.state = "";
568 // Unsetting model to prevent showing changing entries during fading out
569 // that may happen because of triggering an action.
570 LauncherModel.quickListActionInvoked(quickList.appId, index);
571 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