on xenial help sign in
port the touch overlay to MoveHandler
644484fLukáš Tinkl
qml/Panel/Panel.qml+2−3
@@ -108,14 +108,13 @@ Item {
108 drag.minimumY: panelHeight
108 drag.minimumY: panelHeight
109 drag.maximumX: PanelState.maximizedAppDelegate ? PanelState.maximizedAppDelegate.moveHandler.stageWidth : 0
109 drag.maximumX: PanelState.maximizedAppDelegate ? PanelState.maximizedAppDelegate.moveHandler.stageWidth : 0
110 drag.maximumY: PanelState.maximizedAppDelegate ? PanelState.maximizedAppDelegate.moveHandler.stageHeight : 0
110 drag.maximumY: PanelState.maximizedAppDelegate ? PanelState.maximizedAppDelegate.moveHandler.stageHeight : 0
111− drag.threshold: panelHeight
111+ drag.threshold: PanelState.panelHeight
112 drag.filterChildren: true
112 drag.filterChildren: true
113 onReleased: {
113 onReleased: {
114 if (drag.active) {
114 if (drag.active) {
115 var delegate = PanelState.maximizedAppDelegate;
115 var delegate = PanelState.maximizedAppDelegate;
116− print("!!! Released drag at", mouse.x, mouse.y, drag.active)
117 delegate.restoredX = Math.round(mouse.x - delegate.moveHandler.buttonsWidth);
116 delegate.restoredX = Math.round(mouse.x - delegate.moveHandler.buttonsWidth);
118− delegate.restoredY = Math.round(Math.max(mouse.y, panelHeight));
117+ delegate.restoredY = Math.round(Math.max(mouse.y, PanelState.panelHeight));
119 delegate.restoreFromMaximized(false);
118 delegate.restoreFromMaximized(false);
120 }
119 }
121 }
120 }
qml/Stages/MoveHandler.qml+2
@@ -29,6 +29,8 @@ Item {
29 property int stageHeight
29 property int stageHeight
30 property real buttonsWidth: 0
30 property real buttonsWidth: 0
31
31
32+ readonly property alias dragging: priv.dragging
33+
32 signal fakeMaximizeAnimationRequested(real progress)
34 signal fakeMaximizeAnimationRequested(real progress)
33 signal fakeMaximizeLeftAnimationRequested(real progress)
35 signal fakeMaximizeLeftAnimationRequested(real progress)
34 signal fakeMaximizeRightAnimationRequested(real progress)
36 signal fakeMaximizeRightAnimationRequested(real progress)
qml/Stages/WindowControlsOverlay.qml+28−162
@@ -27,8 +27,8 @@ Item {
27
27
28 // to be set from outside
28 // to be set from outside
29 property Item target // appDelegate
29 property Item target // appDelegate
30− property int stageWidth
30+ property alias stageWidth: moveHandler.stageWidth
31− property int stageHeight
31+ property alias stageHeight: moveHandler.stageHeight
32
32
33 // to be read from outside
33 // to be read from outside
34 readonly property alias overlayShown: overlay.visible
34 readonly property alias overlayShown: overlay.visible
@@ -63,16 +63,17 @@ Item {
63 readonly property bool recognizedDrag: recognizedPress && dragging
63 readonly property bool recognizedDrag: recognizedPress && dragging
64 onRecognizedDragChanged: {
64 onRecognizedDragChanged: {
65 if (recognizedDrag) {
65 if (recognizedDrag) {
66− priv.handlePressedChanged(true, tp.x, tp.y);
66+ moveHandler.handlePressedChanged(true, Qt.LeftButton, tp.x, tp.y);
67− } else if (!moveHandler.containsPress) { // prevent interfering with the central piece drag/move
67+ } else if (!mouseArea.containsPress) { // prevent interfering with the central piece drag/move
68− priv.dragging = false;
68+ // FIXME!!!
69+ moveHandler.handlePressedChanged(false, Qt.LeftButton, tp.x, tp.y);
69 }
70 }
70 }
71 }
71
72
72 readonly property point tp: recognizedPress ? Qt.point(touchPoints[0].x, touchPoints[0].y) : Qt.point(-1, -1)
73 readonly property point tp: recognizedPress ? Qt.point(touchPoints[0].x, touchPoints[0].y) : Qt.point(-1, -1)
73 onUpdated: {
74 onUpdated: {
74 if (recognizedDrag) {
75 if (recognizedDrag) {
75− priv.handlePositionChanged(tp.x, tp.y);
76+ moveHandler.handlePositionChanged(tp);
76 }
77 }
77 }
78 }
78 }
79 }
@@ -81,74 +82,13 @@ Item {
81 Timer {
82 Timer {
82 id: overlayTimer
83 id: overlayTimer
83 interval: 2000
84 interval: 2000
84− repeat: priv.dragging || (priv.resizeArea && priv.resizeArea.dragging)
85+ repeat: moveHandler.dragging || (priv.resizeArea && priv.resizeArea.dragging)
85 }
86 }
86
87
87 QtObject {
88 QtObject {
88 id: priv
89 id: priv
89− property real distanceX
90− property real distanceY
91− property bool dragging
92−
93 readonly property var resizeArea: root.target && root.target.resizeArea ? root.target.resizeArea : null
90 readonly property var resizeArea: root.target && root.target.resizeArea ? root.target.resizeArea : null
94 readonly property bool ensureWindow: root.target.state == "normal" || root.target.state == "restored"
91 readonly property bool ensureWindow: root.target.state == "normal" || root.target.state == "restored"
95−
96− readonly property int triggerArea: units.gu(8)
97− property bool nearLeftEdge: target.maximizedLeft
98− property bool nearTopEdge: target.maximized
99− property bool nearRightEdge: target.maximizedRight
100− property bool nearTopLeftCorner: target.maximizedTopLeft
101− property bool nearTopRightCorner: target.maximizedTopRight
102− property bool nearBottomLeftCorner: target.maximizedBottomLeft
103− property bool nearBottomRightCorner: target.maximizedBottomRight
104−
105− function resetEdges() {
106− nearLeftEdge = false;
107− nearRightEdge = false;
108− nearTopEdge = false;
109− nearTopLeftCorner = false;
110− nearTopRightCorner = false;
111− nearBottomLeftCorner = false;
112− nearBottomRightCorner = false;
113− }
114−
115− function handlePressedChanged(pressed, mouseX, mouseY) {
116− if (pressed) {
117− var pos = mapToItem(root.target, mouseX, mouseY);
118− priv.distanceX = pos.x;
119− priv.distanceY = pos.y;
120− priv.dragging = true;
121− } else {
122− priv.dragging = false;
123− }
124− }
125−
126− function handlePositionChanged(mouseX, mouseY) {
127− var pos = mapToItem(root.target.parent, mouseX, mouseY);
128− root.target.requestedX = Math.round(pos.x - priv.distanceX);
129− root.target.requestedY = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
130− }
131−
132− function saveRestoredPos(x, y) {
133− var pos = mapToItem(root.target, x, y);
134− target.restoredX = Math.round(pos.x);
135− target.restoredY = Math.round(pos.y);
136− }
137−
138− // return the progress of mouse pointer movement from 0 to 1 within a corner square of the screen
139− // 0 -> before the mouse enters the square
140− // 1 -> mouse is exactly in the very corner
141− // a is the corner, b is the mouse pos
142− function progressInCorner(ax, ay, bx, by) {
143− // distance of two points, a and b, in pixels
144− var distance = Math.sqrt(Math.pow(bx-ax, 2) + Math.pow(by-ay, 2));
145− // length of the triggerArea square diagonal
146− var diagLength = Math.sqrt(2 * priv.triggerArea * priv.triggerArea);
147− var ratio = 1 - (distance / diagLength);
148− return bx > 0 && bx <= stageWidth && by > 0 && by <= stageHeight ? ratio : 1; // everything "outside" of our square from the center is 1
149− }
150−
151− property real progress: 0
152 }
92 }
153
93
154 // the visual overlay
94 // the visual overlay
@@ -174,106 +114,32 @@ Item {
174
114
175 // move handler
115 // move handler
176 MouseArea {
116 MouseArea {
177− id: moveHandler
117+ id: mouseArea
178 anchors.fill: parent
118 anchors.fill: parent
179 visible: overlay.visible
119 visible: overlay.visible
180 enabled: visible
120 enabled: visible
181 hoverEnabled: true
121 hoverEnabled: true
182− cursorShape: priv.dragging ? Qt.ClosedHandCursor : (overlay.visible ? Qt.OpenHandCursor : Qt.ArrowCursor)
122+ cursorShape: moveHandler.dragging ? Qt.ClosedHandCursor : (overlay.visible ? Qt.OpenHandCursor : Qt.ArrowCursor)
183
123
184− onPressedChanged: priv.handlePressedChanged(pressed, mouseX, mouseY)
124+ onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
185− onPositionChanged: {
125+ onPositionChanged: moveHandler.handlePositionChanged(mouse)
186− if (priv.dragging) {
126+ onReleased: moveHandler.handleReleased(mouse)
187− priv.handlePositionChanged(mouseX, mouseY);
127+ }
188
128
189− var globalPos = mapToItem(null, mouseX, mouseY);
129+ MoveHandler {
190− var globalX = globalPos.x;
130+ id: moveHandler
191− var globalY = globalPos.y;
131+ anchors.fill: mouseArea
192− if (globalX < priv.triggerArea && globalY < PanelState.panelHeight) { // top left
132+ objectName: "moveHandler"
193− if (target.canBeCornerMaximized) {
133+ target: root.target
194− priv.progress = priv.progressInCorner(0, PanelState.panelHeight, globalX, globalY);
134+
195− priv.resetEdges();
135+ onFakeMaximizeAnimationRequested: root.fakeMaximizeAnimationRequested(progress)
196− priv.nearTopLeftCorner = true;
136+ onFakeMaximizeLeftAnimationRequested: root.fakeMaximizeLeftAnimationRequested(progress)
137+ onFakeMaximizeRightAnimationRequested: root.fakeMaximizeRightAnimationRequested(progress)
197− root.fakeMaximizeTopLeftAnimationRequested(priv.progress);
138+ onFakeMaximizeTopLeftAnimationRequested: root.fakeMaximizeTopLeftAnimationRequested(progress)
198− }
199− } else if (globalX > stageWidth - priv.triggerArea && globalY < PanelState.panelHeight) { // top right
200− if (target.canBeCornerMaximized) {
201− priv.progress = priv.progressInCorner(stageWidth, PanelState.panelHeight, globalX, globalY);
202− priv.resetEdges();
203− priv.nearTopRightCorner = true;
204− root.fakeMaximizeTopRightAnimationRequested(priv.progress);
139+ onFakeMaximizeTopRightAnimationRequested: root.fakeMaximizeTopRightAnimationRequested(progress)
205− }
206− } else if (globalX < priv.triggerArea && globalY > stageHeight - priv.triggerArea) { // bottom left
207− if (target.canBeCornerMaximized) {
208− priv.progress = priv.progressInCorner(0, stageHeight, globalX, globalY);
209− priv.resetEdges();
210− priv.nearBottomLeftCorner = true;
211− root.fakeMaximizeBottomLeftAnimationRequested(priv.progress);
140+ onFakeMaximizeBottomLeftAnimationRequested: root.fakeMaximizeBottomLeftAnimationRequested(progress)
212− }
213− } else if (globalX > stageWidth - priv.triggerArea && globalY > stageHeight - priv.triggerArea) { // bottom right
214− if (target.canBeCornerMaximized) {
215− priv.progress = priv.progressInCorner(stageWidth, stageHeight, globalX, globalY);
216− priv.resetEdges();
217− priv.nearBottomRightCorner = true;
218− root.fakeMaximizeBottomRightAnimationRequested(priv.progress);
141+ onFakeMaximizeBottomRightAnimationRequested: root.fakeMaximizeBottomRightAnimationRequested(progress)
219− }
220− } else if (globalX < priv.triggerArea) { // left
221− if (target.canBeMaximizedLeftRight) {
222− priv.progress = MathUtils.clampAndProject(globalX, priv.triggerArea, 0, 0, 1);
223− priv.resetEdges();
224− priv.nearLeftEdge = true;
225− root.fakeMaximizeLeftAnimationRequested(priv.progress);
226− }
227− } else if (globalX > stageWidth - priv.triggerArea) { // right
228− if (target.canBeMaximizedLeftRight) {
229− priv.progress = MathUtils.clampAndProject(globalX, stageWidth - priv.triggerArea, stageWidth, 0, 1);
230− priv.resetEdges();
231− priv.nearRightEdge = true;
232− root.fakeMaximizeRightAnimationRequested(priv.progress);
233− }
234− } else if (globalY < PanelState.panelHeight) { // top
235− if (target.canBeMaximized) {
236− priv.progress = MathUtils.clampAndProject(globalY, Math.max(PanelState.panelHeight, priv.triggerArea), 0, 0, 1);
237− priv.resetEdges();
238− priv.nearTopEdge = true;
239− root.fakeMaximizeAnimationRequested(priv.progress);
240− }
241− } else if (priv.nearLeftEdge || priv.nearRightEdge || priv.nearTopEdge || priv.nearTopLeftCorner || priv.nearTopRightCorner ||
242− priv.nearBottomLeftCorner || priv.nearBottomRightCorner) {
243− print("!!! Exited")
244− priv.progress = 0;
245− priv.resetEdges();
246− root.stopFakeAnimation();
247− } else if (target.anyMaximized) {
248− priv.progress = 0;
249− target.restoreFromMaximized();
250− }
251− }
252− }
253− onReleased: {
254− print("Mouse released (left/top/right)", priv.nearLeftEdge, priv.nearTopEdge, priv.nearRightEdge)
255− if (mouse.button == Qt.LeftButton && (target.state == "normal" || target.state == "restored") && priv.progress == 0) {
256− priv.saveRestoredPos(target.x, target.y);
257− } else if (priv.progress < 0.3) { // cancel the preview shape if under 30%
258− priv.progress = 0;
259− priv.resetEdges();
260− root.stopFakeAnimation();
142+ onStopFakeAnimation: root.stopFakeAnimation()
261− } else if (priv.nearLeftEdge) {
262− target.maximizeLeft();
263− } else if (priv.nearTopEdge) {
264− target.maximize();
265− } else if (priv.nearRightEdge) {
266− target.maximizeRight();
267− } else if (priv.nearTopLeftCorner) {
268− target.maximizeTopLeft();
269− } else if (priv.nearTopRightCorner) {
270− target.maximizeTopRight();
271− } else if (priv.nearBottomLeftCorner) {
272− target.maximizeBottomLeft();
273− } else if (priv.nearBottomRightCorner) {
274− target.maximizeBottomRight();
275− }
276− }
277 }
143 }
278
144
279 // dismiss area
145 // dismiss area