79
78
// length of the triggerArea square diagonal
80
79
var diagLength = Math.sqrt(2 * priv.triggerArea * priv.triggerArea);
81
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
86
property real progress: 0
117
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
126
// Use integer coordinate values to ensure that target is left in a pixel-aligned
122
127
// position. Mouse movement could have subpixel precision, yielding a fractional
123
128
// mouse position.
124
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
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
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
136
priv.resetEdges();
132
137
priv.nearTopLeftCorner = true;
133
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
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
142
priv.resetEdges();
138
143
priv.nearTopRightCorner = true;
139
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
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
148
priv.resetEdges();
144
149
priv.nearBottomLeftCorner = true;
145
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
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
154
priv.resetEdges();
150
155
priv.nearBottomRightCorner = true;
151
156
root.fakeMaximizeBottomRightAnimationRequested(priv.progress);
154
159
priv.resetEdges();
155
160
priv.nearLeftEdge = true;
156
161
root.fakeMaximizeLeftAnimationRequested(priv.progress);
157
} else if (sensingPoints.right.x > stageWidth - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
158
priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, stageWidth - priv.triggerArea, stageWidth, 0, 1);
162
} else if (sensingPoints.right.x > bounds.right - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
163
priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, bounds.right - priv.triggerArea, bounds.right, 0, 1);
159
164
priv.resetEdges();
160
165
priv.nearRightEdge = true;
161
166
root.fakeMaximizeRightAnimationRequested(priv.progress);
162
} else if (sensingPoints.top.y < PanelState.panelHeight + priv.triggerArea && target.canBeMaximized) { // top
163
priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, PanelState.panelHeight + priv.triggerArea, 0, 0, 1);
167
} else if (sensingPoints.top.y < bounds.top + priv.triggerArea && target.canBeMaximized) { // top
168
priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, bounds.top + priv.triggerArea, 0, 0, 1);
164
169
priv.resetEdges();
165
170
priv.nearTopEdge = true;
166
171
root.fakeMaximizeAnimationRequested(priv.progress);