-
Notifications
You must be signed in to change notification settings - Fork 7
/
ResizeWidget.qml
237 lines (202 loc) · 6.09 KB
/
ResizeWidget.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import QtQuick 2.4
import QtQuick.Window 2.2
Item {
property int enableSize: 4
property bool isPressed: false
property point customPoint
//color:"#00000000"
//opacity: 1
//radius: 20
//左上角
Item {
id: leftTop
width: enableSize
height: enableSize
anchors.left: parent.left
anchors.top: parent.top
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(1)
onReleased: release()
onPositionChanged: positionChange(mouse, -1, -1)
}
}
//Top
Item {
id: top
height: enableSize
anchors.left: leftTop.right
anchors.right: rightTop.left
anchors.top: parent.top
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(2)
onReleased: release()
onMouseYChanged: positionChange(Qt.point(customPoint.x, mouseY), 1, -1)
}
}
//右上角
Item {
id: rightTop
width: enableSize
height: enableSize
anchors.right: parent.right
anchors.top: parent.top
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(3)
onReleased: release()
onPositionChanged: positionChange(mouse, 1, -1)
}
}
//Left
Item {
id: left
width: enableSize
anchors.left: parent.left
anchors.top: leftTop.bottom
anchors.bottom: leftBottom.top
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(4)
onReleased: release()
onMouseXChanged: positionChange(Qt.point(mouseX, customPoint.y), -1, 1)
}
}
//Center - 5
Item {
id: center
anchors.left: left.right
anchors.right: right.left
anchors.top: top.bottom
anchors.bottom: bottom.top
MouseArea {
anchors.fill: parent
property point clickPos
onPressed: clickPos = Qt.point(mouse.x,mouse.y)
onPositionChanged: {
if(pressed && mainWindow.visibility !== Window.Maximized && mainWindow.visibility !== Window.FullScreen) {
var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
mainWindow.x += delta.x
mainWindow.y += delta.y
}
}
}
}
//Right
Item {
id: right
width: enableSize
anchors.right: parent.right
anchors.top: rightTop.bottom
anchors.bottom: rightBottom.top
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(6)
onReleased: release()
onMouseXChanged: positionChange(Qt.point(mouseX, customPoint.y), 1, 1)
}
}
//左下角
Item {
id: leftBottom
width: enableSize
height: enableSize
anchors.left: parent.left
anchors.bottom: parent.bottom
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(7)
onReleased: release()
onPositionChanged: positionChange(mouse, -1, 1)
}
}
//bottom
Item {
id: bottom
height: enableSize
anchors.left: leftBottom.right
anchors.right: rightBottom.left
anchors.bottom: parent.bottom
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(8)
onReleased: release()
onMouseYChanged: positionChange(Qt.point(customPoint.x, mouseY), 1, 1)
}
}
//右下角
Item {
id:rightBottom
width: enableSize
height: enableSize
anchors.right: parent.right
anchors.bottom: parent.bottom
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: press(mouse)
onEntered: enter(9)
onReleased: release()
onPositionChanged: positionChange(mouse,1,1)
}
}
function enter(direct) {
resize.setMyCursor(direct)
}
function press(mouse) {
isPressed = true
customPoint = Qt.point(mouse.x, mouse.y)
}
function release() {
isPressed = false
//customPoint = undefined
}
function positionChange(newPosition, directX, directY) { /*x轴方向*/ /*y轴方向*/
if(!isPressed) return
var delta = Qt.point(newPosition.x-customPoint.x, newPosition.y-customPoint.y)
var tmpW,tmpH
if(directX >= 0)
tmpW = mainWindow.width + delta.x
else
tmpW = mainWindow.width - delta.x
if(directY >= 0)
tmpH = mainWindow.height + delta.y
else
tmpH = mainWindow.height - delta.y
if(tmpW < mainWindow.minimumWidth) {
if(directX < 0)
mainWindow.x += (mainWindow.width - mainWindow.minimumWidth)
mainWindow.width = mainWindow.minimumWidth
}
else {
mainWindow.width = tmpW
if(directX < 0)
mainWindow.x += delta.x
}
if(tmpH < mainWindow.minimumHeight) {
if(directY < 0)
mainWindow.y += (mainWindow.height - mainWindow.minimumHeight)
mainWindow.height = mainWindow.minimumHeight
}
else {
mainWindow.height = tmpH
if(directY < 0)
mainWindow.y += delta.y
}
}
}