~mzanetti/unity8/fix-1648251

« back to all changes in this revision

Viewing changes to qml/Stages/WindowControlsOverlay.qml

  • Committer: Michael Zanetti
  • Date: 2016-10-13 11:02:11 UTC
  • mfrom: (2525.1.132 unity8)
  • Revision ID: michael.zanetti@canonical.com-20161013110211-tj2gly2dxaqj5t2e
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
Item {
24
24
    id: root
25
25
    enabled: target && !target.fullscreen
 
26
    anchors.fill: target
26
27
 
27
28
    // to be set from outside
28
29
    property Item target // appDelegate
 
30
    property alias stageWidth: moveHandler.stageWidth
 
31
    property alias stageHeight: moveHandler.stageHeight
29
32
 
30
33
    // to be read from outside
31
34
    readonly property alias overlayShown: overlay.visible
 
35
    readonly property alias dragging: priv.dragging
 
36
 
 
37
    signal fakeMaximizeAnimationRequested(real amount)
 
38
    signal fakeMaximizeLeftAnimationRequested(real amount)
 
39
    signal fakeMaximizeRightAnimationRequested(real amount)
 
40
    signal fakeMaximizeTopLeftAnimationRequested(real amount)
 
41
    signal fakeMaximizeTopRightAnimationRequested(real amount)
 
42
    signal fakeMaximizeBottomLeftAnimationRequested(real amount)
 
43
    signal fakeMaximizeBottomRightAnimationRequested(real amount)
 
44
    signal stopFakeAnimation()
 
45
    signal dragReleased()
32
46
 
33
47
    TouchGestureArea {
34
48
        id: gestureArea
51
65
        readonly property bool recognizedDrag: recognizedPress && dragging
52
66
        onRecognizedDragChanged: {
53
67
            if (recognizedDrag) {
54
 
                priv.handlePressedChanged(true, tp.x, tp.y);
55
 
            } else if (!moveHandler.containsPress) { // prevent interfering with the central piece drag/move
56
 
                priv.dragging = false;
 
68
                moveHandler.handlePressedChanged(true, Qt.LeftButton, tp.x, tp.y);
 
69
            } else if (!mouseArea.containsPress) { // prevent interfering with the central piece drag/move
 
70
                moveHandler.handlePressedChanged(false, Qt.LeftButton);
 
71
                root.dragReleased();
 
72
                moveHandler.handleReleased(true);
57
73
            }
58
74
        }
59
75
 
60
76
        readonly property point tp: recognizedPress ? Qt.point(touchPoints[0].x, touchPoints[0].y) : Qt.point(-1, -1)
61
77
        onUpdated: {
62
78
            if (recognizedDrag) {
63
 
                priv.handlePositionChanged(tp.x, tp.y);
 
79
                moveHandler.handlePositionChanged(tp, priv.getSensingPoints());
64
80
            }
65
81
        }
66
82
    }
69
85
    Timer {
70
86
        id: overlayTimer
71
87
        interval: 2000
72
 
        repeat: priv.dragging || (priv.resizeArea && priv.resizeArea.dragging)
 
88
        repeat: priv.dragging
73
89
    }
74
90
 
75
91
    QtObject {
76
92
        id: priv
77
 
        property real distanceX
78
 
        property real distanceY
79
 
        property bool dragging
80
 
 
81
93
        readonly property var resizeArea: root.target && root.target.resizeArea ? root.target.resizeArea : null
 
94
        readonly property bool ensureWindow: root.target.state == "normal" || root.target.state == "restored"
 
95
        readonly property bool dragging: moveHandler.dragging || (resizeArea && resizeArea.dragging)
82
96
 
83
 
        function handlePressedChanged(pressed, mouseX, mouseY) {
84
 
            if (pressed) {
85
 
                var pos = mapToItem(root.target, mouseX, mouseY);
86
 
                priv.distanceX = pos.x;
87
 
                priv.distanceY = pos.y;
88
 
                priv.dragging = true;
89
 
            } else {
90
 
                priv.dragging = false;
 
97
        function getSensingPoints() {
 
98
            var xPoints = [];
 
99
            var yPoints = [];
 
100
            for (var i = 0; i < gestureArea.touchPoints.length; i++) {
 
101
                var pt = gestureArea.touchPoints[i];
 
102
                xPoints.push(pt.x);
 
103
                yPoints.push(pt.y);
91
104
            }
92
 
        }
93
 
 
94
 
        function handlePositionChanged(mouseX, mouseY) {
95
 
            if (priv.dragging) {
96
 
                var pos = mapToItem(root.target.parent, mouseX, mouseY);
97
 
                root.target.requestedX = Math.round(pos.x - priv.distanceX);
98
 
                root.target.requestedY = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
 
105
 
 
106
            var leftmost = Math.min.apply(Math, xPoints);
 
107
            var rightmost = Math.max.apply(Math, xPoints);
 
108
            var topmost = Math.min.apply(Math, yPoints);
 
109
            var bottommost = Math.max.apply(Math, yPoints);
 
110
 
 
111
            return {
 
112
                left: mapToItem(target.parent, leftmost, (topmost+bottommost)/2),
 
113
                top: mapToItem(target.parent, (leftmost+rightmost)/2, topmost),
 
114
                right: mapToItem(target.parent, rightmost, (topmost+bottommost)/2),
 
115
                topLeft: mapToItem(target.parent, leftmost, topmost),
 
116
                topRight: mapToItem(target.parent, rightmost, topmost),
 
117
                bottomLeft: mapToItem(target.parent, leftmost, bottommost),
 
118
                bottomRight: mapToItem(target.parent, rightmost, bottommost)
99
119
            }
100
120
        }
101
121
    }
113
133
            UbuntuNumberAnimation {}
114
134
        }
115
135
 
116
 
        readonly property bool anyMaximized: target && (target.maximized || target.maximizedLeft || target.maximizedRight)
117
 
 
118
136
        Image {
119
137
            source: "graphics/arrows-centre.png"
120
138
            width: units.gu(10)
125
143
 
126
144
            // move handler
127
145
            MouseArea {
 
146
                id: mouseArea
 
147
                anchors.fill: parent
 
148
                visible: overlay.visible
 
149
                enabled: visible
 
150
                hoverEnabled: true
 
151
 
 
152
                onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
 
153
                onPositionChanged: moveHandler.handlePositionChanged(mouse)
 
154
                onReleased: {
 
155
                    root.dragReleased();
 
156
                    moveHandler.handleReleased();
 
157
                }
 
158
            }
 
159
 
 
160
            MoveHandler {
128
161
                id: moveHandler
129
 
                anchors.fill: parent
130
 
                visible: overlay.visible
131
 
                enabled: visible
132
 
                hoverEnabled: true
133
 
                cursorShape: priv.dragging ? Qt.ClosedHandCursor : (overlay.visible ? Qt.OpenHandCursor : Qt.ArrowCursor)
 
162
                objectName: "moveHandler"
 
163
                target: root.target
134
164
 
135
 
                onPressedChanged: priv.handlePressedChanged(pressed, mouseX, mouseY)
136
 
                onPositionChanged: priv.handlePositionChanged(mouseX, mouseY)
 
165
                onFakeMaximizeAnimationRequested: root.fakeMaximizeAnimationRequested(amount)
 
166
                onFakeMaximizeLeftAnimationRequested: root.fakeMaximizeLeftAnimationRequested(amount)
 
167
                onFakeMaximizeRightAnimationRequested: root.fakeMaximizeRightAnimationRequested(amount)
 
168
                onFakeMaximizeTopLeftAnimationRequested: root.fakeMaximizeTopLeftAnimationRequested(amount)
 
169
                onFakeMaximizeTopRightAnimationRequested: root.fakeMaximizeTopRightAnimationRequested(amount)
 
170
                onFakeMaximizeBottomLeftAnimationRequested: root.fakeMaximizeBottomLeftAnimationRequested(amount)
 
171
                onFakeMaximizeBottomRightAnimationRequested: root.fakeMaximizeBottomRightAnimationRequested(amount)
 
172
                onStopFakeAnimation: root.stopFakeAnimation()
137
173
            }
138
174
 
139
175
            // dismiss area
148
184
                    }
149
185
 
150
186
                    overlayTimer.stop();
151
 
                    mouse.accepted = root.contains(Qt.point(mouse.x, mouse.y));
 
187
                    mouse.accepted = root.contains(mapToItem(root.target, mouse.x, mouse.y));
152
188
                }
153
189
                propagateComposedEvents: true
154
190
            }
157
193
        ResizeGrip { // top left
158
194
            anchors.horizontalCenter: parent.left
159
195
            anchors.verticalCenter: parent.top
160
 
            visible: target && !overlay.anyMaximized && !target.maximizedHorizontally && !target.maximizedVertically
 
196
            visible: priv.ensureWindow || target.maximizedBottomRight
161
197
            resizeTarget: priv.resizeArea
162
198
        }
163
199
 
165
201
            anchors.horizontalCenter: parent.horizontalCenter
166
202
            anchors.verticalCenter: parent.top
167
203
            rotation: 45
168
 
            visible: target && !overlay.anyMaximized && !target.maximizedVertically
 
204
            visible: priv.ensureWindow || target.maximizedHorizontally || target.maximizedBottomLeft || target.maximizedBottomRight
169
205
            resizeTarget: priv.resizeArea
170
206
        }
