-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgetimpl.go
161 lines (135 loc) · 3.35 KB
/
widgetimpl.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
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
//go:build impl
package faithtop
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"strings"
)
type WidgetImpl struct {
widget *widgets.QWidget
alignmentFlag AlignmentFlag
}
func init() {
newWidgetImpl = func() IWidget {
return &WidgetImpl{
widget: widgets.NewQWidget(nil, 0),
}
}
}
func (w *WidgetImpl) getWidget() IWidget {
return w
}
func widgetImplFrom(parent *widgets.QWidget) *WidgetImpl {
return &WidgetImpl{
widget: parent,
}
}
func (w *WidgetImpl) Layout(layout ILayout) IWidget {
w.widget.SetLayout(layout.getLayout().(*LayoutImpl).layout)
return w
}
func (w *WidgetImpl) Align(align AlignmentFlag) IWidget {
w.alignmentFlag = align
return w
}
func (w *WidgetImpl) SizePolicy(width, height SizePolicy) IWidget {
w.widget.SetSizePolicy2(widgets.QSizePolicy__Policy(width), widgets.QSizePolicy__Policy(height))
return w
}
func (w *WidgetImpl) Style(styleSheet string) IWidget {
w.widget.SetStyleSheet(styleSheet)
return w
}
func (w *WidgetImpl) MinWidth(width int) IWidget {
w.widget.SetMinimumWidth(width)
return w
}
func (w *WidgetImpl) MinHeight(height int) IWidget {
w.widget.SetMinimumHeight(height)
return w
}
func (w *WidgetImpl) MaxWidth(width int) IWidget {
w.widget.SetMaximumWidth(width)
return w
}
func (w *WidgetImpl) MaxHeight(height int) IWidget {
w.widget.SetMaximumHeight(height)
return w
}
func (w *WidgetImpl) Enabled(b bool) IWidget {
w.widget.SetEnabled(b)
return w
}
func (w *WidgetImpl) OnDragEnter(fn func(widget IWidget)) IWidget {
w.widget.SetAcceptDrops(true)
w.widget.ConnectDragEnterEvent(func(event *gui.QDragEnterEvent) {
fn(w)
event.AcceptProposedAction()
})
return w
}
func (w *WidgetImpl) OnDragLeave(fn func(widget IWidget)) IWidget {
w.widget.ConnectDragLeaveEvent(func(event *gui.QDragLeaveEvent) {
fn(w)
})
return w
}
func (w *WidgetImpl) OnDrop(fn func(widget IWidget, urls []string)) IWidget {
w.widget.SetAcceptDrops(true)
w.widget.ConnectDropEvent(func(event *gui.QDropEvent) {
urls := []string{}
for _, format := range event.MimeData().Formats() {
d := event.MimeData().Data(format).Data()
for _, line := range strings.Split(d, "\r\n") {
if line != "" {
urls = append(urls, line)
}
}
}
fn(w, urls)
event.AcceptProposedAction()
})
return w
}
func (w *WidgetImpl) AssignWidget(v *IWidget) IWidget {
*v = w
return w
}
func (w *WidgetImpl) Cursor(shape CursorShape) IWidget {
w.widget.SetCursor(gui.NewQCursor2(core.Qt__CursorShape(shape)))
return w
}
func (w *WidgetImpl) OnMousePress(fn func(widget IWidget)) IWidget {
w.widget.ConnectMousePressEvent(func(event *gui.QMouseEvent) {
fn(w)
event.Accept()
})
return w
}
func (w *WidgetImpl) OnMouseRelease(fn func(widget IWidget)) IWidget {
w.widget.ConnectMouseReleaseEvent(func(event *gui.QMouseEvent) {
fn(w)
event.Accept()
})
return w
}
func (w *WidgetImpl) OnKeyPress(fn func(widget IWidget, key Key)) IWidget {
w.widget.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
fn(w, Key(event.Key()))
event.Accept()
})
return w
}
func (w *WidgetImpl) ToolTip(s string) IWidget {
w.widget.SetToolTip(s)
return w
}
func (w *WidgetImpl) Visible(b bool) IWidget {
w.widget.SetVisible(b)
return w
}
func (w *WidgetImpl) ContentMargin(left, top, right, bottom int) IWidget {
w.widget.SetContentsMargins(left, top, right, bottom)
return w
}