-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaithtopimpl.go
93 lines (77 loc) · 1.66 KB
/
faithtopimpl.go
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
//go:build impl
package faithtop
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quickcontrols2"
"github.com/therecipe/qt/widgets"
"os"
)
type AppImpl struct {
app *widgets.QApplication
bridge *QtBridge
}
func init() {
appImpl = func() IApp {
v := &AppImpl{
app: widgets.NewQApplication(len(os.Args), os.Args),
}
v.bridge = NewQtBridge(v.app)
return v
}
}
func (a *AppImpl) Run() int {
return a.app.Exec()
}
func (a *AppImpl) Quit() {
a.app.Quit()
}
func (a *AppImpl) SetClipboardText(s string) IApp {
a.app.Clipboard().SetText(s, gui.QClipboard__Clipboard)
return a
}
func (a *AppImpl) GetClipboardText() string {
return a.app.Clipboard().Text(gui.QClipboard__Clipboard)
}
func (a *AppImpl) OnClipboardTextChanged(fn func(self IApp, s string)) IApp {
a.app.Clipboard().ConnectChanged(func(mode gui.QClipboard__Mode) {
if mode == gui.QClipboard__Clipboard {
fn(a, a.GetClipboardText())
}
})
return a
}
func (a *AppImpl) SetQuickStyle(quickStyle QuickStyle) {
quickcontrols2.QQuickStyle_SetStyle(string(quickStyle))
}
func (a *AppImpl) SetQuitOnLastWindowClosed(b bool) IApp {
a.app.SetQuitOnLastWindowClosed(b)
return a
}
func (a *AppImpl) RunOnUIThread(fn func()) {
a.bridge.RunOnUIThread(fn)
}
//bridge
type QtBridge struct {
core.QObject
_ func() `constructor:"init"`
_ func() `signal:"runInMainThread,auto"`
ch chan func()
}
func (b *QtBridge) init() {
b.ch = make(chan func(), 12)
}
func (b *QtBridge) runInMainThread() {
select {
case fn, ok := <-b.ch:
if !ok {
return
}
fn()
default:
}
}
func (b *QtBridge) RunOnUIThread(fn func()) {
b.ch <- fn
b.RunInMainThread()
}