on xenial help sign in
add support for dragging apps out of the spread
commit792e2c990077a2782fbb142b8f2d83907f38e010 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 20 Feb 2017, 10:50 (10 years ago) parent051de42
5 files changed+94−20
qml/Stage/Spread/ScreensAndWorkspaces.qml+19 qml/Stage/Spread/SpreadDelegateInputArea.qml+24−11 qml/Stage/Spread/WorkspacePreview.qml+10−1 qml/Stage/Spread/Workspaces.qml+17−6 qml/Stage/Stage.qml+24−2
qml/Stage/Spread/ScreensAndWorkspaces.qml+19
@@ -33,6 +33,25 @@ Item {
3333 backgroundColor: "white"
3434 z: 1
3535
36+ DropArea {
37+ anchors.fill: parent
38+ keys: ["workspace"]
39+
40+ onEntered: {
41+ workspaces.workspaceModel.insert(workspaces.workspaceModel.count, {text: drag.source.text})
42+ drag.source.inDropArea = true;
43+ }
44+
45+ onExited: {
46+ workspaces.workspaceModel.remove(workspaces.workspaceModel.count - 1, 1)
47+ drag.source.inDropArea = false;
48+ }
49+
50+ onDropped: {
51+ drag.source.inDropArea = false;
52+ }
53+ }
54+
3655 Column {
3756 anchors.fill: parent
3857 anchors.margins: units.gu(1)
qml/Stage/Spread/SpreadDelegateInputArea.qml+24−11
@@ -85,15 +85,15 @@ Item {
8585 }
8686
8787 // Event eater
88− MouseArea {
89− anchors.fill: parent
90− onClicked: root.clicked()
91− onWheel: wheel.accepted = true
92− }
88+// MouseArea {
89+// anchors.fill: parent
90+// onClicked: root.clicked()
91+// onWheel: wheel.accepted = true
92+// }
9393
9494 MultiPointTouchArea {
9595 anchors.fill: parent
96− mouseEnabled: false
96+// mouseEnabled: false
9797 maximumTouchPoints: 1
9898 property int offset: 0
9999
@@ -109,7 +109,7 @@ Item {
109109 }
110110
111111 onTouchUpdated: {
112− if (!d.moving) {
112+ if (!d.moving || !tp.pressed) {
113113 if (Math.abs(tp.startY - tp.y) > d.threshold) {
114114 d.moving = true;
115115 d.dragEvents = []
@@ -119,17 +119,30 @@ Item {
119119 }
120120 }
121121
122− if (root.closeable) {
123− d.distance = tp.y - tp.startY - offset
122+
123+ var value = tp.y - tp.startY - offset;
124+ if (value < 0) {
125+ var coords = mapToItem(shell, tp.x, tp.y);
126+ fakeDragItem.x = coords.x
127+ fakeDragItem.y = coords.y
128+ fakeDragItem.Drag.active = true;
129+ fakeDragItem.surface = model.window.surface;
130+
124131 } else {
125− var value = tp.y - tp.startY - offset;
126− d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
132+ if (root.closeable) {
133+ d.distance = value
134+ } else {
135+ d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
136+ }
127137 }
128138
129139 d.pushDragEvent(tp);
130140 }
131141
132142 onReleased: {
143+ print("released!")
144+ fakeDragItem.surface = null;
145+
133146 if (!d.moving) {
134147 root.clicked()
135148 }
qml/Stage/Spread/WorkspacePreview.qml+10−1
@@ -14,9 +14,18 @@ Item {
1414
1515 property real previewScale: previewSpace.height / previewSpace.screenHeight
1616
17− Wallpaper {
17+ DropArea {
18+ anchors.fill: parent
19+ keys: ["application"]
20+
21+ onEntered: print("yehaaaa")
22+ }
23+
24+ Image {
1825 source: previewSpace.background
1926 anchors.fill: parent
27+ sourceSize.width: width
28+ sourceSize.height: height
2029
2130 Repeater {
2231 id: topLevelSurfaceRepeater
qml/Stage/Spread/Workspaces.qml+17−6
@@ -48,7 +48,7 @@ Item {
4848 anchors.fill: parent
4949 anchors.leftMargin: -itemWidth
5050 anchors.rightMargin: -itemWidth
51− interactive: false
51+// interactive: false
5252
5353 orientation: ListView.Horizontal
5454 spacing: units.gu(1)
@@ -178,17 +178,25 @@ Item {
178178 id: mouseArea
179179 anchors.fill: parent
180180 hoverEnabled: true
181− preventStealing: true
181+ propagateComposedEvents: true
182182 anchors.leftMargin: listView.leftMargin
183183 anchors.rightMargin: listView.rightMargin
184184
185185 property int draggedIndex: -1
186186
187+ property int startX: 0
188+ property int startY: 0
189+
187190 onMouseXChanged: {
188− var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.foldingAreaWidth * 2)))
189−// var progress = mouseX / width
190− print("p:", progress)
191− listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
191+ if (!pressed || dragging) {
192+ var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.foldingAreaWidth * 2)))
193+ listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
194+ }
195+ }
196+ onMouseYChanged: {
197+ if (Math.abs(mouseY - startY) > units.gu(3)) {
198+ drag.axis = Drag.XAndYAxis;
199+ }
192200 }
193201
194202 onReleased: {
@@ -205,6 +213,8 @@ Item {
205213 }
206214
207215 onPressed: {
216+ startX = mouseX;
217+ startY = mouseY;
208218 if (listView.model.count < 2) return;
209219
210220 var coords = mapToItem(listView.contentItem, mouseX, mouseY)
@@ -220,6 +230,7 @@ Item {
220230 fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
221231 fakeDragItem.Drag.hotSpot.y = mouseCoordsInItem.y
222232
233+ drag.axis = Drag.YAxis;
223234 drag.target = fakeDragItem;
224235 }
225236
qml/Stage/Stage.qml+24−2
@@ -620,6 +620,8 @@ FocusScope {
620620 property int scrollAreaWidth: width / 3
621621 property bool progressiveScrollingEnabled: false
622622
623+ onPressed: mouse.accepted = false
624+
623625 onMouseXChanged: {
624626 mouse.accepted = false
625627
@@ -658,8 +660,6 @@ FocusScope {
658660 }
659661 }
660662 }
661−
662− onPressed: mouse.accepted = false
663663 }
664664 }
665665
@@ -755,6 +755,25 @@ FocusScope {
755755 }
756756 }
757757
758+ MirSurfaceItem {
759+ id: fakeDragItem
760+ property real previewScale: .5
761+ width: implicitWidth * previewScale
762+ height: implicitHeight * previewScale
763+ surfaceWidth: -1
764+ surfaceHeight: -1
765+// surface: model.window.surface
766+ onSurfaceChanged: print("surface changed", surface)
767+ opacity: surface != null ? 1 : 0
768+ Behavior on opacity { UbuntuNumberAnimation {} }
769+ visible: opacity > 0
770+
771+ Drag.active: surface != null
772+ Drag.keys: ["application"]
773+
774+ z: 1000
775+ }
776+
758777 Item {
759778 id: boundariesForWindowPlacement
760779 anchors.fill: parent
@@ -790,6 +809,9 @@ FocusScope {
790809 }
791810 z: normalZ
792811
812+ opacity: fakeDragItem.surface == model.window.surface && fakeDragItem.Drag.active ? 0 : 1
813+ Behavior on opacity { UbuntuNumberAnimation {} }
814+
793815 // Normally we want x/y where the surface thinks it is. Width/height of our delegate will
794816 // match what the actual surface size is.
795817 // Don't write to those, they will be set by states