171
207
 
173
209
            anchors.horizontalCenter: parent.right
174
210
            anchors.verticalCenter: parent.top
175
211
            rotation: 90
176
 
            visible: target && !overlay.anyMaximized && !target.maximizedHorizontally && !target.maximizedVertically
 
212
            visible: priv.ensureWindow || target.maximizedBottomLeft
177
213
            resizeTarget: priv.resizeArea
178
214
        }
179
215
 
181
217
            anchors.horizontalCenter: parent.right
182
218
            anchors.verticalCenter: parent.verticalCenter
183
219
            rotation: 135
184
 
            visible: target && !target.maximizedRight && !target.maximized && !target.maximizedHorizontally
 
220
            visible: priv.ensureWindow || target.maximizedVertically || target.maximizedLeft ||
 
221
                     target.maximizedTopLeft || target.maximizedBottomLeft
185
222
            resizeTarget: priv.resizeArea
186
223
        }
187
224
 
188
225
        ResizeGrip { // bottom right
189
226
            anchors.horizontalCenter: parent.right
190
227
            anchors.verticalCenter: parent.bottom
191
 
            visible: target && !overlay.anyMaximized && !target.maximizedHorizontally && !target.maximizedVertically
 
228
            visible: priv.ensureWindow || target.maximizedTopLeft
192
229
            resizeTarget: priv.resizeArea
193
230
        }
