@@ -2,15 +2,46 @@ import QtQuick 2.4
2import Ubuntu.Components 1.3
2import Ubuntu.Components 1.3
3import "MathUtils.js" as MathUtils
3import "MathUtils.js" as MathUtils
7− implicitWidth: listView.count * (height * 16/9)
7+ implicitWidth: listView.count * (height * 16/9 + listView.spacing) - listView.spacing
8− color: "blue"
8+// color: "blue"
10− property var screen: null
10+ property QtObject screen: null
11+ property alias workspaceModel: listView.model
11 property var background // TODO: should be stored in the workspace data
12 property var background // TODO: should be stored in the workspace data
13−// Rectangle { anchors.fill: parent; color: "green" }
15+ anchors.fill: root
20+ var index = listView.getDropIndex(drag);
21+ listView.model.insert(index, {text: drag.source.text})
22+ listView.dropItemIndex = index;
23+ drag.source.inDropArea = true;
27+ var index = listView.getDropIndex(drag);
28+ if (listView.dropItemIndex == index) return;
29+ listView.model.move(listView.dropItemIndex, index, 1);
30+ listView.dropItemIndex = index;
34+ listView.model.remove(listView.dropItemIndex, 1);
35+ listView.dropItemIndex = -1;
36+ drag.source.inDropArea = false;
40+ listView.dropItemIndex = -1;
41+ drag.source.inDropArea = false;
14 ListView {
45 ListView {
15 id: listView
46 id: listView
16 anchors.fill: parent
47 anchors.fill: parent
@@ -18,19 +49,6 @@ Rectangle {
18 anchors.rightMargin: -itemWidth
49 anchors.rightMargin: -itemWidth
19 interactive: false
50 interactive: false
22− ListElement {text: "1"}
23− ListElement {text: "2"}
24− ListElement {text: "3"}
25− ListElement {text: "4"}
26− ListElement {text: "5"}
27− ListElement {text: "6"}
28− ListElement {text: "7"}
29− ListElement {text: "8"}
30− ListElement {text: "9"}
34 orientation: ListView.Horizontal
52 orientation: ListView.Horizontal
35 spacing: units.gu(1)
53 spacing: units.gu(1)
36 leftMargin: itemWidth
54 leftMargin: itemWidth
@@ -39,14 +57,25 @@ Rectangle {
39 property int itemWidth: height * 16 / 9
57 property int itemWidth: height * 16 / 9
40 property int foldingAreaWidth: units.gu(10)
58 property int foldingAreaWidth: units.gu(10)
41 property real realContentX: contentX - originX + leftMargin
59 property real realContentX: contentX - originX + leftMargin
60+ property int dropItemIndex: -1
62+ function getDropIndex(drag) {
63+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
64+ var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
65+ if (index < 0) index = 0;
66+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
67+ if (index > upperLimit) index = upperLimit;
43 displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
71 displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
45 delegate: Item {
73 delegate: Item {
46 objectName: "delegate" + index
74 objectName: "delegate" + index
47 height: parent.height
75 height: parent.height
48− width: /*dndArea.draggedIndex == index ? units.gu(5) :*/ listView.itemWidth
76+ width: listView.itemWidth
49 Behavior on width { UbuntuNumberAnimation {} }
77 Behavior on width { UbuntuNumberAnimation {} }
78+ visible: listView.dropItemIndex !== index
51 property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
80 property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
52 property int distanceFromLeft: itemX //- listView.leftMargin
81 property int distanceFromLeft: itemX //- listView.leftMargin
@@ -83,34 +112,33 @@ Rectangle {
85 property int itemOffset: {
114 property int itemOffset: {
115+ var rotationOffset = (1 - Math.cos(itemAngle * Math.PI / 360)) * listView.itemWidth
86 if (index == 0) {
116 if (index == 0) {
87 if (distanceFromLeft < 0) {
117 if (distanceFromLeft < 0) {
88− return -distanceFromLeft
118+ return -distanceFromLeft - rotationOffset
92 if (index == listView.count - 1) {
122 if (index == listView.count - 1) {
93 if (distanceFromRight < 0) {
123 if (distanceFromRight < 0) {
94− return distanceFromRight
124+ return distanceFromRight + rotationOffset
99 if (itemX < -listView.foldingAreaWidth) {
129 if (itemX < -listView.foldingAreaWidth) {
100− return -itemX
130+ return -itemX - rotationOffset
102 if (distanceFromLeft < listView.foldingAreaWidth) {
132 if (distanceFromLeft < listView.foldingAreaWidth) {
103− var progress = distanceFromLeft / listView.foldingAreaWidth
104− return (listView.foldingAreaWidth - distanceFromLeft) / 2
133+ return (listView.foldingAreaWidth - distanceFromLeft) / 2 - rotationOffset
107 if (distanceFromRight < -listView.foldingAreaWidth) {
136 if (distanceFromRight < -listView.foldingAreaWidth) {
108− return distanceFromRight
137+ return distanceFromRight + rotationOffset
111 if (distanceFromRight < listView.foldingAreaWidth) {
140 if (distanceFromRight < listView.foldingAreaWidth) {
112− var progress = distanceFromRight / listView.foldingAreaWidth;
113− return -(listView.foldingAreaWidth - distanceFromRight) / 2
141+ return -(listView.foldingAreaWidth - distanceFromRight) / 2 + rotationOffset
@@ -123,38 +151,36 @@ Rectangle {
123 Rotation {
151 Rotation {
124 angle: itemAngle
152 angle: itemAngle
125 axis { x: 0; y: 1; z: 0 }
153 axis { x: 0; y: 1; z: 0 }
126− origin { x: /*itemAngle > 0 ? 0 : listView.itemWidth*/ listView.itemWidth / 2; y: height / 2 }
154+ origin { x: listView.itemWidth / 2; y: height / 2 }
128 Translate {
156 Translate {
129 x: itemOffset
157 x: itemOffset
134 WorkspacePreview {
161 WorkspacePreview {
135 height: listView.height
162 height: listView.height
136 width: listView.itemWidth
163 width: listView.itemWidth
137 background: root.background
164 background: root.background
138− screenHeight: screen.physicalSize.height
165+ screenHeight: root.screen.physicalSize.height
142− anchors.centerIn: parent
168+ anchors.centerIn: parent
143− text: model.text
169+ text: model.text
144− fontSize: "large"
171+ fontSize: "large"
149 MouseArea {
176 MouseArea {
150− id: dndArea
177+ id: mouseArea
151 anchors.fill: parent
178 anchors.fill: parent
152 hoverEnabled: true
179 hoverEnabled: true
153 preventStealing: true
180 preventStealing: true
154 anchors.leftMargin: listView.leftMargin
181 anchors.leftMargin: listView.leftMargin
155 anchors.rightMargin: listView.rightMargin
182 anchors.rightMargin: listView.rightMargin
158 property int draggedIndex: -1
184 property int draggedIndex: -1
160 onMouseXChanged: {
186 onMouseXChanged: {
@@ -162,54 +188,89 @@ Rectangle {
162// var progress = mouseX / width
188// var progress = mouseX / width
163// print("p:", progress)
189// print("p:", progress)
164 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
190 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
194+ fakeDragItem.Drag.drop();
167− if (draggedIndex == -1) {
198+ property bool dragging: drag.active
168− return;
199+ onDraggingChanged: {
201+ print("drai", draggedIndex)
202+ listView.model.remove(draggedIndex, 1)
171−// var newIndex = (listView.realContentX) / listView.itemWidth
206+ onPressed: {
172− var coords = mapToItem(listView.contentItem, mouseX + listView.itemWidth, mouseY)
207+ if (listView.model.count < 2) return;
173− var newIndex = (coords.x + listView.leftMargin) / (listView.itemWidth + listView.spacing)
174− print("newIndex", newIndex)
175−// var newIndex = listView.indexAt(coords.x, coords.y)
176−// if (newIndex == -1) return;
178− if (newIndex > draggedIndex + 1) {
179− newIndex = draggedIndex + 1
180− } else if (newIndex < draggedIndex) {
181− newIndex = draggedIndex - 1
186− if (newIndex >= 0 && newIndex < listView.count) {
209+ var coords = mapToItem(listView.contentItem, mouseX, mouseY)
187− listView.model.move(draggedIndex, newIndex, 1)
210+ draggedIndex = listView.indexAt(coords.x, coords.y)
188− draggedIndex = newIndex
211+ var clickedItem = listView.itemAt(coords.x, coords.y)
192− onReleased: {
213+ var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
193− draggedIndex = -1
214+ fakeDragItem.x = itemCoords.x
194− }
215+ fakeDragItem.y = itemCoords.y
216+ fakeDragItem.text = listView.model.get(draggedIndex).text
197−// var clickedItem = listView.itemAt(mouseX /*+ listView.realContentX*/, mouseY)
218+ var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
198−// var clickedIndex = listView.indexAt(mouseX /*- listView.realContentX*/, mouseY)
219+ fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
220+ fakeDragItem.Drag.hotSpot.y = mouseCoordsInItem.y
222+ drag.target = fakeDragItem;
200− for (var i = 0; i < listView.count; i++) {
225+ WorkspacePreview {
227+ height: listView.height
201− var x = -listView.leftMargin + i * listView.itemWidth - units.gu(1);
228+ width: listView.itemWidth
202− print("x:", x, "index:", listView.indexAt(x, listView.height / 2))
229+ background: root.background
230+ screenHeight: root.screen.physicalSize.height
231+ visible: Drag.active
233+ Drag.active: mouseArea.drag.active
234+ Drag.keys: ['workspace']
236+ property string text
237+ property bool inDropArea: false
239+ anchors.centerIn: parent
205− var coords = mapToItem(listView.contentItem, mouseX, mouseY)
245+ Rectangle {
206− var clickedIndex = listView.indexAt(coords.x, coords.y)
246+ anchors.fill: parent
248+ opacity: parent.inDropArea ? 0 : 1
249+ Behavior on opacity { UbuntuNumberAnimation { } }
251+ anchors.centerIn: parent
208− draggedIndex = clickedIndex
258+ Icon {
261+ anchors.centerIn: parent
210− print("index:", mouseX, clickedIndex)
267+ states: [
269+ when: fakeDragItem.Drag.active
270+ ParentChange { target: fakeDragItem; parent: shell }