on xenial help sign in
fix resizing when making it smaller as minSize and then larger again
9d3a816Michael Zanetti
qml/Stages/WindowMoveResizeArea.qml+14−17
@@ -74,28 +74,24 @@ MouseArea {
74 var mouseDiff = Qt.point(currentPoint.x - priv.startPoint.x, currentPoint.y - priv.startPoint.y);
74 var mouseDiff = Qt.point(currentPoint.x - priv.startPoint.x, currentPoint.y - priv.startPoint.y);
75 var moveDiff = Qt.point(0, 0);
75 var moveDiff = Qt.point(0, 0);
76 var sizeDiff = Qt.point(0, 0);
76 var sizeDiff = Qt.point(0, 0);
77+ var maxSizeDiff = Qt.point(root.minWidth - root.target.width, root.minHeight - root.target.height)
78+
77 if (priv.resizeTop || priv.resizeBottom || priv.resizeLeft || priv.resizeRight) {
79 if (priv.resizeTop || priv.resizeBottom || priv.resizeLeft || priv.resizeRight) {
78 if (priv.resizeTop) {
80 if (priv.resizeTop) {
79− moveDiff.y += mouseDiff.y;
81+ sizeDiff.y = Math.max(maxSizeDiff.y, -currentPoint.y + priv.startPoint.y)
80− sizeDiff.y += -mouseDiff.y;
82+ moveDiff.y = -sizeDiff.y
81− } else if (priv.resizeBottom) {
82− sizeDiff.y += mouse.y - priv.startPoint.y;
83− priv.startPoint.y = mouse.y
84 }
83 }
85− if (priv.resizeLeft) {
84+ if (priv.resizeBottom) {
86− moveDiff.x += mouseDiff.x;
85+ sizeDiff.y = Math.max(maxSizeDiff.y, currentPoint.y - priv.startPoint.y)
87− sizeDiff.x += -mouseDiff.x;
86+ priv.startPoint.y += sizeDiff.y
88− } else if (priv.resizeRight) {
89− sizeDiff.x += mouse.x - priv.startPoint.x;
90− priv.startPoint.x = mouse.x
91 }
87 }
92− if (priv.windowWidth + sizeDiff.x < root.minWidth) {
88+ if (priv.resizeLeft) {
93− sizeDiff.x = root.minWidth - priv.windowWidth;
89+ sizeDiff.x = Math.max(maxSizeDiff.x, -currentPoint.x + priv.startPoint.x)
94− moveDiff.x = moveDiff.x == 0 ? 0 : -sizeDiff.x;
90+ moveDiff.x = -sizeDiff.x
95 }
91 }
96− if (priv.windowHeight + sizeDiff.y < root.minHeight) {
92+ if (priv.resizeRight) {
97− sizeDiff.y = root.minHeight - priv.windowHeight;
93+ sizeDiff.x = Math.max(maxSizeDiff.x, currentPoint.x - priv.startPoint.x)
98− moveDiff.y = moveDiff.y == 0 ? 0 : -sizeDiff.y;
94+ priv.startPoint.x += sizeDiff.x
99 }
95 }
100
96
101 target.x += moveDiff.x;
97 target.x += moveDiff.x;
@@ -106,6 +102,7 @@ MouseArea {
106 target.x += mouseDiff.x;
102 target.x += mouseDiff.x;
107 target.y += mouseDiff.y;
103 target.y += mouseDiff.y;
108 }
104 }
105+
109 }
106 }
110
107
111 onReleased: {
108 onReleased: {
tests/qmltests/Stages/tst_WindowMoveResizeArea.qml+25
@@ -193,5 +193,30 @@ Item {
193 tryCompare(fakeWindow, "width", Math.max(initialWindowWidth + resizeDelta, fakeWindow.minWidth));
193 tryCompare(fakeWindow, "width", Math.max(initialWindowWidth + resizeDelta, fakeWindow.minWidth));
194 tryCompare(fakeWindow, "height", Math.max(initialWindowHeight + resizeDelta, fakeWindow.minHeight));
194 tryCompare(fakeWindow, "height", Math.max(initialWindowHeight + resizeDelta, fakeWindow.minHeight));
195 }
195 }
196+
197+ // This tests if dragging smaller than minSize and then larger again, will keep the edge sticking
198+ // to the mouse, instead of immediately making the window grow again when switching direction
199+ function test_resizeSmallerAndLarger_data() {
200+ return [
201+ { tag: "topLeft", startX: -1, startY: -1, dx: units.gu(15), dy: units.gu(15) },
202+ { tag: "bottomRight", startX: fakeWindow.width + 1, startY: fakeWindow.height + 1, dx: -units.gu(15), dy: -units.gu(15) }
203+ ]
204+ }
205+
206+ function test_resizeSmallerAndLarger(data) {
207+ var initialWindowX = fakeWindow.x;
208+ var initialWindowY = fakeWindow.y;
209+ var initialWindowWidth = fakeWindow.width
210+ var initialWindowHeight = fakeWindow.height
211+
212+ var startDragX = initialWindowX + data.startX
213+ var startDragY = initialWindowY + data.startY
214+ mouseFlick(root, startDragX, startDragY, startDragX + data.dx, startDragY + data.dy, true, false, units.gu(.05), 10);
215+ tryCompare(fakeWindow, "width", Math.max(initialWindowWidth - Math.abs(data.dx), fakeWindow.minWidth));
216+ tryCompare(fakeWindow, "height", Math.max(initialWindowHeight - Math.abs(data.dy), fakeWindow.minHeight));
217+ mouseFlick(root, startDragX + data.dx, startDragY + data.dy, startDragX, startDragY, false, true, units.gu(.05), 10);
218+ tryCompare(fakeWindow, "width", initialWindowWidth);
219+ tryCompare(fakeWindow, "height", initialWindowHeight);
220+ }
196 }
221 }
197}
222}