@@ -2,20 +2,34 @@ 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)
9 property var screen: null
10 property var screen: null
10 property var background // TODO: should be stored in the workspace data
11 property var background // TODO: should be stored in the workspace data
13+// Rectangle { anchors.fill: parent; color: "green" }
12 ListView {
14 ListView {
13 id: listView
15 id: listView
14 anchors.fill: parent
16 anchors.fill: parent
15 anchors.leftMargin: -itemWidth
17 anchors.leftMargin: -itemWidth
16 anchors.rightMargin: -itemWidth
18 anchors.rightMargin: -itemWidth
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"}
20 orientation: ListView.Horizontal
34 orientation: ListView.Horizontal
21 spacing: units.gu(1)
35 spacing: units.gu(1)
@@ -31,11 +45,11 @@ Item {
31 delegate: Item {
45 delegate: Item {
32 objectName: "delegate" + index
46 objectName: "delegate" + index
33 height: parent.height
47 height: parent.height
34− width: /*dndArea.draggedIndex == index ? units.gu(5) : */listView.itemWidth
48+ width: /*dndArea.draggedIndex == index ? units.gu(5) :*/ listView.itemWidth
35 Behavior on width { UbuntuNumberAnimation {} }
49 Behavior on width { UbuntuNumberAnimation {} }
37− property int itemX: -listView.contentX - listView.leftMargin + index * (listView.itemWidth + listView.spacing)
51+ property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
38− property int distanceFromLeft: itemX
52+ property int distanceFromLeft: itemX //- listView.leftMargin
39 property int distanceFromRight: listView.width - listView.leftMargin - listView.rightMargin - itemX - listView.itemWidth
53 property int distanceFromRight: listView.width - listView.leftMargin - listView.rightMargin - itemX - listView.itemWidth
41 property int maxAngle: 40
55 property int maxAngle: 40
@@ -123,6 +137,79 @@ Item {
123 background: root.background
137 background: root.background
124 screenHeight: screen.physicalSize.height
138 screenHeight: screen.physicalSize.height
142+ anchors.centerIn: parent
151+ anchors.fill: parent
153+ preventStealing: true
154+ anchors.leftMargin: listView.leftMargin
155+ anchors.rightMargin: listView.rightMargin
158+ property int draggedIndex: -1
161+ var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth*2) / (width - listView.foldingAreaWidth * 4)))
162+// var progress = mouseX / width
163+// print("p:", progress)
164+ listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
167+ if (draggedIndex == -1) {
171+// var newIndex = (listView.realContentX) / listView.itemWidth
172+ var coords = mapToItem(listView.contentItem, mouseX + listView.itemWidth, mouseY)
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) {
187+ listView.model.move(draggedIndex, newIndex, 1)
188+ draggedIndex = newIndex
197+// var clickedItem = listView.itemAt(mouseX /*+ listView.realContentX*/, mouseY)
198+// var clickedIndex = listView.indexAt(mouseX /*- listView.realContentX*/, mouseY)
200+ for (var i = 0; i < listView.count; i++) {
201+ var x = -listView.leftMargin + i * listView.itemWidth - units.gu(1);
202+ print("x:", x, "index:", listView.indexAt(x, listView.height / 2))
205+ var coords = mapToItem(listView.contentItem, mouseX, mouseY)
206+ var clickedIndex = listView.indexAt(coords.x, coords.y)
208+ draggedIndex = clickedIndex
210+ print("index:", mouseX, clickedIndex)