Skip to content

Commit fa610ee

Browse files
refactor: update QML structure in DetailConfigItem.qml
- Introduced a new containerItem for better organization of child components. - Updated parentName references to use the new containerItem. - Streamlined the loading logic and configuration options handling for improved clarity and maintainability. Log: refactor QML structure for enhanced readability and organization
1 parent e71484f commit fa610ee

1 file changed

Lines changed: 136 additions & 135 deletions

File tree

src/dcc-fcitx5configtool/qml/DetailConfigItem.qml

Lines changed: 136 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DccObject {
1515
property bool loading: true
1616

1717
DccObject {
18+
id: containerItem
1819
name: root.displayName + "_Container" // Add suffix to avoid conflict with root.name
1920
parentName: "GlobalConfigPage"
2021
weight: 40
@@ -29,166 +30,155 @@ DccObject {
2930
spacing: 0
3031
height: implicitHeight + 30
3132
}
32-
}
3333

34-
DccObject {
35-
id: headerItem
36-
property bool expanded: false
37-
parentName: root.displayName + "_Container" // Update to match the new name above
38-
displayName: root.displayName
39-
weight: root.weight
40-
pageType: DccObject.Item
41-
backgroundType: DccObject.Normal | DccObject.Hover
42-
page: RowLayout {
43-
id: headerRow
44-
height: 40
34+
DccObject {
35+
id: headerItem
36+
property bool expanded: false
37+
parentName: containerItem.name
38+
displayName: root.displayName
39+
weight: root.weight
40+
pageType: DccObject.Item
41+
backgroundType: DccObject.Normal | DccObject.Hover
42+
page: RowLayout {
43+
id: headerRow
44+
height: 40
4545

46-
MouseArea {
47-
anchors.fill: parent
48-
onClicked: headerItem.expanded = !headerItem.expanded
49-
}
46+
MouseArea {
47+
anchors.fill: parent
48+
onClicked: headerItem.expanded = !headerItem.expanded
49+
}
5050

51-
Label {
52-
Layout.leftMargin: 10
53-
Layout.alignment: Qt.AlignVCenter
54-
font: D.DTK.fontManager.t6
55-
text: dccObj.displayName
56-
}
57-
D.ToolButton {
58-
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
59-
icon.width: 12
60-
icon.height: 12
61-
icon.name: headerItem.expanded ? "arrow_ordinary_down" : "arrow_ordinary_right"
62-
onClicked: headerItem.expanded = !headerItem.expanded
51+
Label {
52+
Layout.leftMargin: 10
53+
Layout.alignment: Qt.AlignVCenter
54+
font: D.DTK.fontManager.t6
55+
text: dccObj.displayName
56+
}
57+
D.ToolButton {
58+
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
59+
icon.width: 12
60+
icon.height: 12
61+
icon.name: headerItem.expanded ? "arrow_ordinary_down" : "arrow_ordinary_right"
62+
onClicked: headerItem.expanded = !headerItem.expanded
63+
}
6364
}
6465
}
65-
}
66-
67-
Component.onCompleted: {
68-
dccData.fcitx5ConfigProxy.onRequestConfigFinished.connect(() => {
69-
configOptions = []
70-
configOptions = dccData.fcitx5ConfigProxy.globalConfigOptions(
71-
root.name)
72-
keyName = ""
73-
})
74-
configOptions = dccData.fcitx5ConfigProxy.globalConfigOptions(root.name)
75-
loading = false
76-
}
7766

78-
Loader {
79-
active: !loading
80-
asynchronous: true
81-
sourceComponent: DccRepeater {
82-
model: configOptions
83-
delegate: Component {
84-
DccObject {
85-
parentName: root.displayName + "_Container" // Update to match the new name above
86-
displayName: modelData.description
87-
weight: root.weight + index + 1
88-
pageType: DccObject.Editor
89-
visible: headerItem.expanded
90-
backgroundType: DccObject.Normal | DccObject.Hover
91-
page: Loader {
92-
height: 40
93-
sourceComponent: {
94-
switch (modelData.type) {
95-
case "Boolean":
96-
return booleanComponent
97-
case "Integer":
98-
return integerComponent
99-
case "String":
100-
return stringComponent
101-
case "List|Key":
102-
return keyComponent
103-
case "Enum":
104-
return enumComponent
105-
default:
106-
return null
67+
Loader {
68+
active: !root.loading
69+
asynchronous: true
70+
sourceComponent: DccRepeater {
71+
model: root.configOptions
72+
delegate: Component {
73+
DccObject {
74+
parentName: containerItem.name
75+
displayName: modelData.description
76+
weight: root.weight + index + 1
77+
pageType: DccObject.Editor
78+
visible: headerItem.expanded
79+
backgroundType: DccObject.Normal | DccObject.Hover
80+
page: Loader {
81+
height: 40
82+
sourceComponent: {
83+
switch (modelData.type) {
84+
case "Boolean":
85+
return booleanComponent
86+
case "Integer":
87+
return integerComponent
88+
case "String":
89+
return stringComponent
90+
case "List|Key":
91+
return keyComponent
92+
case "Enum":
93+
return enumComponent
94+
default:
95+
return null
96+
}
10797
}
108-
}
10998

110-
Component {
111-
id: booleanComponent
112-
D.Switch {
113-
checked: modelData.value === "True"
114-
onCheckedChanged: {
115-
dccData.fcitx5ConfigProxy.setValue(
116-
root.name + "/" + modelData.name,
117-
checked ? "True" : "False")
99+
Component {
100+
id: booleanComponent
101+
D.Switch {
102+
checked: modelData.value === "True"
103+
onCheckedChanged: {
104+
dccData.fcitx5ConfigProxy.setValue(
105+
root.name + "/" + modelData.name,
106+
checked ? "True" : "False")
107+
}
118108
}
119109
}
120-
}
121110

122-
Component {
123-
id: integerComponent
124-
D.SpinBox {
125-
width: 55
126-
implicitWidth: 55
127-
value: parseInt(modelData.value)
128-
onValueChanged: {
129-
dccData.fcitx5ConfigProxy.setValue(
130-
root.name + "/" + modelData.name,
131-
value.toString())
111+
Component {
112+
id: integerComponent
113+
D.SpinBox {
114+
width: 55
115+
implicitWidth: 55
116+
value: parseInt(modelData.value)
117+
onValueChanged: {
118+
dccData.fcitx5ConfigProxy.setValue(
119+
root.name + "/" + modelData.name,
120+
value.toString())
121+
}
132122
}
133123
}
134-
}
135124

136-
Component {
137-
id: stringComponent
138-
D.TextField {
139-
text: modelData.value
140-
onTextChanged: {
141-
dccData.fcitx5ConfigProxy.setValue(
142-
root.name + "/" + modelData.name,
143-
text)
125+
Component {
126+
id: stringComponent
127+
D.TextField {
128+
text: modelData.value
129+
onTextChanged: {
130+
dccData.fcitx5ConfigProxy.setValue(
131+
root.name + "/" + modelData.name,
132+
text)
133+
}
144134
}
145135
}
146-
}
147136

148-
Component {
149-
id: keyComponent
150-
KeySequenceDisplay {
151-
placeholderText: qsTr("Please enter a new shortcut")
152-
keys: modelData.value
153-
background.visible: false
154-
onFocusChanged: {
155-
if (!focus) {
156-
if (keys.length > 0) {
157-
dccData.fcitx5ConfigProxy.setValue(
158-
root.name + "/" + modelData.name + "/0",
159-
keys, true)
160-
} else if (keyName != modelData.name) {
161-
keys = modelData.value
137+
Component {
138+
id: keyComponent
139+
KeySequenceDisplay {
140+
placeholderText: qsTr("Please enter a new shortcut")
141+
keys: modelData.value
142+
background.visible: false
143+
onFocusChanged: {
144+
if (!focus) {
145+
if (keys.length > 0) {
146+
dccData.fcitx5ConfigProxy.setValue(
147+
root.name + "/" + modelData.name + "/0",
148+
keys, true)
149+
} else if (root.keyName != modelData.name) {
150+
keys = modelData.value
151+
}
162152
}
163153
}
164-
}
165-
onKeysChanged: {
166-
root.keyName = modelData.name
167-
}
154+
onKeysChanged: {
155+
root.keyName = modelData.name
156+
}
168157

169-
Connections {
170-
target: root
171-
function onKeyNameChanged() {
172-
if (keyName != modelData.name) {
173-
focus = false
158+
Connections {
159+
target: root
160+
function onKeyNameChanged() {
161+
if (root.keyName != modelData.name) {
162+
focus = false
163+
}
174164
}
175165
}
176166
}
177167
}
178-
}
179168

180-
Component {
181-
id: enumComponent
182-
D.ComboBox {
183-
model: modelData.propertiesI18n
184-
flat: true
185-
currentIndex: modelData.properties.indexOf(
186-
modelData.value) ? modelData.properties.indexOf(
187-
modelData.value) : 0
188-
onCurrentIndexChanged: {
189-
dccData.fcitx5ConfigProxy.setValue(
190-
root.name + "/" + modelData.name,
191-
modelData.properties[currentIndex])
169+
Component {
170+
id: enumComponent
171+
D.ComboBox {
172+
model: modelData.propertiesI18n
173+
flat: true
174+
currentIndex: modelData.properties.indexOf(
175+
modelData.value) ? modelData.properties.indexOf(
176+
modelData.value) : 0
177+
onCurrentIndexChanged: {
178+
dccData.fcitx5ConfigProxy.setValue(
179+
root.name + "/" + modelData.name,
180+
modelData.properties[currentIndex])
181+
}
192182
}
193183
}
194184
}
@@ -197,4 +187,15 @@ DccObject {
197187
}
198188
}
199189
}
190+
191+
Component.onCompleted: {
192+
dccData.fcitx5ConfigProxy.onRequestConfigFinished.connect(() => {
193+
configOptions = []
194+
configOptions = dccData.fcitx5ConfigProxy.globalConfigOptions(
195+
root.name)
196+
keyName = ""
197+
})
198+
configOptions = dccData.fcitx5ConfigProxy.globalConfigOptions(root.name)
199+
loading = false
200+
}
200201
}

0 commit comments

Comments
 (0)