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 1.2
19import Ubuntu.Components.ListItems 1.0 as ListItems
20import Unity.Launcher 0.1
21import Ubuntu.Components.Popups 0.1
22import "../Components/ListItems"
23import "../Components/"
29 rotation: inverted ? 180 : 0
32 property bool inverted: false
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)
42 if (quickList.state == "open") {
54 objectName: "buttonShowDashHome"
62 topMargin: -units.gu(2)
65 color: UbuntuColors.orange
69 objectName: "dashItem"
72 anchors.centerIn: parent
73 source: "graphics/home.png"
74 rotation: root.rotation
79 onClicked: root.showDashHome()
84 anchors.left: parent.left
85 anchors.right: parent.right
86 height: parent.height - dashItem.height - parent.spacing*2
89 id: launcherListViewItem
95 objectName: "launcherListView"
98 topMargin: -extensionSize + units.gu(0.5)
99 bottomMargin: -extensionSize + units.gu(1)
100 leftMargin: units.gu(0.5)
101 rightMargin: units.gu(0.5)
103 topMargin: extensionSize
104 bottomMargin: extensionSize
105 height: parent.height - dashItem.height - parent.spacing*2
107 cacheBuffer: itemHeight * 3
108 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
109 highlightRangeMode: ListView.ApplyRange
110 preferredHighlightBegin: (height - itemHeight) / 2
111 preferredHighlightEnd: (height + itemHeight) / 2
113 // for the single peeking icon, when alert-state is set on delegate
114 property int peekingIndex: -1
116 // The size of the area the ListView is extended to make sure items are not
117 // destroyed when dragging them outside the list. This needs to be at least
118 // itemHeight to prevent folded items from disappearing and DragArea limits
119 // need to be smaller than this size to avoid breakage.
120 property int extensionSize: 0
122 // Setting extensionSize after the list has been populated because it has
123 // the potential to mess up with the intial positioning in combination
124 // with snapping to the center of the list. This catches all the cases
125 // where the item would be outside the list for more than itemHeight / 2.
126 // For the rest, give it a flick to scroll to the beginning. Note that
127 // the flicking alone isn't enough because in some cases it's not strong
128 // enough to overcome the snapping.
129 // https://bugreports.qt-project.org/browse/QTBUG-32251
130 Component.onCompleted: {
131 extensionSize = itemHeight * 3
132 flick(0, clickFlickSpeed)
135 // The height of the area where icons start getting folded
136 property int foldingStartHeight: units.gu(6.5)
137 // The height of the area where the items reach the final folding angle
138 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
139 property int itemWidth: units.gu(7)
140 property int itemHeight: units.gu(6.5)
141 property int clickFlickSpeed: units.gu(60)
142 property int draggedIndex: dndArea.draggedIndex
143 property real realContentY: contentY - originY + topMargin
144 property int realItemHeight: itemHeight + spacing
146 // In case the start dragging transition is running, we need to delay the
147 // move because the displaced transition would clash with it and cause items
148 // to be moved to wrong places
149 property bool draggingTransitionRunning: false
150 property int scheduledMoveTo: -1
152 UbuntuNumberAnimation {
153 id: snapToBottomAnimation
154 target: launcherListView
156 to: launcherListView.originY + launcherListView.topMargin
159 UbuntuNumberAnimation {
160 id: snapToTopAnimation
161 target: launcherListView
163 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
166 UbuntuNumberAnimation {
168 target: launcherListView
170 function moveTo(contentY) {
171 from = launcherListView.contentY;
177 displaced: Transition {
178 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
181 delegate: FoldingLauncherDelegate {
183 objectName: "launcherDelegate" + index
184 // We need the appId in the delegate in order to find
185 // the right app when running autopilot tests for
187 readonly property string appId: model.appId
188 itemHeight: launcherListView.itemHeight
189 itemWidth: launcherListView.itemWidth
194 countVisible: model.countVisible
195 progress: model.progress
196 itemRunning: model.running
197 itemFocused: model.focused
198 inverted: root.inverted
199 alerting: model.alerting
202 property bool dragging: false
204 SequentialAnimation {
208 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
209 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
211 UbuntuNumberAnimation {
212 target: launcherDelegate
216 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
217 duration: UbuntuAnimation.BriskDuration
221 UbuntuNumberAnimation {
222 target: launcherDelegate
227 duration: UbuntuAnimation.BriskDuration
230 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
231 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
236 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
237 var itemPosition = index * launcherListView.itemHeight;
238 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
239 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : launcherListView.itemHeight
240 if (itemPosition + launcherListView.itemHeight + distanceToEnd > launcherListView.contentY + launcherListView.topMargin + height) {
241 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd);
242 } else if (itemPosition - distanceToEnd < launcherListView.contentY + launcherListView.topMargin) {
243 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin);
245 if (!dragging && launcher.state !== "visible") {
246 peekingAnimation.start()
250 if (launcherListView.peekingIndex === -1) {
251 launcherListView.peekingIndex = index
254 if (launcherListView.peekingIndex === index) {
255 launcherListView.peekingIndex = -1
262 objectName: "dropIndicator"
263 anchors.centerIn: parent
264 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
266 source: "graphics/divider-line.png"
272 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
274 target: launcherDelegate
282 target: launcherDelegate
287 target: dropIndicator
293 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
295 target: launcherDelegate
307 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
312 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
313 UbuntuNumberAnimation { properties: "angle,offset" }
318 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
319 UbuntuNumberAnimation { properties: "angle,offset" }
322 id: draggingTransition
325 SequentialAnimation {
326 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
328 UbuntuNumberAnimation { properties: "height" }
329 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
333 if (launcherListView.scheduledMoveTo > -1) {
334 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
335 dndArea.draggedIndex = launcherListView.scheduledMoveTo
336 launcherListView.scheduledMoveTo = -1
340 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
346 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
347 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
348 SequentialAnimation {
349 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
350 UbuntuNumberAnimation { properties: "height" }
351 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
352 PropertyAction { target: dndArea; property: "postDragging"; value: false }
353 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
361 objectName: "dndArea"
362 acceptedButtons: Qt.LeftButton | Qt.RightButton
365 topMargin: launcherListView.topMargin
366 bottomMargin: launcherListView.bottomMargin
368 drag.minimumY: -launcherListView.topMargin
369 drag.maximumY: height + launcherListView.bottomMargin
371 property int draggedIndex: -1
372 property var selectedItem
373 property bool preDragging: false
374 property bool dragging: !!selectedItem && selectedItem.dragging
375 property bool postDragging: false
380 selectedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
384 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
385 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
387 // Check if we actually clicked an item or only at the spacing in between
388 if (clickedItem === null) {
392 if (mouse.button & Qt.RightButton) { // context menu
394 quickList.item = clickedItem;
395 quickList.model = launcherListView.model.get(index).quickList;
396 quickList.appId = launcherListView.model.get(index).appId;
397 quickList.state = "open";
401 // First/last item do the scrolling at more than 12 degrees
402 if (index == 0 || index == launcherListView.count - 1) {
403 if (clickedItem.angle > 12) {
404 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
405 } else if (clickedItem.angle < -12) {
406 launcherListView.flick(0, launcherListView.clickFlickSpeed);
408 root.applicationSelected(LauncherModel.get(index).appId);
413 // the rest launches apps up to an angle of 30 degrees
414 if (clickedItem.angle > 30) {
415 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
416 } else if (clickedItem.angle < -30) {
417 launcherListView.flick(0, launcherListView.clickFlickSpeed);
419 root.applicationSelected(LauncherModel.get(index).appId);
432 var droppedIndex = draggedIndex;
443 selectedItem.dragging = false;
444 selectedItem = undefined;
447 drag.target = undefined
449 progressiveScrollingTimer.stop();
450 launcherListView.interactive = true;
451 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
452 snapToBottomAnimation.start();
453 } else if (droppedIndex < 2 && postDragging) {
454 snapToTopAnimation.start();
459 if (Math.abs(selectedItem.angle) > 30) {
463 draggedIndex = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
466 quickList.item = selectedItem;
467 quickList.model = launcherListView.model.get(draggedIndex).quickList;
468 quickList.appId = launcherListView.model.get(draggedIndex).appId;
469 quickList.state = "open";
471 launcherListView.interactive = false
473 var yOffset = draggedIndex > 0 ? (mouseY + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouseY + launcherListView.realContentY
475 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
476 fakeDragItem.x = units.gu(0.5)
477 fakeDragItem.y = mouseY - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
478 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
479 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
480 fakeDragItem.count = LauncherModel.get(draggedIndex).count
481 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
482 fakeDragItem.flatten()
483 drag.target = fakeDragItem
490 if (draggedIndex >= 0) {
491 if (!selectedItem.dragging) {
492 var distance = Math.max(Math.abs(mouseX - startX), Math.abs(mouseY - startY))
493 if (!preDragging && distance > units.gu(1.5)) {
495 quickList.state = "";
497 if (distance > launcherListView.itemHeight) {
498 selectedItem.dragging = true
502 if (!selectedItem.dragging) {
506 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
508 // Move it down by the the missing size to compensate index calculation with only expanded items
509 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
511 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
512 progressiveScrollingTimer.downwards = false
513 progressiveScrollingTimer.start()
514 } else if (mouseY < launcherListView.realItemHeight) {
515 progressiveScrollingTimer.downwards = true
516 progressiveScrollingTimer.start()
518 progressiveScrollingTimer.stop()
521 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
523 if (newIndex > draggedIndex + 1) {
524 newIndex = draggedIndex + 1
525 } else if (newIndex < draggedIndex) {
526 newIndex = draggedIndex -1
531 if (newIndex >= 0 && newIndex < launcherListView.count) {
532 if (launcherListView.draggingTransitionRunning) {
533 launcherListView.scheduledMoveTo = newIndex
535 launcherListView.model.move(draggedIndex, newIndex)
536 draggedIndex = newIndex
543 id: progressiveScrollingTimer
547 property bool downwards: true
550 var minY = -launcherListView.topMargin
551 if (launcherListView.contentY > minY) {
552 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
555 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
556 if (launcherListView.contentY < maxY) {
557 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
567 objectName: "fakeDragItem"
568 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
569 itemWidth: launcherListView.itemWidth
570 itemHeight: launcherListView.itemHeight
573 rotation: root.rotation
577 fakeDragItemAnimation.start();
580 UbuntuNumberAnimation {
581 id: fakeDragItemAnimation
582 target: fakeDragItem;
583 properties: "angle,offset";
592 objectName: "quickListShape"
593 anchors.fill: quickList
594 opacity: quickList.state === "open" ? 0.8 : 0
596 rotation: root.rotation
598 Behavior on opacity {
599 UbuntuNumberAnimation {}
607 rightMargin: -units.dp(4)
608 verticalCenter: parent.verticalCenter
609 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
613 source: "graphics/quicklist_tooltip.png"
619 enabled: quickList.state == "open"
629 objectName: "quickList"
631 // Because we're setting left/right anchors depending on orientation, it will break the
632 // width setting after rotating twice. This makes sure we also re-apply width on rotation
633 width: root.inverted ? units.gu(30) : units.gu(30)
634 height: quickListColumn.height
635 visible: quickListShape.visible
637 left: root.inverted ? undefined : parent.right
638 right: root.inverted ? parent.left : undefined
641 y: itemCenter - (height / 2) + offset
642 rotation: root.rotation
645 property string appId
649 property int itemCenter: item ? root.mapFromItem(quickList.item).y + (item.height / 2) : units.gu(1)
650 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
651 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
656 height: childrenRect.height
660 model: quickList.model
663 objectName: "quickListEntry" + index
664 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
665 highlightWhenPressed: model.clickable
667 // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
668 // ListItems don't know that they are sitting in a themed Popover where the color
669 // needs to be inverted.
670 __foregroundColor: "black"
673 if (!model.clickable) {
676 quickList.state = "";
677 // Unsetting model to prevent showing changing entries during fading out
678 // that may happen because of triggering an action.
679 LauncherModel.quickListActionInvoked(quickList.appId, index);
680 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