194
231
 
196
233
            anchors.horizontalCenter: parent.horizontalCenter
197
234
            anchors.verticalCenter: parent.bottom
198
235
            rotation: 45
199
 
            visible: target && !overlay.anyMaximized && !target.maximizedVertically
 
236
            visible: priv.ensureWindow || target.maximizedHorizontally || target.maximizedTopLeft || target.maximizedTopRight
200
237
            resizeTarget: priv.resizeArea
201
238
        }
202
239
 
204
241
            anchors.horizontalCenter: parent.left
205
242
            anchors.verticalCenter: parent.bottom
206
243
            rotation: 90
207
 
            visible: target && !overlay.anyMaximized && !target.maximizedHorizontally && !target.maximizedVertically
 
244
            visible: priv.ensureWindow || target.maximizedTopRight
208
245
            resizeTarget: priv.resizeArea
209
246
        }
210
247
 
212
249
            anchors.horizontalCenter: parent.left
213
250
            anchors.verticalCenter: parent.verticalCenter
214
251
            rotation: 135
215
 
            visible: target && !target.maximizedLeft && !target.maximized && !target.maximizedHorizontally
 
252
            visible: priv.ensureWindow || target.maximizedVertically || target.maximizedRight ||
 
253
                     target.maximizedTopRight || target.maximizedBottomRight
216
254
            resizeTarget: priv.resizeArea
217
255
        }
218
256
    }