-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.qml
More file actions
263 lines (221 loc) · 6.45 KB
/
Copy pathMain.qml
File metadata and controls
263 lines (221 loc) · 6.45 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import QtQuick
import QtQuick.Controls
import Qt.labs.platform
Window {
id: mainWindow
width: 1400
height: 60
visible: true
title: qsTr("Hello World")
flags: Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
color: "transparent"
x: (Screen.width - width) / 2
y: Screen.height - 100
property int timerCounter: 0
property bool windowIsHidden: false
Window {
id: hideBar
width: 200
height: 5
visible: true
flags: Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x: (Screen.width - width) / 2
y: (Screen.height - 12)
color: "transparent"
Rectangle {
anchors.fill: parent
color: "white"
opacity: 0.5
radius: 7
MouseArea {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton
onEntered: {
hideBar.width = 250
hideBar.height = 10
if (windowIsHidden) {
enterAnimation.start()
windowIsHidden = false
}
}
onExited: {
hideBar.width = 200
hideBar.height = 5
// 此时再启动定时器,使得鼠标位于横条上时程序坞不会消失
mainTimer.start()
}
}
}
}
Timer {
id: mainTimer
interval: 1000
running: true
repeat: true
onTriggered: {
timerCounter += 1
if (timerCounter === 5) {
exitAnimation.start()
mainTimer.stop()
windowIsHidden = true
timerCounter = 0
}
}
}
NumberAnimation {
id: enterAnimation
target: mainWindow
properties: "y"
from: Screen.height
to: Screen.height - 100
duration: 300
}
NumberAnimation {
id: exitAnimation
target: mainWindow
properties: "y"
from: Screen.height - 100
to: Screen.height
duration: 300
}
SystemTrayIcon {
id: trayIcon
icon.source: "qrc:/resource/microsoft.png"
menu: trayMenu
visible: true
}
Menu {
id: trayMenu
MenuItem {
text: "设置"
onTriggered: {
var settingWindow = Qt.createComponent("SettingWindow.qml")
if (settingWindow.status === Component.Ready) {
var windowInstance = settingWindow.createObject();
// 获取屏幕宽度和高度
var screenWidth = Screen.width;
var screenHeight = Screen.height;
// 设置新窗口居中显示
windowInstance.x = (screenWidth - windowInstance.width) / 2;
windowInstance.y = (screenHeight - windowInstance.height) / 2;
}
}
}
MenuSeparator{}
MenuItem {
text: "显示 / 隐藏"
onTriggered: {
if (mainWindow.visible) {
mainWindow.hide()
} else {
mainWindow.show()
}
}
}
MenuItem {
text: "重启"
}
MenuItem {
text: "退出"
onTriggered: {
Qt.quit()
}
}
}
Rectangle {
anchors.fill: parent
radius: 15
color: "white"
opacity: 0.5
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton
property bool mouseIsPressed: false
property int myMouseX: 0
property int myMouseY: 0
property int offsetX: 0
property int offsetY: 0
onEntered: function(mouse) {
timerCounter = 0
}
onPressed: function(mouse) {
cursorShape = Qt.SizeAllCursor
mouseIsPressed = true
myMouseX = mouse.x
myMouseY = mouse.y
}
onReleased: function(mouse) {
cursorShape = Qt.ArrowCursor
mouseIsPressed = false
}
onPositionChanged: {
if (mouseIsPressed) {
offsetX = mouse.x - myMouseX
offsetY = mouse.y - myMouseY
mainWindow.x += offsetX
mainWindow.y += offsetY
myMouseX = mouse.x
myMouseY = mouse.y
}
}
}
}
Row {
id: userProgramArea
width: 0.8 * parent.width
height: parent.height
anchors.left: parent.left
anchors.leftMargin: 15
anchors.rightMargin: 15
spacing: 11
Repeater {
id: userPrograms
model: UserDataModel
delegate: ProgramComponent {
programName: NameRole
programIcon: "file:./icon/" + IconRole
opacity: 1
onItemLeftClicked: {
UserDataModel.execProgram(index, [])
}
onFileDraggedin: function(fileUrlList) {
UserDataModel.execProgram(index, fileUrlList)
}
}
}
}
Rectangle {
id: divider
width: 1
height: 0.7 * parent.height
anchors.left: userProgramArea.right
anchors.verticalCenter: parent.verticalCenter
color: "white"
}
Row {
id: systemProgramArea
height: parent.height
anchors.right: parent.right
anchors.leftMargin: 15
anchors.rightMargin: 15
spacing: 10
Repeater {
id: systemPrograms
model: SystemDataModel
delegate: ProgramComponent {
programName: NameRole
programIcon: "file:./icon/" + IconRole
opacity: 1
onItemLeftClicked: {
SystemDataModel.execProgram(index, [])
}
onFileDraggedin: function(fileUrlList) {
// SystemDataModel.execProgram(index, fileUrlList)
}
}
}
}
}