@@ -19,15 +19,14 @@ import Unity.Application 0.1 // For Mir singleton
19import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
20import Utils 0.1
20import Utils 0.1
21import "../Components"
21import "../Components"
22−import "../Components/PanelState"
27 property Item target // appDelegate
26 property Item target // appDelegate
28− property int stageWidth
29− property int stageHeight
30 property real buttonsWidth: 0
27 property real buttonsWidth: 0
28+ property Item boundsItem
29+ property real boundsTopMargin: 0
32 readonly property bool dragging: priv.dragging
31 readonly property bool dragging: priv.dragging
@@ -79,7 +78,10 @@ QtObject {
79 // length of the triggerArea square diagonal
78 // length of the triggerArea square diagonal
80 var diagLength = Math.sqrt(2 * priv.triggerArea * priv.triggerArea);
79 var diagLength = Math.sqrt(2 * priv.triggerArea * priv.triggerArea);
81 var ratio = 1 - (distance / diagLength);
80 var ratio = 1 - (distance / diagLength);
82− return bx > 0 && bx <= stageWidth && by > 0 && by <= stageHeight ? ratio : 1; // everything "outside" of our square from the center is 1
82+ // everything "outside" of our square from the center is 1
83+ var mousePosBoundsCoords = target.mapToItem(root.boundsItem, bx, by);
84+ return root.boundsItem.contains(mousePosBoundsCoords) ? ratio : 1;
84 property real progress: 0
86 property real progress: 0
@@ -117,35 +119,38 @@ QtObject {
117 target.requestRestore();
119 target.requestRestore();
120− var pos = mapToItem(target.parent, mouse.x, mouse.y);
122+ var pos = mapToItem(target.parent, mouse.x, mouse.y); // How can that work if we're just a QtObject (not an Item)?
123+ var bounds = boundsItem.mapToItem(target.parent, 0, 0, boundsItem.width, boundsItem.height);
124+ bounds.y += boundsTopMargin;
125+ bounds.height -= boundsTopMargin;
121 // Use integer coordinate values to ensure that target is left in a pixel-aligned
126 // Use integer coordinate values to ensure that target is left in a pixel-aligned
122 // position. Mouse movement could have subpixel precision, yielding a fractional
127 // position. Mouse movement could have subpixel precision, yielding a fractional
123 // mouse position.
128 // mouse position.
124 target.windowedX = Math.round(pos.x - priv.distanceX);
129 target.windowedX = Math.round(pos.x - priv.distanceX);
125− target.windowedY = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
130+ target.windowedY = Math.round(Math.max(pos.y - priv.distanceY, bounds.top));
127 if (sensingPoints) { // edge/corner detection when dragging via the touch overlay
132 if (sensingPoints) { // edge/corner detection when dragging via the touch overlay
128− if (sensingPoints.topLeft.x < priv.triggerArea && sensingPoints.topLeft.y < PanelState.panelHeight + priv.triggerArea
133+ if (sensingPoints.topLeft.x < priv.triggerArea && sensingPoints.topLeft.y < bounds.top + priv.triggerArea
129 && target.canBeCornerMaximized) { // top left
134 && target.canBeCornerMaximized) { // top left
130− priv.progress = priv.progressInCorner(0, PanelState.panelHeight, sensingPoints.topLeft.x, sensingPoints.topLeft.y);
135+ priv.progress = priv.progressInCorner(bounds.left, bounds.top, sensingPoints.topLeft.x, sensingPoints.topLeft.y);
131 priv.resetEdges();
136 priv.resetEdges();
132 priv.nearTopLeftCorner = true;
137 priv.nearTopLeftCorner = true;
133 root.fakeMaximizeTopLeftAnimationRequested(priv.progress);
138 root.fakeMaximizeTopLeftAnimationRequested(priv.progress);
134− } else if (sensingPoints.topRight.x > stageWidth - priv.triggerArea && sensingPoints.topRight.y < PanelState.panelHeight + priv.triggerArea
139+ } else if (sensingPoints.topRight.x > bounds.right - priv.triggerArea && sensingPoints.topRight.y < bounds.top + priv.triggerArea
135 && target.canBeCornerMaximized) { // top right
140 && target.canBeCornerMaximized) { // top right
136− priv.progress = priv.progressInCorner(stageWidth, PanelState.panelHeight, sensingPoints.topRight.x, sensingPoints.topRight.y);
141+ priv.progress = priv.progressInCorner(bounds.right, bounds.top, sensingPoints.topRight.x, sensingPoints.topRight.y);
137 priv.resetEdges();
142 priv.resetEdges();
138 priv.nearTopRightCorner = true;
143 priv.nearTopRightCorner = true;
139 root.fakeMaximizeTopRightAnimationRequested(priv.progress);
144 root.fakeMaximizeTopRightAnimationRequested(priv.progress);
140− } else if (sensingPoints.bottomLeft.x < priv.triggerArea && sensingPoints.bottomLeft.y > stageHeight - priv.triggerArea
145+ } else if (sensingPoints.bottomLeft.x < priv.triggerArea && sensingPoints.bottomLeft.y > bounds.bottom - priv.triggerArea
141 && target.canBeCornerMaximized) { // bottom left
146 && target.canBeCornerMaximized) { // bottom left
142− priv.progress = priv.progressInCorner(0, stageHeight, sensingPoints.bottomLeft.x, sensingPoints.bottomLeft.y);
147+ priv.progress = priv.progressInCorner(bounds.left, bounds.bottom, sensingPoints.bottomLeft.x, sensingPoints.bottomLeft.y);
143 priv.resetEdges();
148 priv.resetEdges();
144 priv.nearBottomLeftCorner = true;
149 priv.nearBottomLeftCorner = true;
145 root.fakeMaximizeBottomLeftAnimationRequested(priv.progress);
150 root.fakeMaximizeBottomLeftAnimationRequested(priv.progress);
146− } else if (sensingPoints.bottomRight.x > stageWidth - priv.triggerArea && sensingPoints.bottomRight.y > stageHeight - priv.triggerArea
151+ } else if (sensingPoints.bottomRight.x > bounds.right - priv.triggerArea && sensingPoints.bottomRight.y > bounds.bottom - priv.triggerArea
147 && target.canBeCornerMaximized) { // bottom right
152 && target.canBeCornerMaximized) { // bottom right
148− priv.progress = priv.progressInCorner(stageWidth, stageHeight, sensingPoints.bottomRight.x, sensingPoints.bottomRight.y);
153+ priv.progress = priv.progressInCorner(bounds.right, bounds.bottom, sensingPoints.bottomRight.x, sensingPoints.bottomRight.y);
149 priv.resetEdges();
154 priv.resetEdges();
150 priv.nearBottomRightCorner = true;
155 priv.nearBottomRightCorner = true;
151 root.fakeMaximizeBottomRightAnimationRequested(priv.progress);
156 root.fakeMaximizeBottomRightAnimationRequested(priv.progress);
@@ -154,13 +159,13 @@ QtObject {
154 priv.resetEdges();
159 priv.resetEdges();
155 priv.nearLeftEdge = true;
160 priv.nearLeftEdge = true;
156 root.fakeMaximizeLeftAnimationRequested(priv.progress);
161 root.fakeMaximizeLeftAnimationRequested(priv.progress);
157− } else if (sensingPoints.right.x > stageWidth - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
162+ } else if (sensingPoints.right.x > bounds.right - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
158− priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, stageWidth - priv.triggerArea, stageWidth, 0, 1);
163+ priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, bounds.right - priv.triggerArea, bounds.right, 0, 1);
159 priv.resetEdges();
164 priv.resetEdges();
160 priv.nearRightEdge = true;
165 priv.nearRightEdge = true;
161 root.fakeMaximizeRightAnimationRequested(priv.progress);
166 root.fakeMaximizeRightAnimationRequested(priv.progress);
162− } else if (sensingPoints.top.y < PanelState.panelHeight + priv.triggerArea && target.canBeMaximized) { // top
167+ } else if (sensingPoints.top.y < bounds.top + priv.triggerArea && target.canBeMaximized) { // top
163− priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, PanelState.panelHeight + priv.triggerArea, 0, 0, 1);
168+ priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, bounds.top + priv.triggerArea, 0, 0, 1);
164 priv.resetEdges();
169 priv.resetEdges();
165 priv.nearTopEdge = true;
170 priv.nearTopEdge = true;
166 root.fakeMaximizeAnimationRequested(priv.progress);
171 root.fakeMaximizeAnimationRequested(priv.progress);