@@ -36,6 +36,8 @@ MouseArea {
36 property int borderThickness: 0
36 property int borderThickness: 0
37 property int minWidth: 0
37 property int minWidth: 0
38 property int minHeight: 0
38 property int minHeight: 0
39+ property int defaultWidth: units.gu(60)
40+ property int defaultHeight: units.gu(50)
39 property int screenWidth: 0
41 property int screenWidth: 0
40 property int screenHeight: 0
42 property int screenHeight: 0
@@ -67,13 +69,14 @@ MouseArea {
69 Component.onCompleted: {
71 Component.onCompleted: {
70− var windowGeometry = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height))
72+ var windowGeometry = windowStateStorage.getGeometry(root.windowId,
71− if (windowGeometry !== undefined) {
73+ Qt.rect(target.x, target.y, defaultWidth, defaultHeight));
72− target.width = Math.min(windowGeometry.width, root.screenWidth)
75+ target.requestedWidth = Math.min(Math.max(windowGeometry.width, minWidth), screenWidth);
73− target.height = Math.min(windowGeometry.height, root.screenHeight - PanelState.panelHeight)
76+ target.requestedHeight = Math.min(Math.max(windowGeometry.height, minHeight), root.screenHeight - PanelState.panelHeight);
74− target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.width), 0)
77+ target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.requestedWidth), 0)
75− target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.height), PanelState.panelHeight)
78+ target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.requestedHeight), PanelState.panelHeight)
77 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
80 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
78 if (windowState === WindowStateStorage.WindowStateMaximized) {
81 if (windowState === WindowStateStorage.WindowStateMaximized) {
79 target.maximize(false)
82 target.maximize(false)
@@ -93,6 +96,18 @@ MouseArea {
93 property bool topBorder: false
96 property bool topBorder: false
94 property bool bottomBorder: false
97 property bool bottomBorder: false
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
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
96 property bool dragging: false
111 property bool dragging: false
97 property real startMousePosX
112 property real startMousePosX
98 property real startMousePosY
113 property real startMousePosY
@@ -100,6 +115,8 @@ MouseArea {
100 property real startY
115 property real startY
101 property real startWidth
116 property real startWidth
102 property real startHeight
117 property real startHeight
118+ property real currentWidth
119+ property real currentHeight
104 property string cursorName: {
121 property string cursorName: {
105 if (root.containsMouse || root.pressed) {
122 if (root.containsMouse || root.pressed) {
@@ -138,11 +155,24 @@ MouseArea {
159+ id: resetBordersToMoveTimer
162+ d.moveLeftBorder = false;
163+ d.moveTopBorder = false;
141 onPressedChanged: {
167 onPressedChanged: {
142 var pos = mapToItem(target.parent, mouseX, mouseY);
168 var pos = mapToItem(target.parent, mouseX, mouseY);
144 if (pressed) {
170 if (pressed) {
145 d.updateBorders();
171 d.updateBorders();
172+ resetBordersToMoveTimer.stop();
173+ d.moveLeftBorder = d.leftBorder;
174+ d.moveTopBorder = d.topBorder;
146 var pos = mapToItem(root.target.parent, mouseX, mouseY);
176 var pos = mapToItem(root.target.parent, mouseX, mouseY);
147 d.startMousePosX = pos.x;
177 d.startMousePosX = pos.x;
148 d.startMousePosY = pos.y;
178 d.startMousePosY = pos.y;
@@ -150,8 +180,11 @@ MouseArea {
150 d.startY = target.y;
180 d.startY = target.y;
151 d.startWidth = target.width;
181 d.startWidth = target.width;
152 d.startHeight = target.height;
182 d.startHeight = target.height;
183+ d.currentWidth = target.width;
184+ d.currentHeight = target.height;
153 d.dragging = true;
185 d.dragging = true;
187+ resetBordersToMoveTimer.start();
155 d.dragging = false;
188 d.dragging = false;
156 if (containsMouse) {
189 if (containsMouse) {
157 d.updateBorders();
190 d.updateBorders();
@@ -182,37 +215,49 @@ MouseArea {
182 if (d.leftBorder) {
215 if (d.leftBorder) {
183 var newTargetX = d.startX + deltaX;
216 var newTargetX = d.startX + deltaX;
184 if (target.x + target.width > newTargetX + minWidth) {
217 if (target.x + target.width > newTargetX + minWidth) {
185− target.width = target.x + target.width - newTargetX;
218+ target.requestedWidth = target.x + target.width - newTargetX;
186− target.x = newTargetX;
188− target.x = target.x + target.width - minWidth;
220+ target.requestedWidth = minWidth;
189− target.width = minWidth;
192 } else if (d.rightBorder) {
223 } else if (d.rightBorder) {
193 if (d.startWidth + deltaX >= minWidth) {
224 if (d.startWidth + deltaX >= minWidth) {
194− target.width = d.startWidth + deltaX;
225+ target.requestedWidth = d.startWidth + deltaX;
196− target.width = minWidth;
227+ target.requestedWidth = minWidth;
200 if (d.topBorder) {
231 if (d.topBorder) {
201 var newTargetY = d.startY + deltaY;
232 var newTargetY = d.startY + deltaY;
202 if (target.y + target.height > newTargetY + minHeight) {
233 if (target.y + target.height > newTargetY + minHeight) {
203− target.height = target.y + target.height - newTargetY;
234+ target.requestedHeight = target.y + target.height - newTargetY;
204− target.y = newTargetY;
206− target.y = target.y + target.height - minHeight;
236+ target.requestedHeight = minHeight;
207− target.height = minHeight;
210 } else if (d.bottomBorder) {
239 } else if (d.bottomBorder) {
211 if (d.startHeight + deltaY >= minHeight) {
240 if (d.startHeight + deltaY >= minHeight) {
212− target.height = d.startHeight + deltaY;
241+ target.requestedHeight = d.startHeight + deltaY;
214− target.height = minHeight;
243+ target.requestedHeight = minHeight;
251+ if (d.moveLeftBorder) {
252+ target.x += d.currentWidth - target.width;
254+ d.currentWidth = target.width;
257+ if (d.moveTopBorder) {
258+ target.y += d.currentHeight - target.height;
260+ d.currentHeight = target.height;