-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenubarimpl.go
104 lines (89 loc) · 1.95 KB
/
menubarimpl.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
94
95
96
97
98
99
100
101
102
103
104
//go:build impl
package faithtop
import "github.com/therecipe/qt/widgets"
type (
MenuBarImpl struct {
menubar *widgets.QMenuBar
}
MenuImpl struct {
menu *widgets.QMenu
}
ActionImpl struct {
action *widgets.QAction
}
)
func init() {
newMenuBarImpl = func() IMenuBar {
return &MenuBarImpl{
menubar: widgets.NewQMenuBar(nil),
}
}
newMenuImpl = func() IMenu {
return &MenuImpl{
menu: widgets.NewQMenu(nil),
}
}
newActionImpl = func(text string) IAction {
return &ActionImpl{
action: widgets.NewQAction2(text, nil),
}
}
showPopupMenuImpl = func(win IWindow, anchor IWidget, menu IMenu) {
target := anchor.getWidget().(*WidgetImpl).widget
pos := target.MapToGlobal(win.(*WindowImpl).window.CentralWidget().Pos())
pos.SetY(pos.Y() + target.Height())
menu.(*MenuImpl).menu.Exec2(pos, nil)
}
}
func (m *MenuBarImpl) Menus(menus ...IMenu) IMenuBar {
for _, menu := range menus {
m.menubar.AddMenu(menu.(*MenuImpl).menu)
}
return m
}
func (m *MenuImpl) Title(title string) IMenu {
m.menu.SetTitle(title)
return m
}
func (m *MenuImpl) Actions(actions ...IAction) IMenu {
vs := []*widgets.QAction{}
for _, action := range actions {
vs = append(vs, action.(*ActionImpl).action)
}
m.menu.Clear()
m.menu.AddActions(vs)
return m
}
func (a *ActionImpl) OnClick(fn func()) IAction {
a.action.ConnectTriggered(func(bool) {
fn()
})
return a
}
func (a *MenuImpl) Assign(v *IMenu) IMenu {
*v = a
return a
}
func (a *ActionImpl) Assign(v *IAction) IAction {
*v = a
return a
}
func (a *ActionImpl) Text(text string) IAction {
a.action.SetText(text)
return a
}
func (a *ActionImpl) GetText() string {
return a.action.Text()
}
func (m *MenuImpl) AddAction(i IAction) IMenu {
m.menu.AddActions([]*widgets.QAction{i.(*ActionImpl).action})
return m
}
func (m *MenuImpl) Clear() IMenu {
m.menu.Clear()
return m
}
func (m *MenuImpl) RemoveAction(action IAction) IMenu {
m.menu.RemoveAction(action.(*ActionImpl).action)
return m
}