-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopBar.qml
246 lines (235 loc) · 6.92 KB
/
TopBar.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
238
239
240
241
242
243
244
245
246
import QtQuick 2.14
import QtQuick.Window 2.14
Rectangle {
id: bar
MouseArea {
id: moveBarArea
anchors{
top: parent.top
right: minimalize.left
left: parent.left
bottom: parent.bottom
}
function maximalizeFunc(protect) {
window.maximalized = !window.maximalized
if(protect === true) {
moveProtector.protect = true
moveProtector.restart()
}
if(window.maximalized){
window.showMaximized()
}
else{
window.showNormal()
}
}
Timer {
id: moveProtector
property bool protect: false
property real len
property int ycoord
property point abs
interval: 1; running: false; repeat: false
onTriggered: {
protect = false //normal protect
if(len > 0) { //scale protect
var xcoord = Math.floor(abs.x - (moveBarArea.width*len))
startWindowPos = Qt.point(xcoord, ycoord)
startWindowSize = Qt.size(window.width, window.height)
startMousePos = abs
window.x = xcoord
window.y = ycoord
}
len = 0
}
}
onDoubleClicked: maximalizeFunc(true)
onPressed: {
startMousePos = absoluteMousePos(this)
startWindowPos = Qt.point(window.x, window.y)
startWindowSize = Qt.size(window.width, window.height)
}
onMouseXChanged:{
if(pressed && !window.maximalized && !moveProtector.protect) {
var abs = absoluteMousePos(this)
window.x = startWindowPos.x + (abs.x - startMousePos.x)
}
}
onMouseYChanged: {
if(pressed && !moveProtector.protect) {
var abs = absoluteMousePos(this)
window.y = Math.max(Screen.virtualY, startWindowPos.y + (abs.y - startMousePos.y))
if( window.y < Screen.virtualY + 1 && !window.maximalized )
maximalizeFunc(true)
if( window.y > Screen.virtualY && window.maximalized ) {
var xcoord = mouseX/moveBarArea.width;
maximalizeFunc(false)
moveProtector.len = xcoord
moveProtector.abs = abs
moveProtector.ycoord = abs.y - mouseY
moveProtector.protect = true
moveProtector.start()
}
}
}
}
Rectangle {
id: close
color: "transparent"
width: 45
anchors{
right: parent.right
top: parent.top
}
height: parent.height
Rectangle {
color: "white"
rotation: -45
transformOrigin: Item.Center
anchors.centerIn: parent
height: parent.height - 7
width: 2.5
}
Rectangle {
color: "white"
rotation: 45
transformOrigin: Item.Center
anchors.centerIn: parent
height: parent.height - 7
width: 2.5
}
MouseArea {
anchors.fill: parent
hoverEnabled: true;
onEntered: parent.color = "tomato"
onExited: parent.color = "transparent"
onClicked: Qt.quit()
onPressed: parent.opacity = 0.6
onReleased: parent.opacity = 1
}
Behavior on color {
ColorAnimation { duration: 200 }
}
Behavior on opacity {
OpacityAnimator { duration: 100 }
}
}
Rectangle {
id: maximalize;
color: bar.color
anchors{
right: close.left
top: parent.top
}
height: parent.height
width: 35
Rectangle {
id: max;
visible: !window.maximalized
anchors {
fill: parent
margins: 7
}
color: "transparent"
border{
color: "white"
width: 1
}
}
Rectangle {
id: min;
visible: window.maximalized
anchors {
fill: maximalize
leftMargin: 7
rightMargin: 9
topMargin: 9
bottomMargin: 7
}
color: "transparent"
border{
color: "white"
width: 1
}
Rectangle {
visible: window.maximalized
anchors {
top: parent.top
right: parent.right
topMargin: -3
rightMargin: -3
}
color: "white"
height: 1
width: parent.width
}
Rectangle {
visible: window.maximalized
anchors {
top: parent.top
right: parent.right
topMargin: -3
rightMargin: -3
}
color: "white"
height: parent.height
width: 1
}
}
MouseArea {
id: maximalizator
anchors.fill: parent
hoverEnabled: true;
onEntered: maximalize.color = "skyblue"
onExited: maximalize.color = bar.color
onPressed: parent.opacity = 0.6
onReleased: parent.opacity = 1
onClicked: {
window.maximalized = !window.maximalized
if(window.maximalized){
window.showMaximized()
}
else{
window.showNormal()
}
}
}
Behavior on color {
ColorAnimation { duration: 200 }
}
Behavior on opacity {
OpacityAnimator { duration: 100 }
}
}
Rectangle {
id: minimalize
color: "transparent"
anchors{
right: maximalize.left
top: parent.top
}
height: parent.height
width: 35
Rectangle {
anchors.centerIn: parent
height: 2
width: 15
color: "white"
}
MouseArea {
anchors.fill: parent
hoverEnabled: true;
onEntered: parent.color = "skyblue"
onExited: parent.color = "transparent"
onPressed: parent.opacity = 0.6
onReleased: parent.opacity = 1
onClicked: window.showMinimized()
}
Behavior on color {
ColorAnimation { duration: 200 }
}
Behavior on opacity {
OpacityAnimator { duration: 100 }
}
}
}