51{
52 QString field;
53 int idx;
54 int frame = 0;
55
56 QString projName;
57 int width = 0;
58 int height = 0;
59 int frameCount = 1;
60 float framerate = 24.0;
61 float pixelRatio = 1.0;
62
63 int projNameIdx = -1;
64 int widthIdx = -1;
65 int heightIdx = -1;
66 int frameCountIdx = -1;
67 int framerateIdx = -1;
68 int pixelRatioIdx = -1;
69
71
72 KisCursorOverrideLock cursorLock(Qt::WaitCursor);
73
74 idx = filename.lastIndexOf(QRegularExpression("[\\/]"));
75 QString base = (idx == -1) ? QString() : filename.left(idx + 1);
76 QString path = filename;
77
78 if (path.right(4).toUpper() == ".CSV")
79 path = path.left(path.size() - 4);
80
81
82 path.append(".frames/");
83
85
87
90 importDoc->setInfiniteAutoSaveInterval();
91 importDoc->setFileBatchMode(true);
92
94
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 }
118 int step = 0;
119
120 do {
121 qApp->processEvents();
122
125 break;
126 }
127
128 if ((idx = readLine.
nextLine(io)) <= 0) {
129 if ((idx < 0) ||(step < 5))
131 break;
132 }
134
135 if (field.isNull()) continue;
136
137 switch (step) {
138
139 case 0 :
140 step = 1;
141 break;
142
143 case 1 :
144 step = 2;
145
146 for (idx = 0; !field.isNull(); idx++) {
147 if (field == "Project Name") {
148 projNameIdx = idx;
149
150 } else if (field == "Width") {
151 widthIdx = idx;
152
153 } else if (field == "Height") {
154 heightIdx = idx;
155
156 } else if (field == "Frame Count") {
157 frameCountIdx = idx;
158
159 } else if (field == "Frame Rate") {
160 framerateIdx = idx;
161
162 } else if (field == "Pixel Aspect Ratio") {
163 pixelRatioIdx = idx;
164 }
166 }
167 break;
168
169 case 2 :
170 step= 3;
171
172 for (idx= 0; !field.isNull(); idx++) {
173 if (idx == projNameIdx) {
174 projName = field;
175
176 } else if (idx == widthIdx) {
177 width = field.toInt();
178
179 } else if (idx == heightIdx) {
180 height = field.toInt();
181
182 } else if (idx == frameCountIdx) {
183 frameCount = field.toInt();
184
185 if (frameCount < 1) frameCount= 1;
186
187 } else if (idx == framerateIdx) {
188 framerate = field.toFloat();
189
190 } else if (idx == pixelRatioIdx) {
191 pixelRatio = field.toFloat();
192
193 }
195 }
196
197 if ((width < 1) || (height < 1)) {
199 break;
200 }
201
202 retval =
createNewImage(width, height, pixelRatio, projName.isNull() ? filename : projName);
203 break;
204
205 case 3 :
206 if (field[0] != '#') break;
207
208 for (; !(field = readLine.
nextField()).isNull(); ) {
210 layers.append(layerRecord);
211 }
214 step = 4;
215 Q_FALLTHROUGH();
216
217 case 4 :
218
219 if (field == "#Layers") {
220
221 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++)
222 layers.at(idx)->name = field;
223
224 break;
225 }
226 if (field == "#Density") {
227
228 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++)
229 layers.at(idx)->density = field.toFloat();
230
231 break;
232 }
233 if (field == "#Blending") {
234
235 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++)
236 layers.at(idx)->blending = field;
237
238 break;
239 }
240 if (field == "#Visible") {
241
242 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++)
243 layers.at(idx)->visible = field.toInt();
244
245 break;
246 }
247 if (field == "#Folder") {
248
249 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++)
250 layers.at(idx)->path =
validPath(field, base);
251
252 break;
253 }
254 if ((field.size() < 2) || (field[0] != '#') || !field[1].isDigit()) break;
255
256 step = 5;
257
258 Q_FALLTHROUGH();
259
260 case 5 :
261
262 if ((field.size() < 2) || (field[0] != '#') || !field[1].isDigit()) break;
263
264 for (idx = 0; !(field = readLine.
nextField()).isNull() && (idx < layers.size()); idx++) {
266
267 if (layer->
last != field) {
269
270
271 }
272 retval =
setLayer(layer, importDoc.data(), path);
274 layer->
frame = frame;
275 }
276 }
277 frame++;
278 break;
279 }
280 }
while (retval.
isOk());
281
282
283
287
288 if (frame > frameCount)
289 frameCount = frame;
290
293 }
294
295 for (idx = 0; idx < layers.size(); idx++) {
297
298
299 if ((layer->
frame > 0) || !layer->
last.isEmpty()) {
300 retval =
setLayer(layer, importDoc.data(), path);
301
303 break;
304 }
305 }
306 }
307
309
310 for (idx = layers.size() - 1; idx >= 0; idx--) {
312
315 }
316 }
318 }
319 qDeleteAll(layers);
320 io->close();
321
323
324
325
326 if (!setView) {
328 if (sb) {
329 sb->clearMessage();
330 }
331 } else {
333 }
334 }
335
336 return retval;
337}
KisImportExportErrorCode setLayer(CSVLayerRecord *, KisDocument *, const QString &)
QString validPath(const QString &, const QString &)
KisImportExportErrorCode createNewImage(int, int, float, const QString &)
int nextLine(QIODevice *io)
void clearStatusBarMessage()
void setDocumentRange(const KisTimeSpan range)
void setFramerate(int fps)
KisImageAnimationInterface * animationInterface() const
static KisPart * instance()
KisMainWindow * currentMainwindow() const
static KisTimeSpan fromTimeToTime(int start, int end)
KisDocument * createDocument(QList< KisNodeSP > nodes, KisImageSP srcImage, const QRect &copiedBounds)
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)