-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportDialog.qml
222 lines (203 loc) · 8.93 KB
/
ExportDialog.qml
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
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import AlgWidgets 2.0
import "Krita.js" as Krita
AlgDialog {
width: 400
height: 300
minimumWidth: 400
minimumHeight: 300
defaultButtonText: "Ok"
title: qsTr("Select Materials/Channels to export")
QtObject {
id: internal
property var documentType: {
'Material': "material",
'Stack': "stack",
'Channel': "channel"
}
function nextModelIndex(model, materialName) {
var result = 0
for (result = 0; result < model.count; ++result) {
var modelObject = model.get(result)
if (modelObject.type === documentType.Material && modelObject.name.localeCompare(materialName) > 0) {
break
}
}
return result
}
}
function reload() {
var documentStructure = alg.mapexport.documentStructure()
documentStructureModel.clear()
var mapsList = Krita.exportMaps();
for (var materialId in documentStructure.materials) {
var material = documentStructure.materials[materialId]
var id = internal.nextModelIndex(documentStructureModel, material.name)
var modelMaterialId = id
documentStructureModel.insert(id,
{'name': material.name,
'path': material.name,
'type': internal.documentType.Material,
'parentIndex': 0,
'defaultChecked': mapsList.isChecked(material.name)})
++id
//Browse stacks
for (var stackId in material.stacks) {
var stack = material.stacks[stackId]
var stackPath = material.name + "." + stack.name
var modelStackId = stack.name !== "" ? id : --id
// Do not display the main stack
if (stack.name !== "") {
documentStructureModel.insert(id,
{'name': stack.name,
'path': stackPath,
'type': internal.documentType.Stack,
'parentIndex': id - modelMaterialId,
'defaultChecked': mapsList.isChecked(stackPath)})
}
++id
//Browse channels
for (var channelId in stack.channels) {
var channel = stack.channels[channelId]
var channelPath = stackPath + "." + channel
documentStructureModel.insert(id,
{'name': channel,
'path': channelPath,
'type': internal.documentType.Channel,
'parentIndex': id - modelStackId,
'defaultChecked': mapsList.isChecked(channelPath)})
++id
}
}
}
}
onAccepted: {
var exportMaps = {}
for (var i = 0; i < repeater.count; ++i) {
exportMaps[repeater.itemAt(i).documentPath] = repeater.itemAt(i).checked;
}
alg.settings.setValue("exportMaps", exportMaps)
}
ListModel {
id: documentStructureModel
}
Rectangle {
id: content
parent: contentItem
anchors.fill: parent
anchors.margins: 12
color: "transparent"
clip: true
ColumnLayout {
spacing: 6
anchors.fill: parent
Flow {
id: controlButtons
spacing: 6
layoutDirection: Qt.RightToLeft
AlgButton {
id: noneButton
text: qsTr("None")
}
AlgButton {
id: allButton
text: qsTr("All")
}
AlgButton {
id: colorButton
text: qsTr("Color")
}
}
AlgScrollView {
id: scrollView
Layout.fillWidth: true
Layout.fillHeight: true
ColumnLayout {
spacing: 6
Layout.minimumWidth: scrollView.viewportWidth
Layout.maximumWidth: scrollView.viewportWidth
Repeater {
id: repeater
model: documentStructureModel
RowLayout {
id: rowItem
spacing: 6
property int paddingSize: type === internal.documentType.Stack ?
10 : type === internal.documentType.Channel ?
20 : 0
property var prevItem: null
property alias checked: modelCheckBox.checked
property string documentPath: model.path
signal clicked()
Layout.leftMargin: paddingSize
Layout.minimumWidth: scrollView.viewportWidth - paddingSize
Layout.maximumWidth: scrollView.viewportWidth - paddingSize
Component.onCompleted: {
if (parentIndex > 0) prevItem = repeater.itemAt(index - parentIndex)
}
AlgCheckBox {
id: modelCheckBox
checked: defaultChecked
Layout.preferredWidth: height
onClicked: {
rowItem.clicked()
}
onCheckedChanged: {
if (prevItem && checked) {
prevItem.checked = true;
}
}
Connections {
target: noneButton
function onClicked() {
checked = false
}
}
Connections {
target: allButton
function onClicked() {
checked = true
}
}
Connections {
target: colorButton
function onClicked() {
//an example documentPath is "MaterialName..ChannelName"
//get the channel name on its own
var channelSplit = documentPath.split('.')
var channelName = channelSplit[channelSplit.length - 1]
//Loop through all of the items and only check the ones that are basecolor and emissive
if (channelName === "basecolor" || channelName === "emissive" || channelSplit.length === 1) {
checked = true
} else {
checked = false
}
}
}
Connections {
target: prevItem
function onClicked() {
checked = prevItem.checked
// transmit event to children
rowItem.clicked()
}
}
}
AlgTextEdit {
readOnly: true
borderActivated: true
borderOpacity: 0.3
Layout.fillWidth: true
text: name
}
}
}
}
}
}
}
}