on xenial help sign in
improve dragging and hover scrolling
f20331bMichael Zanetti
qml/Stage/Spread/ScreensAndWorkspaces.qml+12−2
@@ -138,6 +138,11 @@ Item {
138 hoverEnabled: true
138 hoverEnabled: true
139 onPressed: mouse.accepted = false;
139 onPressed: mouse.accepted = false;
140 }
140 }
141+ DropArea {
142+ id: leftFakeDropArea
143+ anchors.fill: parent
144+ keys: ["application", "workspace"]
145+ }
141 }
146 }
142 Rectangle {
147 Rectangle {
143 anchors { right: parent.right; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
148 anchors { right: parent.right; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
@@ -150,16 +155,21 @@ Item {
150 hoverEnabled: true
155 hoverEnabled: true
151 onPressed: mouse.accepted = false;
156 onPressed: mouse.accepted = false;
152 }
157 }
158+ DropArea {
159+ id: rightFakeDropArea
160+ anchors.fill: parent
161+ keys: ["application", "workspace"]
162+ }
153 }
163 }
154 Timer {
164 Timer {
155 repeat: true
165 repeat: true
156− running: leftScrollArea.containsMouse || rightScrollArea.containsMouse
166+ running: leftScrollArea.containsMouse || rightScrollArea.containsMouse || leftFakeDropArea.containsDrag || rightFakeDropArea.containsDrag
157 interval: UbuntuAnimation.SlowDuration
167 interval: UbuntuAnimation.SlowDuration
158 triggeredOnStart: true
168 triggeredOnStart: true
159 onTriggered: {
169 onTriggered: {
160 var newOffset = row.anchors.horizontalCenterOffset;
170 var newOffset = row.anchors.horizontalCenterOffset;
161 var maxOffset = Math.max((row.width - root.width + units.gu(10)) / 2, 0);
171 var maxOffset = Math.max((row.width - root.width + units.gu(10)) / 2, 0);
162− if (leftScrollArea.containsMouse) {
172+ if (leftScrollArea.containsMouse || leftFakeDropArea.containsDrag) {
163 newOffset += units.gu(20)
173 newOffset += units.gu(20)
164 } else {
174 } else {
165 newOffset -= units.gu(20)
175 newOffset -= units.gu(20)
qml/Stage/Spread/WorkspacePreview.qml+9−6
@@ -14,12 +14,7 @@ Item {
14
14
15 property real previewScale: previewSpace.height / previewSpace.screenHeight
15 property real previewScale: previewSpace.height / previewSpace.screenHeight
16
16
17− DropArea {
17+ property bool containsDrag: false
18− anchors.fill: parent
19− keys: ["application"]
20−
21− onEntered: print("yehaaaa")
22− }
23
18
24 Image {
19 Image {
25 source: previewSpace.background
20 source: previewSpace.background
@@ -67,6 +62,14 @@ Item {
67 }
62 }
68
63
69 }
64 }
65+
66+ Rectangle {
67+ anchors.fill: parent
68+ border.color: UbuntuColors.blue
69+ border.width: units.gu(.5)
70+ color: "transparent"
71+ visible: previewSpace.containsDrag
72+ }
70}
73}
71
74
72 // Repeater {
75 // Repeater {
qml/Stage/Spread/Workspaces.qml+33−5
@@ -18,14 +18,14 @@ Item {
18 keys: ['workspace']
18 keys: ['workspace']
19
19
20 onEntered: {
20 onEntered: {
21− var index = listView.getDropIndex(drag);
21+ var index = listView.getWorkspaceDropIndex(drag);
22 listView.model.insert(index, {text: drag.source.text})
22 listView.model.insert(index, {text: drag.source.text})
23 listView.dropItemIndex = index;
23 listView.dropItemIndex = index;
24 drag.source.inDropArea = true;
24 drag.source.inDropArea = true;
25 }
25 }
26
26
27 onPositionChanged: {
27 onPositionChanged: {
28− var index = listView.getDropIndex(drag);
28+ var index = listView.getWorkspaceDropIndex(drag);
29 if (listView.dropItemIndex == index) return;
29 if (listView.dropItemIndex == index) return;
30 listView.model.move(listView.dropItemIndex, index, 1);
30 listView.model.move(listView.dropItemIndex, index, 1);
31 listView.dropItemIndex = index;
31 listView.dropItemIndex = index;
@@ -42,6 +42,18 @@ Item {
42 drag.source.inDropArea = false;
42 drag.source.inDropArea = false;
43 }
43 }
44 }
44 }
45+ DropArea {
46+ anchors.fill: parent
47+ keys: ["application"]
48+
49+ onPositionChanged: {
50+ listView.progressiveScroll(drag.x)
51+ listView.hoveredWorkspaceIndex = listView.getApplicationDropIndex(drag)
52+ }
53+ onExited: {
54+ listView.hoveredWorkspaceIndex = -1
55+ }
56+ }
45
57
46 ListView {
58 ListView {
47 id: listView
59 id: listView
@@ -59,8 +71,18 @@ Item {
59 property int foldingAreaWidth: units.gu(10)
71 property int foldingAreaWidth: units.gu(10)
60 property real realContentX: contentX - originX + leftMargin
72 property real realContentX: contentX - originX + leftMargin
61 property int dropItemIndex: -1
73 property int dropItemIndex: -1
74+ property int hoveredWorkspaceIndex: -1
75+
76+ function getWorkspaceDropIndex(drag) {
77+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
78+ var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
79+ if (index < 0) index = 0;
80+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
81+ if (index > upperLimit) index = upperLimit;
82+ return index;
83+ }
62
84
63− function getDropIndex(drag) {
85+ function getApplicationDropIndex(drag) {
64 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
86 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
65 var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
87 var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
66 if (index < 0) index = 0;
88 if (index < 0) index = 0;
@@ -69,6 +91,12 @@ Item {
69 return index;
91 return index;
70 }
92 }
71
93
94+ function progressiveScroll(mouseX) {
95+ var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
96+ print("p", progress, mouseX)
97+ listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
98+ }
99+
72 displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
100 displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
73
101
74 delegate: Item {
102 delegate: Item {
@@ -164,6 +192,7 @@ Item {
164 width: listView.itemWidth
192 width: listView.itemWidth
165 background: root.background
193 background: root.background
166 screenHeight: root.screen.physicalSize.height
194 screenHeight: root.screen.physicalSize.height
195+ containsDrag: listView.hoveredWorkspaceIndex == index
167
196
168 Label {
197 Label {
169 anchors.centerIn: parent
198 anchors.centerIn: parent
@@ -189,8 +218,7 @@ Item {
189
218
190 onMouseXChanged: {
219 onMouseXChanged: {
191 if (!pressed || dragging) {
220 if (!pressed || dragging) {
192− var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.foldingAreaWidth * 2)))
221+ listView.progressiveScroll(mouseX)
193− listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
194 }
222 }
195 }
223 }
196 onMouseYChanged: {
224 onMouseYChanged: {
qml/Stage/Stage.qml−2
@@ -762,8 +762,6 @@ FocusScope {
762 height: implicitHeight * previewScale
762 height: implicitHeight * previewScale
763 surfaceWidth: -1
763 surfaceWidth: -1
764 surfaceHeight: -1
764 surfaceHeight: -1
765−// surface: model.window.surface
766− onSurfaceChanged: print("surface changed", surface)
767 opacity: surface != null ? 1 : 0
765 opacity: surface != null ? 1 : 0
768 Behavior on opacity { UbuntuNumberAnimation {} }
766 Behavior on opacity { UbuntuNumberAnimation {} }
769 visible: opacity > 0
767 visible: opacity > 0