]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
Fix clip count & duration on document opening
[kdenlive] / src / kdenlivedoc.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include <KDebug>
21 #include <KStandardDirs>
22 #include <KMessageBox>
23 #include <KLocale>
24 #include <KFileDialog>
25 #include <KIO/NetAccess>
26 #include <KApplication>
27
28 #include "kdenlivedoc.h"
29 #include "docclipbase.h"
30 #include "profilesdialog.h"
31 #include "kdenlivesettings.h"
32 #include "renderer.h"
33 #include "clipmanager.h"
34 #include "addfoldercommand.h"
35 #include "editfoldercommand.h"
36 #include "titlewidget.h"
37 #include "mainwindow.h"
38
39 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0) {
40     kDebug() << "// init profile, ratnum: " << profile.frame_rate_num << ", " << profile.frame_rate_num << ", width: " << profile.width;
41     m_clipManager = new ClipManager(this);
42     if (!url.isEmpty()) {
43         QString tmpFile;
44         if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
45             QFile file(tmpFile);
46             m_document.setContent(&file, false);
47             file.close();
48             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
49             QDomNode westley = m_document.elementsByTagName("westley").at(0);
50             if (!infoXmlNode.isNull()) {
51                 QDomElement infoXml = infoXmlNode.toElement();
52                 QString profilePath = infoXml.attribute("profile");
53                 m_startPos = infoXml.attribute("position").toInt();
54                 if (!profilePath.isEmpty()) setProfilePath(profilePath);
55                 double version = infoXml.attribute("version").toDouble();
56                 if (version < 0.7) convertDocument(version);
57                 else {
58                     //delete all mlt producers and instead, use Kdenlive saved producers
59                     QDomNodeList prods = m_document.elementsByTagName("producer");
60                     int maxprod = prods.count();
61                     int pos = 0;
62                     for (int i = 0; i < maxprod; i++) {
63                         QDomNode m = prods.at(pos);
64                         if (m.toElement().attribute("id") == "black")
65                             pos = 1;
66                         else westley.removeChild(m);
67                     }
68                     prods = m_document.elementsByTagName("kdenlive_producer");
69                     maxprod = prods.count();
70                     for (int i = 0; i < maxprod; i++) {
71                         prods.at(0).toElement().setTagName("producer");
72                         westley.insertBefore(prods.at(0), QDomNode());
73                     }
74                 }
75                 QDomElement e;
76                 QDomNodeList producers = m_document.elementsByTagName("producer");
77                 const int max = producers.count();
78                 if (max > 0) {
79                     m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
80                     parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
81                 }
82
83                 for (int i = 0; i < max; i++) {
84                     e = producers.item(i).cloneNode().toElement();
85                     if (m_documentLoadingStep > 0) {
86                         m_documentLoadingProgress += m_documentLoadingStep;
87                         parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
88                         qApp->processEvents();
89                     }
90                     if (!e.isNull() && e.attribute("id") != "black") {
91                         addClip(e, e.attribute("id").toInt());
92                     }
93                 }
94
95                 QDomNode markers = m_document.elementsByTagName("markers").at(0);
96                 if (!markers.isNull()) {
97                     QDomNodeList markerslist = markers.childNodes();
98                     int maxchild = markerslist.count();
99                     for (int k = 0; k < maxchild; k++) {
100                         e = markerslist.at(k).toElement();
101                         if (e.tagName() == "marker") {
102                             int id = e.attribute("id").toInt();
103                             m_clipManager->getClipById(id)->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
104                         }
105                     }
106                     m_document.removeChild(markers);
107                 }
108                 m_document.removeChild(infoXmlNode);
109
110                 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
111             } else kWarning() << "  NO KDENLIVE INFO FOUND IN FILE: " << url.path();
112             KIO::NetAccess::removeTempFile(tmpFile);
113         } else {
114             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
115         }
116     } else {
117         // Creating new document
118         QDomElement westley = m_document.createElement("westley");
119         m_document.appendChild(westley);
120
121         QDomElement tractor = m_document.createElement("tractor");
122         tractor.setAttribute("id", "maintractor");
123         QDomElement multitrack = m_document.createElement("multitrack");
124         QDomElement playlist = m_document.createElement("playlist");
125         playlist.setAttribute("id", "black_track");
126         westley.appendChild(playlist);
127
128
129         // create playlists
130         int audiotracks = 2;
131         int videotracks = 3;
132         int total = audiotracks + videotracks + 1;
133
134         for (int i = 1; i < total; i++) {
135             QDomElement playlist = m_document.createElement("playlist");
136             playlist.setAttribute("id", "playlist" + QString::number(i));
137             westley.appendChild(playlist);
138         }
139
140         QDomElement track0 = m_document.createElement("track");
141         track0.setAttribute("producer", "black_track");
142         tractor.appendChild(track0);
143
144         // create audio tracks
145         for (int i = 1; i < audiotracks + 1; i++) {
146             QDomElement track = m_document.createElement("track");
147             track.setAttribute("producer", "playlist" + QString::number(i));
148             track.setAttribute("hide", "video");
149             tractor.appendChild(track);
150         }
151
152         // create video tracks
153         for (int i = audiotracks + 1; i < total; i++) {
154             QDomElement track = m_document.createElement("track");
155             track.setAttribute("producer", "playlist" + QString::number(i));
156             tractor.appendChild(track);
157         }
158
159         for (uint i = 2; i < total ; i++) {
160             QDomElement transition = m_document.createElement("transition");
161             transition.setAttribute("in", "0");
162             //TODO: Make audio mix last for all project duration
163             transition.setAttribute("out", "15000");
164
165             QDomElement property = m_document.createElement("property");
166             property.setAttribute("name", "a_track");
167             QDomText value = m_document.createTextNode(QString::number(1));
168             property.appendChild(value);
169             transition.appendChild(property);
170
171             property = m_document.createElement("property");
172             property.setAttribute("name", "b_track");
173             value = m_document.createTextNode(QString::number(i));
174             property.appendChild(value);
175             transition.appendChild(property);
176
177             property = m_document.createElement("property");
178             property.setAttribute("name", "mlt_service");
179             value = m_document.createTextNode("mix");
180             property.appendChild(value);
181             transition.appendChild(property);
182
183             property = m_document.createElement("property");
184             property.setAttribute("name", "combine");
185             value = m_document.createTextNode("1");
186             property.appendChild(value);
187             transition.appendChild(property);
188
189             property = m_document.createElement("property");
190             property.setAttribute("name", "internal_added");
191             value = m_document.createTextNode("237");
192             property.appendChild(value);
193             transition.appendChild(property);
194             tractor.appendChild(transition);
195         }
196         westley.appendChild(tractor);
197     }
198     m_scenelist = m_document.toString();
199     kDebug() << "KDEnnlive document, init timecode: " << m_fps;
200     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
201     else m_timecode.setFormat((int) m_fps);
202 }
203
204 KdenliveDoc::~KdenliveDoc() {
205     delete m_commandStack;
206     delete m_clipManager;
207 }
208
209 void KdenliveDoc::convertDocument(double version) {
210     // Opening a old Kdenlive document
211     QDomNode westley = m_document.elementsByTagName("westley").at(1);
212     QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
213     QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
214     QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
215     QDomNodeList playlists = m_document.elementsByTagName("playlist");
216
217     QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
218     QString profile = props.toElement().attribute("videoprofile");
219     if (profile == "dv_wide") profile = "dv_pal_wide";
220     if (!profile.isEmpty()) {
221         setProfilePath(profile);
222     } else setProfilePath("dv_pal");
223
224     // move playlists outside of tractor and add the tracks instead
225     int max = playlists.count();
226     for (int i = 0; i < max; i++) {
227         QDomNode n = playlists.at(i);
228         westley.insertBefore(n, QDomNode());
229         QDomElement pl = n.toElement();
230         QDomElement track = m_document.createElement("track");
231         QString trackType = pl.attribute("hide");
232         if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
233         QString playlist_id =  pl.attribute("id");
234         if (playlist_id.isEmpty()) {
235             playlist_id = "black_track";
236             pl.setAttribute("id", playlist_id);
237         }
238         track.setAttribute("producer", playlist_id);
239         tractor.appendChild(track);
240     }
241     tractor.removeChild(multitrack);
242
243     // audio track mixing transitions should not be added to track view, so add required attribute
244     QDomNodeList transitions = m_document.elementsByTagName("transition");
245     max = transitions.count();
246     for (int i = 0; i < max; i++) {
247         QDomElement tr = transitions.at(i).toElement();
248         if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
249             QDomElement property = m_document.createElement("property");
250             property.setAttribute("name", "internal_added");
251             QDomText value = m_document.createTextNode("237");
252             property.appendChild(value);
253             tr.appendChild(property);
254         } else {
255             // convert transition
256             QDomNamedNodeMap attrs = tr.attributes();
257             for (unsigned int j = 0; j < attrs.count(); j++) {
258                 QString attrName = attrs.item(j).nodeName();
259                 if (attrName != "in" && attrName != "out" && attrName != "id") {
260                     QDomElement property = m_document.createElement("property");
261                     property.setAttribute("name", attrName);
262                     QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
263                     property.appendChild(value);
264                     tr.appendChild(property);
265                 }
266             }
267         }
268     }
269
270     // move transitions after tracks
271     for (int i = 0; i < max; i++) {
272         tractor.insertAfter(transitions.at(0), QDomNode());
273     }
274
275     QDomElement markers = m_document.createElement("markers");
276
277     // change producer names
278     QDomNodeList producers = m_document.elementsByTagName("producer");
279     max = producers.count();
280     for (int i = 0; i < max; i++) {
281         QDomElement prod = producers.at(0).toElement();
282         QDomNode m = prod.firstChild();
283         if (!m.isNull() && m.toElement().tagName() == "markers") {
284             QDomNodeList prodchilds = m.childNodes();
285             int maxchild = prodchilds.count();
286             for (int k = 0; k < maxchild; k++) {
287                 QDomElement mark = prodchilds.at(0).toElement();
288                 mark.setAttribute("id", prod.attribute("id"));
289                 markers.insertAfter(mark, QDomNode());
290             }
291             prod.removeChild(m);
292         }
293         int duration = prod.attribute("duration").toInt();
294         if (duration > 0) prod.setAttribute("out", QString::number(duration));
295         westley.insertBefore(prod, QDomNode());
296     }
297
298     QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
299     if (!markers.firstChild().isNull()) westley0.appendChild(markers);
300     westley0.removeChild(kdenlivedoc);
301
302     QDomNodeList elements = westley.childNodes();
303     max = elements.count();
304     for (int i = 0; i < max; i++) {
305         QDomElement prod = elements.at(0).toElement();
306         westley0.insertAfter(prod, QDomNode());
307     }
308
309     westley0.removeChild(westley);
310
311     //kDebug() << "/////////////////  CONVERTED DOC:";
312     //kDebug() << m_document.toString();
313     //kDebug() << "/////////////////  END CONVERTED DOC:";
314 }
315
316 QDomElement KdenliveDoc::documentInfoXml(QDomElement timelineInfo) {
317     QDomDocument doc;
318     QDomElement e;
319     QDomElement addedXml = doc.createElement("kdenlivedoc");
320     QDomElement markers = doc.createElement("markers");
321     addedXml.setAttribute("version", "0.7");
322     addedXml.setAttribute("profile", profilePath());
323     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
324     QList <DocClipBase*> list = m_clipManager->documentClipList();
325     for (int i = 0; i < list.count(); i++) {
326         e = list.at(i)->toXML();
327         e.setTagName("kdenlive_producer");
328         addedXml.appendChild(doc.importNode(e, true));
329         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
330         for (int j = 0; j < marks.count(); j++) {
331             QDomElement marker = doc.createElement("marker");
332             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
333             marker.setAttribute("comment", marks.at(j).comment());
334             marker.setAttribute("id", e.attribute("id"));
335             markers.appendChild(marker);
336         }
337     }
338     addedXml.appendChild(markers);
339     addedXml.appendChild(doc.importNode(timelineInfo, true));
340     //kDebug() << m_document.toString();
341     return addedXml;
342 }
343
344
345 ClipManager *KdenliveDoc::clipManager() {
346     return m_clipManager;
347 }
348
349 KUrl KdenliveDoc::projectFolder() const {
350     if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
351     return m_projectFolder;
352 }
353
354 QString KdenliveDoc::getDocumentStandard() {
355     //WARNING: this way to tell the video standard is a bit hackish...
356     if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
357     return "NTSC";
358 }
359
360 QString KdenliveDoc::profilePath() const {
361     return m_profile.path;
362 }
363
364 void KdenliveDoc::setProfilePath(QString path) {
365     KdenliveSettings::setCurrent_profile(path);
366     m_profile = ProfilesDialog::getVideoProfile(path);
367     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
368     m_width = m_profile.width;
369     m_height = m_profile.height;
370     kDebug() << "KDEnnlive document, init timecode from path: " << path << ",  " << m_fps;
371     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
372     else m_timecode.setFormat((int) m_fps);
373 }
374
375 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
376     emit progressInfo(message, progress);
377 }
378
379 void KdenliveDoc::loadingProgressed() {
380     m_documentLoadingProgress += m_documentLoadingStep;
381     emit progressInfo(QString(), (int) m_documentLoadingProgress);
382 }
383
384 KUndoStack *KdenliveDoc::commandStack() {
385     return m_commandStack;
386 }
387
388 void KdenliveDoc::setRenderer(Render *render) {
389     m_render = render;
390     emit progressInfo(i18n("Loading playlist..."), 0);
391     qApp->processEvents();
392     if (m_render) m_render->setSceneList(m_scenelist, m_startPos);
393     emit progressInfo(QString(), -1);
394 }
395
396 Render *KdenliveDoc::renderer() {
397     return m_render;
398 }
399
400 void KdenliveDoc::updateClip(int id) {
401     emit updateClipDisplay(id);
402 }
403
404 void KdenliveDoc::updateAllProjectClips() {
405     QList <DocClipBase*> list = m_clipManager->documentClipList();
406     for (int i = 0; i < list.count(); i++)
407         emit updateClipDisplay(list.at(i)->getId());
408 }
409
410 int KdenliveDoc::getFramePos(QString duration) {
411     return m_timecode.getFrameCount(duration, m_fps);
412 }
413
414 QString KdenliveDoc::producerName(int id) {
415     QString result = "unnamed";
416     QDomNodeList prods = producersList();
417     int ct = prods.count();
418     for (int i = 0; i <  ct ; i++) {
419         QDomElement e = prods.item(i).toElement();
420         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
421             result = e.attribute("name");
422             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
423             break;
424         }
425     }
426     return result;
427 }
428
429 void KdenliveDoc::setProducerDuration(int id, int duration) {
430     QDomNodeList prods = producersList();
431     int ct = prods.count();
432     for (int i = 0; i <  ct ; i++) {
433         QDomElement e = prods.item(i).toElement();
434         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
435             e.setAttribute("duration", QString::number(duration));
436             break;
437         }
438     }
439 }
440
441 int KdenliveDoc::getProducerDuration(int id) {
442     int result = 0;
443     QDomNodeList prods = producersList();
444     int ct = prods.count();
445     for (int i = 0; i <  ct ; i++) {
446         QDomElement e = prods.item(i).toElement();
447         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
448             result = e.attribute("duration").toInt();
449             break;
450         }
451     }
452     return result;
453 }
454
455
456 QDomDocument KdenliveDoc::generateSceneList() {
457     QDomDocument doc;
458     QDomElement westley = doc.createElement("westley");
459     doc.appendChild(westley);
460     QDomElement prod = doc.createElement("producer");
461 }
462
463 QDomDocument KdenliveDoc::toXml() const {
464     return m_document;
465 }
466
467 Timecode KdenliveDoc::timecode() const {
468     return m_timecode;
469 }
470
471 QDomNodeList KdenliveDoc::producersList() {
472     return m_document.elementsByTagName("producer");
473 }
474
475 void KdenliveDoc::backupMltPlaylist() {
476     if (m_render) m_scenelist = m_render->sceneList();
477 }
478
479 double KdenliveDoc::fps() const {
480     return m_fps;
481 }
482
483 int KdenliveDoc::width() const {
484     return m_width;
485 }
486
487 int KdenliveDoc::height() const {
488     return m_height;
489 }
490
491 KUrl KdenliveDoc::url() const {
492     return m_url;
493 }
494
495 void KdenliveDoc::setUrl(KUrl url) {
496     m_url = url;
497 }
498
499 void KdenliveDoc::setModified(bool mod) {
500     if (mod == m_modified) return;
501     m_modified = mod;
502     emit docModified(m_modified);
503 }
504
505 bool KdenliveDoc::isModified() const {
506     return m_modified;
507 }
508
509 QString KdenliveDoc::description() const {
510     if (m_url.isEmpty())
511         return i18n("Untitled") + " / " + m_profile.description;
512     else
513         return m_url.fileName() + " / " + m_profile.description;
514 }
515
516 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
517     DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
518     kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
519     m_clipManager->addClip(clip);
520     emit addProjectClip(clip);
521 }
522
523 void KdenliveDoc::addFolder(const QString foldername, int clipId, bool edit) {
524     emit addProjectFolder(foldername, clipId, false, edit);
525 }
526
527 void KdenliveDoc::deleteFolder(const QString foldername, int clipId) {
528     emit addProjectFolder(foldername, clipId, true);
529 }
530
531 void KdenliveDoc::deleteProjectClip(QList <int> ids) {
532     for (int i = 0; i < ids.size(); ++i) {
533         emit deletTimelineClip(ids.at(i));
534         m_clipManager->slotDeleteClip(ids.at(i));
535     }
536     setModified(true);
537 }
538
539 void KdenliveDoc::deleteProjectFolder(QMap <QString, int> map) {
540     QMapIterator<QString, int> i(map);
541     while (i.hasNext()) {
542         i.next();
543         slotDeleteFolder(i.key(), i.value());
544     }
545     setModified(true);
546 }
547
548 void KdenliveDoc::deleteClip(const uint clipId) {
549     emit signalDeleteProjectClip(clipId);
550     m_clipManager->deleteClip(clipId);
551 }
552
553 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
554     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
555     m_clipManager->slotAddClipFile(url, group, groupId);
556     setModified(true);
557 }
558
559 void KdenliveDoc::slotAddTextClipFile(const QString path, const QString group, const int groupId) {
560     kDebug() << "/////////  DOCUM, ADD TXT CLP: " << path;
561     m_clipManager->slotAddTextClipFile(path, group, groupId);
562     setModified(true);
563 }
564
565 void KdenliveDoc::slotAddFolder(const QString folderName) {
566     AddFolderCommand *command = new AddFolderCommand(this, folderName, m_clipManager->getFreeClipId(), true);
567     commandStack()->push(command);
568     setModified(true);
569 }
570
571 void KdenliveDoc::slotDeleteFolder(const QString folderName, const int id) {
572     AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
573     commandStack()->push(command);
574     setModified(true);
575 }
576
577 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, int clipId) {
578     EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
579     commandStack()->push(command);
580     setModified(true);
581 }
582
583 int KdenliveDoc::getFreeClipId() {
584     return m_clipManager->getFreeClipId();
585 }
586
587 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
588     return m_clipManager->getClipById(clipId);
589 }
590
591 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
592     m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
593     setModified(true);
594 }
595
596 void KdenliveDoc::slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, bool loop, const QString group, const int groupId) {
597     m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, group, groupId);
598     setModified(true);
599 }
600
601 void KdenliveDoc::slotCreateTextClip(QString group, int groupId) {
602     QString titlesFolder = projectFolder().path() + "/titles/";
603     KStandardDirs::makeDir(titlesFolder);
604     TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
605     if (dia_ui->exec() == QDialog::Accepted) {
606         QString titleName = "title";
607         int counter = 0;
608         QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
609         while (QFile::exists(path + ".kdenlivetitle")) {
610             counter++;
611             path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
612         }
613         QPixmap pix = dia_ui->renderedPixmap();
614         pix.save(path + ".png");
615         dia_ui->saveTitle(path + ".kdenlivetitle");
616         slotAddTextClipFile(path, QString(), -1);
617     }
618     delete dia_ui;
619 }
620
621 void KdenliveDoc::editTextClip(QString path, int id) {
622     TitleWidget *dia_ui = new TitleWidget(KUrl(path + ".kdenlivetitle"), path, m_render, kapp->activeWindow());
623     if (dia_ui->exec() == QDialog::Accepted) {
624         QPixmap pix = dia_ui->renderedPixmap();
625         pix.save(path + ".png");
626         dia_ui->saveTitle(path + ".kdenlivetitle");
627         //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
628         emit refreshClipThumbnail(id);
629     }
630     delete dia_ui;
631 }
632
633
634 #include "kdenlivedoc.moc"
635