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.3
19import Ubuntu.Components.ListItems 1.3 as ListItems
20import Unity.Launcher 0.1
21import Ubuntu.Components.Popups 1.3
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 || mouseEventEater.containsMouse || dashItem.hovered
37 property int highlightIndex: -1
39 signal applicationSelected(string appId)
43 if (quickList.state == "open") {
61 objectName: "buttonShowDashHome"
69 topMargin: -units.gu(2)
71 aspect: UbuntuShape.Flat
72 backgroundColor: UbuntuColors.orange
76 objectName: "dashItem"
79 anchors.centerIn: parent
80 source: "graphics/home.png"
81 rotation: root.rotation
86 onClicked: root.showDashHome()
91 anchors.left: parent.left
92 anchors.right: parent.right
93 height: parent.height - dashItem.height - parent.spacing*2
96 id: launcherListViewItem
102 objectName: "launcherListView"
105 topMargin: -extensionSize + units.gu(0.5)
106 bottomMargin: -extensionSize + units.gu(1)
107 leftMargin: units.gu(0.5)
108 rightMargin: units.gu(0.5)
110 topMargin: extensionSize
111 bottomMargin: extensionSize
112 height: parent.height - dashItem.height - parent.spacing*2
114 cacheBuffer: itemHeight * 3
115 snapMode: interactive ? ListView.SnapToItem : ListView.NoSnap
116 highlightRangeMode: ListView.ApplyRange
117 preferredHighlightBegin: (height - itemHeight) / 2
118 preferredHighlightEnd: (height + itemHeight) / 2
120 // for the single peeking icon, when alert-state is set on delegate
121 property int peekingIndex: -1
123 // The size of the area the ListView is extended to make sure items are not
124 // destroyed when dragging them outside the list. This needs to be at least
125 // itemHeight to prevent folded items from disappearing and DragArea limits
126 // need to be smaller than this size to avoid breakage.
127 property int extensionSize: 0
129 // Setting extensionSize after the list has been populated because it has
130 // the potential to mess up with the intial positioning in combination
131 // with snapping to the center of the list. This catches all the cases
132 // where the item would be outside the list for more than itemHeight / 2.
133 // For the rest, give it a flick to scroll to the beginning. Note that
134 // the flicking alone isn't enough because in some cases it's not strong
135 // enough to overcome the snapping.
136 // https://bugreports.qt-project.org/browse/QTBUG-32251
137 Component.onCompleted: {
138 extensionSize = itemHeight * 3
139 flick(0, clickFlickSpeed)
142 // The height of the area where icons start getting folded
143 property int foldingStartHeight: units.gu(6.5)
144 // The height of the area where the items reach the final folding angle
145 property int foldingStopHeight: foldingStartHeight - itemHeight - spacing
146 property int itemWidth: units.gu(7)
147 property int itemHeight: units.gu(6.5)
148 property int clickFlickSpeed: units.gu(60)
149 property int draggedIndex: dndArea.draggedIndex
150 property real realContentY: contentY - originY + topMargin
151 property int realItemHeight: itemHeight + spacing
153 // In case the start dragging transition is running, we need to delay the
154 // move because the displaced transition would clash with it and cause items
155 // to be moved to wrong places
156 property bool draggingTransitionRunning: false
157 property int scheduledMoveTo: -1
159 UbuntuNumberAnimation {
160 id: snapToBottomAnimation
161 target: launcherListView
163 to: launcherListView.originY + launcherListView.topMargin
166 UbuntuNumberAnimation {
167 id: snapToTopAnimation
168 target: launcherListView
170 to: launcherListView.contentHeight - launcherListView.height + launcherListView.originY - launcherListView.topMargin
173 UbuntuNumberAnimation {
175 target: launcherListView
177 function moveTo(contentY) {
178 from = launcherListView.contentY;
184 displaced: Transition {
185 NumberAnimation { properties: "x,y"; duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
188 delegate: FoldingLauncherDelegate {
190 objectName: "launcherDelegate" + index
191 // We need the appId in the delegate in order to find
192 // the right app when running autopilot tests for
194 readonly property string appId: model.appId
195 itemHeight: launcherListView.itemHeight
196 itemWidth: launcherListView.itemWidth
201 countVisible: model.countVisible
202 progress: model.progress
203 itemRunning: model.running
204 itemFocused: model.focused
205 inverted: root.inverted
206 alerting: model.alerting
209 property bool dragging: false
211 SequentialAnimation {
215 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
216 PropertyAction { target: launcherListViewItem; property: "clip"; value: 0 }
218 UbuntuNumberAnimation {
219 target: launcherDelegate
223 to: (units.gu(.5) + launcherListView.width * .5) * (root.inverted ? -1 : 1)
224 duration: UbuntuAnimation.BriskDuration
228 UbuntuNumberAnimation {
229 target: launcherDelegate
234 duration: UbuntuAnimation.BriskDuration
237 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
238 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
243 if (!dragging && (launcherListView.peekingIndex === -1 || launcher.visibleWidth > 0)) {
244 var itemPosition = index * launcherListView.itemHeight;
245 var height = launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin
246 var distanceToEnd = index == 0 || index == launcherListView.count - 1 ? 0 : launcherListView.itemHeight
247 if (itemPosition + launcherListView.itemHeight + distanceToEnd > launcherListView.contentY + launcherListView.topMargin + height) {
248 moveAnimation.moveTo(itemPosition + launcherListView.itemHeight - launcherListView.topMargin - height + distanceToEnd);
249 } else if (itemPosition - distanceToEnd < launcherListView.contentY + launcherListView.topMargin) {
250 moveAnimation.moveTo(itemPosition - distanceToEnd - launcherListView.topMargin);
252 if (!dragging && launcher.state !== "visible") {
253 peekingAnimation.start()
257 if (launcherListView.peekingIndex === -1) {
258 launcherListView.peekingIndex = index
261 if (launcherListView.peekingIndex === index) {
262 launcherListView.peekingIndex = -1
269 objectName: "dropIndicator"
270 anchors.centerIn: parent
271 width: parent.width + mainColumn.anchors.leftMargin + mainColumn.anchors.rightMargin
273 source: "graphics/divider-line.png"
279 when: dndArea.selectedItem === launcherDelegate && fakeDragItem.visible && !dragging
281 target: launcherDelegate
289 target: launcherDelegate
294 target: dropIndicator
300 when: dndArea.draggedIndex >= 0 && (dndArea.preDragging || dndArea.dragging || dndArea.postDragging) && dndArea.draggedIndex != index
302 target: launcherDelegate
314 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
319 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.FastDuration }
320 UbuntuNumberAnimation { properties: "angle,offset" }
325 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
326 UbuntuNumberAnimation { properties: "angle,offset" }
329 id: draggingTransition
332 SequentialAnimation {
333 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: true }
335 UbuntuNumberAnimation { properties: "height" }
336 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.FastDuration }
340 if (launcherListView.scheduledMoveTo > -1) {
341 launcherListView.model.move(dndArea.draggedIndex, launcherListView.scheduledMoveTo)
342 dndArea.draggedIndex = launcherListView.scheduledMoveTo
343 launcherListView.scheduledMoveTo = -1
347 PropertyAction { target: launcherListView; property: "draggingTransitionRunning"; value: false }
353 NumberAnimation { target: dropIndicator; properties: "opacity"; duration: UbuntuAnimation.SnapDuration }
354 NumberAnimation { properties: "itemOpacity"; duration: UbuntuAnimation.BriskDuration }
355 SequentialAnimation {
356 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
357 UbuntuNumberAnimation { properties: "height" }
358 ScriptAction { script: if (index == launcherListView.count-1) launcherListView.flick(0, -launcherListView.clickFlickSpeed); }
359 PropertyAction { target: dndArea; property: "postDragging"; value: false }
360 PropertyAction { target: dndArea; property: "draggedIndex"; value: -1 }
368 objectName: "dndArea"
369 acceptedButtons: Qt.LeftButton | Qt.RightButton
372 topMargin: launcherListView.topMargin
373 bottomMargin: launcherListView.bottomMargin
375 drag.minimumY: -launcherListView.topMargin
376 drag.maximumY: height + launcherListView.bottomMargin
378 property int draggedIndex: -1
379 property var selectedItem
380 property bool preDragging: false
381 property bool dragging: !!selectedItem && selectedItem.dragging
382 property bool postDragging: false
390 function processPress(mouse) {
391 selectedItem = launcherListView.itemAt(mouse.x, mouse.y + launcherListView.realContentY)
396 var index = Math.floor((mouseY + launcherListView.realContentY) / launcherListView.realItemHeight);
397 var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
399 // Check if we actually clicked an item or only at the spacing in between
400 if (clickedItem === null) {
404 if (mouse.button & Qt.RightButton) { // context menu
406 quickList.item = clickedItem;
407 quickList.model = launcherListView.model.get(index).quickList;
408 quickList.appId = launcherListView.model.get(index).appId;
409 quickList.state = "open";
413 // First/last item do the scrolling at more than 12 degrees
414 if (index == 0 || index == launcherListView.count - 1) {
415 if (clickedItem.angle > 12) {
416 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
417 } else if (clickedItem.angle < -12) {
418 launcherListView.flick(0, launcherListView.clickFlickSpeed);
420 root.applicationSelected(LauncherModel.get(index).appId);
425 // the rest launches apps up to an angle of 30 degrees
426 if (clickedItem.angle > 30) {
427 launcherListView.flick(0, -launcherListView.clickFlickSpeed);
428 } else if (clickedItem.angle < -30) {
429 launcherListView.flick(0, launcherListView.clickFlickSpeed);
431 root.applicationSelected(LauncherModel.get(index).appId);
443 function endDrag(dragItem) {
444 var droppedIndex = draggedIndex;
455 selectedItem.dragging = false;
456 selectedItem = undefined;
459 dragItem.target = undefined
461 progressiveScrollingTimer.stop();
462 launcherListView.interactive = true;
463 if (droppedIndex >= launcherListView.count - 2 && postDragging) {
464 snapToBottomAnimation.start();
465 } else if (droppedIndex < 2 && postDragging) {
466 snapToTopAnimation.start();
471 processPressAndHold(mouse, drag);
474 function processPressAndHold(mouse, dragItem) {
475 if (Math.abs(selectedItem.angle) > 30) {
481 draggedIndex = Math.floor((mouse.y + launcherListView.realContentY) / launcherListView.realItemHeight);
484 quickList.item = selectedItem;
485 quickList.model = launcherListView.model.get(draggedIndex).quickList;
486 quickList.appId = launcherListView.model.get(draggedIndex).appId;
487 quickList.state = "open";
489 launcherListView.interactive = false
491 var yOffset = draggedIndex > 0 ? (mouse.y + launcherListView.realContentY) % (draggedIndex * launcherListView.realItemHeight) : mouse.y + launcherListView.realContentY
493 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
494 fakeDragItem.x = units.gu(0.5)
495 fakeDragItem.y = mouse.y - yOffset + launcherListView.anchors.topMargin + launcherListView.topMargin
496 fakeDragItem.angle = selectedItem.angle * (root.inverted ? -1 : 1)
497 fakeDragItem.offset = selectedItem.offset * (root.inverted ? -1 : 1)
498 fakeDragItem.count = LauncherModel.get(draggedIndex).count
499 fakeDragItem.progress = LauncherModel.get(draggedIndex).progress
500 fakeDragItem.flatten()
501 dragItem.target = fakeDragItem
508 processPositionChanged(mouse)
511 function processPositionChanged(mouse) {
512 if (draggedIndex >= 0) {
513 if (!selectedItem.dragging) {
514 var distance = Math.max(Math.abs(mouse.x - startX), Math.abs(mouse.y - startY))
515 if (!preDragging && distance > units.gu(1.5)) {
517 quickList.state = "";
519 if (distance > launcherListView.itemHeight) {
520 selectedItem.dragging = true
524 if (!selectedItem.dragging) {
528 var itemCenterY = fakeDragItem.y + fakeDragItem.height / 2
530 // Move it down by the the missing size to compensate index calculation with only expanded items
531 itemCenterY += (launcherListView.itemHeight - selectedItem.height) / 2
533 if (mouseY > launcherListView.height - launcherListView.topMargin - launcherListView.bottomMargin - launcherListView.realItemHeight) {
534 progressiveScrollingTimer.downwards = false
535 progressiveScrollingTimer.start()
536 } else if (mouseY < launcherListView.realItemHeight) {
537 progressiveScrollingTimer.downwards = true
538 progressiveScrollingTimer.start()
540 progressiveScrollingTimer.stop()
543 var newIndex = (itemCenterY + launcherListView.realContentY) / launcherListView.realItemHeight
545 if (newIndex > draggedIndex + 1) {
546 newIndex = draggedIndex + 1
547 } else if (newIndex < draggedIndex) {
548 newIndex = draggedIndex -1
553 if (newIndex >= 0 && newIndex < launcherListView.count) {
554 if (launcherListView.draggingTransitionRunning) {
555 launcherListView.scheduledMoveTo = newIndex
557 launcherListView.model.move(draggedIndex, newIndex)
558 draggedIndex = newIndex
565 id: progressiveScrollingTimer
569 property bool downwards: true
572 var minY = -launcherListView.topMargin
573 if (launcherListView.contentY > minY) {
574 launcherListView.contentY = Math.max(launcherListView.contentY - units.dp(2), minY)
577 var maxY = launcherListView.contentHeight - launcherListView.height + launcherListView.topMargin + launcherListView.originY
578 if (launcherListView.contentY < maxY) {
579 launcherListView.contentY = Math.min(launcherListView.contentY + units.dp(2), maxY)
589 objectName: "fakeDragItem"
590 visible: dndArea.draggedIndex >= 0 && !dndArea.postDragging
591 itemWidth: launcherListView.itemWidth
592 itemHeight: launcherListView.itemHeight
595 rotation: root.rotation
599 fakeDragItemAnimation.start();
602 UbuntuNumberAnimation {
603 id: fakeDragItemAnimation
604 target: fakeDragItem;
605 properties: "angle,offset";
614 objectName: "quickListShape"
615 anchors.fill: quickList
616 opacity: quickList.state === "open" ? 0.8 : 0
618 rotation: root.rotation
620 Behavior on opacity {
621 UbuntuNumberAnimation {}
629 rightMargin: -units.dp(4)
630 verticalCenter: parent.verticalCenter
631 verticalCenterOffset: -quickList.offset * (root.inverted ? -1 : 1)
635 source: "graphics/quicklist_tooltip.png"
640 anchors.fill: quickListShape
641 enabled: quickList.state == "open" || pressed
647 // Forward for dragging to work when quickList is open
650 var m = mapToItem(dndArea, mouseX, mouseY)
651 dndArea.processPress(m)
655 var m = mapToItem(dndArea, mouseX, mouseY)
656 dndArea.processPressAndHold(m, drag)
660 var m = mapToItem(dndArea, mouseX, mouseY)
661 dndArea.processPositionChanged(m)
665 dndArea.endDrag(drag);
669 dndArea.endDrag(drag);
675 objectName: "quickList"
677 // Because we're setting left/right anchors depending on orientation, it will break the
678 // width setting after rotating twice. This makes sure we also re-apply width on rotation
679 width: root.inverted ? units.gu(30) : units.gu(30)
680 height: quickListColumn.height
681 visible: quickListShape.visible
683 left: root.inverted ? undefined : parent.right
684 right: root.inverted ? parent.left : undefined
687 y: itemCenter - (height / 2) + offset
688 rotation: root.rotation
691 property string appId
695 property int itemCenter: item ? root.mapFromItem(quickList.item).y + (item.height / 2) : units.gu(1)
696 property int offset: itemCenter + (height/2) + units.gu(1) > parent.height ? -itemCenter - (height/2) - units.gu(1) + parent.height :
697 itemCenter - (height/2) < units.gu(1) ? (height/2) - itemCenter + units.gu(1) : 0
702 height: childrenRect.height
706 model: quickList.model
709 objectName: "quickListEntry" + index
710 text: (model.clickable ? "" : "<b>") + model.label + (model.clickable ? "" : "</b>")
711 highlightWhenPressed: model.clickable
713 // FIXME: This is a workaround for the theme not being context sensitive. I.e. the
714 // ListItems don't know that they are sitting in a themed Popover where the color
715 // needs to be inverted.
716 __foregroundColor: "black"
719 if (!model.clickable) {
723 quickList.state = "";
724 // Unsetting model to prevent showing changing entries during fading out
725 // that may happen because of triggering an action.
726 LauncherModel.quickListActionInvoked(quickList.appId, index);
727 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