StyleDesignerTab.qml
10.6 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import QtQuick
import QtQuick.Controls.Basic
import QtQuick.Layouts
import "components"
import "." as App
Item {
id: tab
// ===== 状态 =====
// 8 字段表单值(与 jewelry.categories 顺序一致)
property var formData: ({
"主石形状": "",
"主石材质": "",
"金属": "",
"花头形式": "",
"戒臂结构": "",
"戒臂处理": "",
"辅石镶嵌": "",
"特殊元素": "",
})
property string assembledPrompt: ""
property string currentTaskId: ""
property string lastResultPath: ""
property string statusText: "● 就绪"
property color statusColor: App.Theme.success
function updateField(category, value) {
var copy = Object.assign({}, tab.formData)
copy[category] = value || ""
tab.formData = copy
tab.assembledPrompt = jewelry.previewPrompt(copy)
}
function reassemble() {
tab.assembledPrompt = jewelry.previewPrompt(tab.formData)
}
function submit() {
if (tab.currentTaskId !== "") return
if (tab.assembledPrompt.trim().length === 0) {
tab.statusText = "● 选几个字段先"
tab.statusColor = App.Theme.danger
return
}
try {
// submitTask 同步返回 task_id,自己记下来给信号过滤用
var taskId = imageGen.submitTask(
tab.assembledPrompt,
[], // 款式设计不带参考图
"1:1", // 珠宝出图常用比例
"2K",
"慢速模式" // Pro 模型,质量优先
)
tab.currentTaskId = taskId
tab.statusText = "● 已提交"
tab.statusColor = App.Theme.accent
} catch (e) {
tab.statusText = "● " + e
tab.statusColor = App.Theme.danger
}
}
Component.onCompleted: reassemble()
Connections {
target: jewelry
function onLibraryChanged(category) {
optionsRepeater.reloadAll()
}
}
// 监听生成信号 — 只对自己提交的 task 做反应(taskId 唯一可区分本 tab vs 图片生成 tab)
Connections {
target: imageGen
function onTaskProgress(taskId, progress, msg) {
if (taskId !== tab.currentTaskId) return
tab.statusText = "● " + (msg || "生成中…")
tab.statusColor = App.Theme.accent
}
function onTaskCompleted(taskId, resultPath, prompt, model) {
if (taskId !== tab.currentTaskId) return
tab.lastResultPath = resultPath
tab.currentTaskId = ""
tab.statusText = "● 已完成"
tab.statusColor = App.Theme.success
}
function onTaskFailed(taskId, error) {
if (taskId !== tab.currentTaskId) return
tab.currentTaskId = ""
tab.statusText = "● " + (error || "失败")
tab.statusColor = App.Theme.danger
}
}
RowLayout {
anchors.fill: parent
anchors.margins: App.Theme.space5
spacing: App.Theme.space4
// ===== 左侧:8 字段表单 =====
Card {
Layout.preferredWidth: 360
Layout.fillHeight: true
ColumnLayout {
anchors.fill: parent
anchors.margins: App.Theme.space4
spacing: App.Theme.space3
CaptionLabel {
text: "款式字段"
font.pointSize: App.Theme.fontLg
}
ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
ColumnLayout {
width: parent.width
spacing: App.Theme.space3
Repeater {
id: optionsRepeater
model: jewelry.categories // 8 个类别名
// task #15b 词库变化时重新拉
function reloadAll() {
// QML 自动重新评估 model:,主动 reset
model = []
model = jewelry.categories
}
delegate: ColumnLayout {
Layout.fillWidth: true
spacing: 4
CaptionLabel {
text: modelData
font.pointSize: App.Theme.fontBase
}
ThemedComboBox {
Layout.fillWidth: true
// 头插一个 "(不选)" 让用户能清空字段
model: ["(不选)"].concat(jewelry.getOptions(modelData))
onActivated: {
var v = currentText === "(不选)" ? "" : currentText
tab.updateField(modelData, v)
}
}
}
}
}
}
}
}
// ===== 右侧:Prompt 预览 + 生成 + 结果 =====
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: App.Theme.space4
// Prompt 预览卡
Card {
Layout.fillWidth: true
Layout.preferredHeight: 200
ColumnLayout {
anchors.fill: parent
anchors.margins: App.Theme.space4
spacing: App.Theme.space3
RowLayout {
spacing: App.Theme.space3
CaptionLabel {
text: "Prompt 预览"
font.pointSize: App.Theme.fontLg
}
Item { Layout.fillWidth: true }
Label {
text: tab.assembledPrompt.length + " 字"
font.family: App.Theme.fontFamily
font.pointSize: App.Theme.fontXs
color: App.Theme.textTertiary
}
}
ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
Rectangle {
anchors.fill: parent
color: App.Theme.bgSubtle
radius: App.Theme.radiusMd
Text {
anchors.fill: parent
anchors.margins: App.Theme.space3
text: tab.assembledPrompt
color: App.Theme.textPrimary
font.family: App.Theme.fontFamily
font.pointSize: App.Theme.fontSm
wrapMode: Text.Wrap
}
}
}
}
}
// 操作行
RowLayout {
spacing: App.Theme.space3
Layout.fillWidth: true
PrimaryButton {
text: tab.currentTaskId !== "" ? "生成中…" : "生成图片"
enabled: tab.currentTaskId === ""
onClicked: tab.submit()
}
SecondaryButton {
text: "重置字段"
onClicked: {
var fresh = {}
for (var i = 0; i < jewelry.categories.length; i++) {
fresh[jewelry.categories[i]] = ""
}
tab.formData = fresh
tab.reassemble()
}
}
Label {
text: tab.statusText
font.family: App.Theme.fontFamily
font.pointSize: App.Theme.fontSm
color: tab.statusColor
}
Item { Layout.fillWidth: true }
}
// 预览大图
Card {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumHeight: 240
ColumnLayout {
anchors.fill: parent
anchors.margins: App.Theme.space4
spacing: App.Theme.space3
CaptionLabel {
text: "预览"
font.pointSize: App.Theme.fontLg
}
Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
color: App.Theme.bgSubtle
radius: App.Theme.radiusMd
Image {
anchors.fill: parent
anchors.margins: App.Theme.space3
source: tab.lastResultPath ? "file:///" + tab.lastResultPath : ""
fillMode: Image.PreserveAspectFit
smooth: true
asynchronous: true
cache: false
visible: tab.lastResultPath !== ""
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onDoubleClicked: {
if (tab.lastResultPath) {
Qt.openUrlExternally("file:///" + tab.lastResultPath)
}
}
}
}
Text {
anchors.centerIn: parent
visible: tab.lastResultPath === ""
text: "选择字段后点 \"生成图片\""
color: App.Theme.textTertiary
font.family: App.Theme.fontFamily
font.pointSize: App.Theme.fontSm
}
}
}
}
}
}
}