18 import Ubuntu.Components 0.1
19 import Ubuntu.Components.ListItems 0.1 as ListItems
20 import Unity.Launcher 0.1
21 import Ubuntu.Components.Popups 0.1
22 import
"../Components/ListItems"
23 import "../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)
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.showDashHome()
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)
113 property int extensionSize: 0
123 Component.onCompleted: {
124 extensionSize = itemHeight * 3
125 flick(0, clickFlickSpeed)
129 property int foldingStartHeight: units.gu(6.5)
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
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)
291 if (clickedItem === null) {
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);
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
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
561 __foregroundColor: Theme.palette.selected.backgroundText
564 if (!model.clickable) {
567 quickList.state =
"";
570 LauncherModel.quickListActionInvoked(quickList.appId, index);
571 quickList.model = undefined;