-
Notifications
You must be signed in to change notification settings - Fork 363
/
ToastManager.qml
51 lines (45 loc) · 1.12 KB
/
ToastManager.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
import QtQuick 2.15
import Test 1.0
// 消息框管理
// 龚建波 2024-06-22
Item {
id: control
// 弹出新的消息时,信号通知已有的消息框上移
signal showNext()
property var toastArray: []
Component {
id: toast_comp
ToastItem {
id: toast_item
Connections {
target: control
function onShowNext() {
toast_item.next()
}
}
onClosing: {
toastArray.shift()
toast_item.destroy()
}
Component.onDestruction: {
console.log("onDestruction")
}
Component.onCompleted: {
console.log("onCompleted")
}
}
}
ScreenTool {
id: screen_tool
}
function showToast(msg) {
let rect = screen_tool.focusRect()
if (rect.width <= 0)
return
control.showNext()
let toast = toast_comp.createObject()
// 存起来避免被gc
toastArray.push(toast)
toast.pop(msg, rect)
}
}