on xenial help sign in
fix resizing when making it smaller as minSize and then larger again
commit9d3a816206c9a51fdd6cd631f64bb5b54774de6a authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 6 Feb 2015, 12:21 (12 years ago) parent35cd0a3
2 files changed+39−17
qml/Stages/WindowMoveResizeArea.qml+14−17 tests/qmltests/Stages/tst_WindowMoveResizeArea.qml+25
qml/Stages/WindowMoveResizeArea.qml+14−17
@@ -74,28 +74,24 @@ MouseArea {
7474 var mouseDiff = Qt.point(currentPoint.x - priv.startPoint.x, currentPoint.y - priv.startPoint.y);
7575 var moveDiff = Qt.point(0, 0);
7676 var sizeDiff = Qt.point(0, 0);
77+ var maxSizeDiff = Qt.point(root.minWidth - root.target.width, root.minHeight - root.target.height)
78+
7779 if (priv.resizeTop || priv.resizeBottom || priv.resizeLeft || priv.resizeRight) {
7880 if (priv.resizeTop) {
79− moveDiff.y += mouseDiff.y;
80− sizeDiff.y += -mouseDiff.y;
81− } else if (priv.resizeBottom) {
82− sizeDiff.y += mouse.y - priv.startPoint.y;
83− priv.startPoint.y = mouse.y
81+ sizeDiff.y = Math.max(maxSizeDiff.y, -currentPoint.y + priv.startPoint.y)
82+ moveDiff.y = -sizeDiff.y
8483 }
85− if (priv.resizeLeft) {
86− moveDiff.x += mouseDiff.x;
87− sizeDiff.x += -mouseDiff.x;
88− } else if (priv.resizeRight) {
89− sizeDiff.x += mouse.x - priv.startPoint.x;
90− priv.startPoint.x = mouse.x
84+ if (priv.resizeBottom) {
85+ sizeDiff.y = Math.max(maxSizeDiff.y, currentPoint.y - priv.startPoint.y)
86+ priv.startPoint.y += sizeDiff.y
9187 }
92− if (priv.windowWidth + sizeDiff.x < root.minWidth) {
93− sizeDiff.x = root.minWidth - priv.windowWidth;
94− moveDiff.x = moveDiff.x == 0 ? 0 : -sizeDiff.x;
88+ if (priv.resizeLeft) {
89+ sizeDiff.x = Math.max(maxSizeDiff.x, -currentPoint.x + priv.startPoint.x)
90+ moveDiff.x = -sizeDiff.x
9591 }
96− if (priv.windowHeight + sizeDiff.y < root.minHeight) {
97− sizeDiff.y = root.minHeight - priv.windowHeight;
98− moveDiff.y = moveDiff.y == 0 ? 0 : -sizeDiff.y;
92+ if (priv.resizeRight) {
93+ sizeDiff.x = Math.max(maxSizeDiff.x, currentPoint.x - priv.startPoint.x)
94+ priv.startPoint.x += sizeDiff.x
9995 }
10096
10197 target.x += moveDiff.x;
@@ -106,6 +102,7 @@ MouseArea {
106102 target.x += mouseDiff.x;
107103 target.y += mouseDiff.y;
108104 }
105+
109106 }
110107
111108 onReleased: {
tests/qmltests/Stages/tst_WindowMoveResizeArea.qml+25
@@ -193,5 +193,30 @@ Item {
193193 tryCompare(fakeWindow, "width", Math.max(initialWindowWidth + resizeDelta, fakeWindow.minWidth));
194194 tryCompare(fakeWindow, "height", Math.max(initialWindowHeight + resizeDelta, fakeWindow.minHeight));
195195 }
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+ }
196221 }
197222}