@@ -36,6 +36,8 @@ MouseArea {
3636 property int borderThickness: 0
3737 property int minWidth: 0
3838 property int minHeight: 0
39+ property int defaultWidth: units.gu(60)
40+ property int defaultHeight: units.gu(50)
3941 property int screenWidth: 0
4042 property int screenHeight: 0
4143
@@ -67,13 +69,14 @@ MouseArea {
6769 }
6870
6971 Component.onCompleted: {
70− var windowGeometry = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height))
71− if (windowGeometry !== undefined) {
72− target.width = Math.min(windowGeometry.width, root.screenWidth)
73− target.height = Math.min(windowGeometry.height, root.screenHeight - PanelState.panelHeight)
74− target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.width), 0)
75− target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.height), PanelState.panelHeight)
76− }
72+ var windowGeometry = windowStateStorage.getGeometry(root.windowId,
73+ Qt.rect(target.x, target.y, defaultWidth, defaultHeight));
74+
75+ target.requestedWidth = Math.min(Math.max(windowGeometry.width, minWidth), screenWidth);
76+ target.requestedHeight = Math.min(Math.max(windowGeometry.height, minHeight), root.screenHeight - PanelState.panelHeight);
77+ target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.requestedWidth), 0)
78+ target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.requestedHeight), PanelState.panelHeight)
79+
7780 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
7881 if (windowState === WindowStateStorage.WindowStateMaximized) {
7982 target.maximize(false)
@@ -93,6 +96,18 @@ MouseArea {
9396 property bool topBorder: false
9497 property bool bottomBorder: false
9598
99+ // true - A change in surface size will cause the left border of the window to move accordingly.
100+ // The window's right border will stay in the same position.
101+ // false - a change in surface size will cause the right border of the window to move accordingly.
102+ // The window's left border will stay in the same position.
103+ property bool moveLeftBorder: false
104+
105+ // true - A change in surface size will cause the top border of the window to move accordingly.
106+ // The window's bottom border will stay in the same position.
107+ // false - a change in surface size will cause the bottom border of the window to move accordingly.
108+ // The window's top border will stay in the same position.
109+ property bool moveTopBorder: false
110+
96111 property bool dragging: false
97112 property real startMousePosX
98113 property real startMousePosY
@@ -100,6 +115,8 @@ MouseArea {
100115 property real startY
101116 property real startWidth
102117 property real startHeight
118+ property real currentWidth
119+ property real currentHeight
103120
104121 property string cursorName: {
105122 if (root.containsMouse || root.pressed) {
@@ -138,11 +155,24 @@ MouseArea {
138155 }
139156 }
140157
158+ Timer {
159+ id: resetBordersToMoveTimer
160+ interval: 2000
161+ onTriggered: {
162+ d.moveLeftBorder = false;
163+ d.moveTopBorder = false;
164+ }
165+ }
166+
141167 onPressedChanged: {
142168 var pos = mapToItem(target.parent, mouseX, mouseY);
143169
144170 if (pressed) {
145171 d.updateBorders();
172+ resetBordersToMoveTimer.stop();
173+ d.moveLeftBorder = d.leftBorder;
174+ d.moveTopBorder = d.topBorder;
175+
146176 var pos = mapToItem(root.target.parent, mouseX, mouseY);
147177 d.startMousePosX = pos.x;
148178 d.startMousePosY = pos.y;
@@ -150,8 +180,11 @@ MouseArea {
150180 d.startY = target.y;
151181 d.startWidth = target.width;
152182 d.startHeight = target.height;
183+ d.currentWidth = target.width;
184+ d.currentHeight = target.height;
153185 d.dragging = true;
154186 } else {
187+ resetBordersToMoveTimer.start();
155188 d.dragging = false;
156189 if (containsMouse) {
157190 d.updateBorders();
@@ -182,37 +215,49 @@ MouseArea {
182215 if (d.leftBorder) {
183216 var newTargetX = d.startX + deltaX;
184217 if (target.x + target.width > newTargetX + minWidth) {
185− target.width = target.x + target.width - newTargetX;
186− target.x = newTargetX;
218+ target.requestedWidth = target.x + target.width - newTargetX;
187219 } else {
188− target.x = target.x + target.width - minWidth;
189− target.width = minWidth;
220+ target.requestedWidth = minWidth;
190221 }
191222
192223 } else if (d.rightBorder) {
193224 if (d.startWidth + deltaX >= minWidth) {
194− target.width = d.startWidth + deltaX;
225+ target.requestedWidth = d.startWidth + deltaX;
195226 } else {
196− target.width = minWidth;
227+ target.requestedWidth = minWidth;
197228 }
198229 }
199230
200231 if (d.topBorder) {
201232 var newTargetY = d.startY + deltaY;
202233 if (target.y + target.height > newTargetY + minHeight) {
203− target.height = target.y + target.height - newTargetY;
204− target.y = newTargetY;
234+ target.requestedHeight = target.y + target.height - newTargetY;
205235 } else {
206− target.y = target.y + target.height - minHeight;
207− target.height = minHeight;
236+ target.requestedHeight = minHeight;
208237 }
209238
210239 } else if (d.bottomBorder) {
211240 if (d.startHeight + deltaY >= minHeight) {
212− target.height = d.startHeight + deltaY;
241+ target.requestedHeight = d.startHeight + deltaY;
213242 } else {
214− target.height = minHeight;
243+ target.requestedHeight = minHeight;
244+ }
245+ }
246+ }
247+
248+ Connections {
249+ target: root.target
250+ onWidthChanged: {
251+ if (d.moveLeftBorder) {
252+ target.x += d.currentWidth - target.width;
253+ }
254+ d.currentWidth = target.width;
255+ }
256+ onHeightChanged: {
257+ if (d.moveTopBorder) {
258+ target.y += d.currentHeight - target.height;
215259 }
260+ d.currentHeight = target.height;
216261 }
217262 }
218263}