-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (66 loc) · 3.05 KB
/
main.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
package main
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/qml"
"github.com/therecipe/qt/quickcontrols2"
"os"
"sync"
)
type QmlBridge struct {
core.QObject
_ func(errmsg string) `signal:"error"`
_ func(jdType string, jdHost string, jdPort string, jdName string, jdUsername string, jdPassword string) `slot:"loadJobs"`
_ func(count int) `signal:"jobsLoaded"`
_ func(errmsg string) `signal:"errorLoadingJobs"`
_ func(c string, t string, j string, d string) `slot:"newJob"`
_ func(i int, c string, t string, j string, d string) `slot:"editJob"`
_ func(i int) `slot:"removeJob"`
_ func(cUrl string, cUsername string, cPassword string) `slot:"loadCustomers"`
_ func(count int, done int) `signal:"customersLoaded"`
_ func(errmsg string) `signal:"errorLoadingCustomers"`
_ func(l []string) `slot:"loadLabels"`
_ func(t string) `slot:"newLabel"`
_ func(i int, t string) `slot:"updateLabel"`
_ func(i int) `slot:"removeLabel"`
_ func() int `slot:"labelCount"`
_ func(t string) `slot:"copyText"`
}
var qmlBridge *QmlBridge
var customerModel *CustomerModel
var jobModel *JobModel
var labelModel *LabelModel
// dbMutex is for controlling DB access.
var dbMutex sync.Mutex
var app *gui.QGuiApplication
func main() {
qmlBridge = NewQmlBridge(nil)
customerModel = NewCustomerModel(nil)
jobModel = NewJobModel(nil)
labelModel = NewLabelModel(nil)
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
gui.NewQGuiApplication(len(os.Args), os.Args)
quickcontrols2.QQuickStyle_SetStyle("material")
view := qml.NewQQmlApplicationEngine(nil)
qmlBridge.ConnectLoadJobs(jobModel.loadJobsShim)
qmlBridge.ConnectNewJob(jobModel.newJobShim)
qmlBridge.ConnectEditJob(jobModel.editJobShim)
qmlBridge.ConnectRemoveJob(jobModel.removeJobShim)
qmlBridge.ConnectLoadCustomers(customerModel.loadCustomersShim)
qmlBridge.ConnectLoadLabels(labelModel.loadLabelsShim)
qmlBridge.ConnectNewLabel(labelModel.newLabelShim)
qmlBridge.ConnectUpdateLabel(labelModel.updateLabelShim)
qmlBridge.ConnectRemoveLabel(labelModel.removeLabelShim)
qmlBridge.ConnectLabelCount(labelModel.labelCount)
qmlBridge.ConnectCopyText(copyText)
view.RootContext().SetContextProperty("QmlBridge", qmlBridge)
view.RootContext().SetContextProperty("CustomerModel", customerModel)
view.RootContext().SetContextProperty("JobModel", jobModel)
view.RootContext().SetContextProperty("LabelModel", labelModel)
view.Load(core.NewQUrl3("qrc:///qml/main.qml", 0))
gui.QGuiApplication_Exec()
}
func copyText(t string) {
clipboard := app.Clipboard()
clipboard.SetText(t, gui.QClipboard__Clipboard)
}