mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
uic: support icons using iconset
This commit is contained in:
parent
a0a4624563
commit
4c6062de1f
@ -57,6 +57,21 @@ type UiString struct {
|
||||
Notr bool `xml:"notr,attr,omitempty"`
|
||||
}
|
||||
|
||||
type UiIcon struct {
|
||||
ResourceFile string `xml:"resource,attr"`
|
||||
|
||||
NormalOff *string `xml:"normaloff,omitempty"`
|
||||
NormalOn *string `xml:"normalon,omitempty"`
|
||||
ActiveOff *string `xml:"activeoff,omitempty"`
|
||||
ActiveOn *string `xml:"activeon,omitempty"`
|
||||
DisabledOff *string `xml:"disabledoff,omitempty"`
|
||||
DisabledOn *string `xml:"disabledon,omitempty"`
|
||||
SelectedOff *string `xml:"selectedoff,omitempty"`
|
||||
SelectedOn *string `xml:"selectedon,omitempty"`
|
||||
|
||||
Base string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type UiProperty struct {
|
||||
Name string `xml:"name,attr"`
|
||||
StringVal *UiString `xml:"string,omitempty"`
|
||||
@ -64,6 +79,7 @@ type UiProperty struct {
|
||||
BoolVal *bool `xml:"bool,omitempty"` // "true" or "false"
|
||||
EnumVal *string `xml:"enum,omitempty"`
|
||||
RectVal *UiRect `xml:"rect,omitempty"`
|
||||
IconVal *UiIcon `xml:"iconset,omitempty"`
|
||||
}
|
||||
|
||||
type UiActionReference struct {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
var (
|
||||
DefaultGridMargin = 11
|
||||
DefaultSpacing = 6
|
||||
IconCounter = 0
|
||||
)
|
||||
|
||||
func collectClassNames_Widget(u *UiWidget) []string {
|
||||
@ -63,6 +64,45 @@ func normalizeEnumName(s string) string {
|
||||
return `qt.` + strings.Replace(s, `::`, `__`, -1)
|
||||
}
|
||||
|
||||
func renderSetIcon(targetName, setterFunc string, iconVal *UiIcon, ret *strings.Builder) {
|
||||
|
||||
iconName := fmt.Sprintf("icon%d", IconCounter)
|
||||
IconCounter++
|
||||
|
||||
ret.WriteString(iconName + " := qt.NewQIcon()\n")
|
||||
|
||||
// A base entry is a synonym for NormalOff. Don't need them both
|
||||
if iconVal.NormalOff != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOff) + ", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)\n")
|
||||
} else {
|
||||
ret.WriteString(iconName + ".AddFile(" + strconv.Quote(strings.TrimSpace(iconVal.Base)) + ")\n")
|
||||
}
|
||||
|
||||
if iconVal.NormalOn != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__On)\n")
|
||||
}
|
||||
if iconVal.ActiveOff != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Active, qt.QIcon__Off)\n")
|
||||
}
|
||||
if iconVal.ActiveOn != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Active, qt.QIcon__On)\n")
|
||||
}
|
||||
if iconVal.DisabledOff != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Disabled, qt.QIcon__Off)\n")
|
||||
}
|
||||
if iconVal.DisabledOn != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Disabled, qt.QIcon__On)\n")
|
||||
}
|
||||
if iconVal.SelectedOff != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Selected, qt.QIcon__Off)\n")
|
||||
}
|
||||
if iconVal.SelectedOn != nil {
|
||||
ret.WriteString(iconName + ".AddFile4(" + strconv.Quote(*iconVal.NormalOn) + ", qt.NewQSize(), qt.QIcon__Selected, qt.QIcon__On)\n")
|
||||
}
|
||||
|
||||
ret.WriteString(`ui.` + targetName + setterFunc + `(` + iconName + ")\n")
|
||||
}
|
||||
|
||||
func renderProperties(properties []UiProperty, ret *strings.Builder, targetName, parentClass string, isLayout bool) error {
|
||||
|
||||
contentsMargins := [4]int{DefaultGridMargin, DefaultGridMargin, DefaultGridMargin, DefaultGridMargin} // left, top, right, bottom
|
||||
@ -122,6 +162,9 @@ func renderProperties(properties []UiProperty, ret *strings.Builder, targetName,
|
||||
// detect the case and convert it to match
|
||||
ret.WriteString(`ui.` + targetName + setterFunc + `(` + normalizeEnumName(*prop.EnumVal) + ")\n")
|
||||
|
||||
} else if prop.IconVal != nil {
|
||||
renderSetIcon(targetName, setterFunc, prop.IconVal, ret)
|
||||
|
||||
} else {
|
||||
ret.WriteString("/* miqt-uic: no handler for " + targetName + " property '" + prop.Name + "' */\n")
|
||||
}
|
||||
@ -273,6 +316,10 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
|
||||
if prop, ok := propertyByName(a.Properties, "shortcut"); ok {
|
||||
ret.WriteString("ui." + a.Name + `.SetShortcut(qt.NewQKeySequence2(` + generateString(prop.StringVal, w.Class) + `))` + "\n")
|
||||
}
|
||||
|
||||
if prop, ok := propertyByName(a.Properties, "icon"); ok {
|
||||
renderSetIcon(a.Name, ".SetIcon", prop.IconVal, &ret)
|
||||
}
|
||||
}
|
||||
|
||||
// Items
|
||||
|
Loading…
Reference in New Issue
Block a user