]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
Fix dropframe timecode, patch from John T. Mertz
[kdenlive] / src / clipproperties.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 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
21 #include "clipproperties.h"
22 #include "kdenlivesettings.h"
23 #include "kthumb.h"
24 #include "markerdialog.h"
25
26 #include <KStandardDirs>
27 #include <KDebug>
28 #include <KFileItem>
29
30 #include <QDir>
31
32 static const int VIDEOTAB = 0;
33 static const int AUDIOTAB = 1;
34 static const int COLORTAB = 2;
35 static const int SLIDETAB = 3;
36 static const int IMAGETAB = 4;
37 static const int MARKERTAB = 5;
38 static const int METATAB = 6;
39 static const int ADVANCEDTAB = 7;
40
41 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
42         QDialog(parent),
43         m_clip(clip),
44         m_tc(tc),
45         m_fps(fps),
46         m_count(0),
47         m_clipNeedsRefresh(false),
48         m_clipNeedsReLoad(false)
49 {
50     setFont(KGlobalSettings::toolBarFont());
51     m_view.setupUi(this);
52     KUrl url = m_clip->fileURL();
53     m_view.clip_path->setText(url.path());
54     m_view.clip_description->setText(m_clip->description());
55     QMap <QString, QString> props = m_clip->properties();
56
57     m_view.clip_force_out->setHidden(true);
58     m_view.clip_out->setHidden(true);
59
60     if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
61         m_view.clip_force_ar->setChecked(true);
62         m_view.clip_ar->setEnabled(true);
63         m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
64     }
65
66     if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
67         m_view.clip_force_framerate->setChecked(true);
68         m_view.clip_framerate->setEnabled(true);
69         m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
70     }
71
72     if (props.contains("force_progressive")) {
73         m_view.clip_force_progressive->setChecked(true);
74         m_view.clip_progressive->setEnabled(true);
75         m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
76     }
77
78     if (props.contains("threads") && props.value("threads").toInt() != 1) {
79         m_view.clip_force_threads->setChecked(true);
80         m_view.clip_threads->setEnabled(true);
81         m_view.clip_threads->setValue(props.value("threads").toInt());
82     }
83
84     if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
85         m_view.clip_force_vindex->setChecked(true);
86         m_view.clip_vindex->setEnabled(true);
87         m_view.clip_vindex->setValue(props.value("video_index").toInt());
88     }
89
90     if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
91         m_view.clip_force_aindex->setChecked(true);
92         m_view.clip_aindex->setEnabled(true);
93         m_view.clip_aindex->setValue(props.value("audio_index").toInt());
94     }
95
96     if (props.contains("audio_max")) {
97         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
98     }
99
100     if (props.contains("video_max")) {
101         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
102     }
103
104     // Check for Metadata
105     QMap<QString, QString> meta = m_clip->metadata();
106     QMap<QString, QString>::const_iterator i = meta.constBegin();
107     while (i != meta.constEnd()) {
108         QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
109         metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
110         metaitem->setText(1, i.value());
111         ++i;
112     }
113
114     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
115     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
116     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
117     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
118     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
119     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
120
121     if (props.contains("audiocodec"))
122         m_view.clip_acodec->setText(props.value("audiocodec"));
123     if (props.contains("frequency"))
124         m_view.clip_frequency->setText(props.value("frequency"));
125     if (props.contains("channels"))
126         m_view.clip_channels->setText(props.value("channels"));
127
128     CLIPTYPE t = m_clip->clipType();
129     if (t != AUDIO && t != AV) {
130         m_view.clip_force_aindex->setEnabled(false);
131     }
132
133     if (t != VIDEO && t != AV) {
134         m_view.clip_force_vindex->setEnabled(false);
135     }
136
137     if (t == IMAGE) {
138         m_view.tabWidget->removeTab(SLIDETAB);
139         m_view.tabWidget->removeTab(COLORTAB);
140         m_view.tabWidget->removeTab(AUDIOTAB);
141         m_view.tabWidget->removeTab(VIDEOTAB);
142         if (props.contains("frame_size"))
143             m_view.image_size->setText(props.value("frame_size"));
144         if (props.contains("transparency"))
145             m_view.image_transparency->setChecked(props.value("transparency").toInt());
146         int width = 180.0 * KdenliveSettings::project_display_ratio();
147         if (width % 2 == 1) width++;
148         m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
149     } else if (t == COLOR) {
150         m_view.clip_path->setEnabled(false);
151         m_view.tabWidget->removeTab(METATAB);
152         m_view.tabWidget->removeTab(IMAGETAB);
153         m_view.tabWidget->removeTab(SLIDETAB);
154         m_view.tabWidget->removeTab(AUDIOTAB);
155         m_view.tabWidget->removeTab(VIDEOTAB);
156         m_view.clip_thumb->setHidden(true);
157         m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
158     } else if (t == SLIDESHOW) {
159         m_view.clip_path->setText(url.directory());
160         m_view.tabWidget->removeTab(METATAB);
161         m_view.tabWidget->removeTab(IMAGETAB);
162         m_view.tabWidget->removeTab(COLORTAB);
163         m_view.tabWidget->removeTab(AUDIOTAB);
164         m_view.tabWidget->removeTab(VIDEOTAB);
165
166         //WARNING: Keep in sync with slideshowclip.cpp
167         m_view.image_type->addItem("JPG (*.jpg)", "jpg");
168         m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
169         m_view.image_type->addItem("PNG (*.png)", "png");
170         m_view.image_type->addItem("BMP (*.bmp)", "bmp");
171         m_view.image_type->addItem("GIF (*.gif)", "gif");
172         m_view.image_type->addItem("TGA (*.tga)", "tga");
173         m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
174         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
175
176         m_view.slide_loop->setChecked(props.value("loop").toInt());
177         m_view.slide_fade->setChecked(props.value("fade").toInt());
178         m_view.luma_softness->setValue(props.value("softness").toInt());
179         QString path = props.value("resource");
180         QString ext = path.section('.', -1);
181         for (int i = 0; i < m_view.image_type->count(); i++) {
182             if (m_view.image_type->itemData(i).toString() == ext) {
183                 m_view.image_type->setCurrentIndex(i);
184                 break;
185             }
186         }
187         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
188
189         m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
190         m_view.slide_duration_format->addItem(i18n("Frames"));
191         connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
192         m_view.slide_duration_frames->setHidden(true);
193         m_view.luma_duration_frames->setHidden(true);
194
195         parseFolder();
196
197         m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
198         QString lumaFile = props.value("luma_file");
199
200         // Check for Kdenlive installed luma files
201         QStringList filters;
202         filters << "*.pgm" << "*.png";
203
204         QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
205         foreach(const QString &folder, customLumas) {
206             QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
207             foreach(const QString &fname, filesnames) {
208                 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
209                 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
210             }
211         }
212
213         // Check for MLT lumas
214         QString profilePath = KdenliveSettings::mltpath();
215         QString folder = profilePath.section('/', 0, -3);
216         folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
217         QDir lumafolder(folder);
218         QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
219         foreach(const QString &fname, filesnames) {
220             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
221             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
222         }
223
224         if (!lumaFile.isEmpty()) {
225             m_view.slide_luma->setChecked(true);
226             m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
227         } else m_view.luma_file->setEnabled(false);
228         slotEnableLuma(m_view.slide_fade->checkState());
229         slotEnableLumaFile(m_view.slide_luma->checkState());
230         connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
231         connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
232
233         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
234     } else if (t != AUDIO) {
235         m_view.tabWidget->removeTab(IMAGETAB);
236         m_view.tabWidget->removeTab(SLIDETAB);
237         m_view.tabWidget->removeTab(COLORTAB);
238         if (props.contains("frame_size"))
239             m_view.clip_size->setText(props.value("frame_size"));
240         if (props.contains("videocodec"))
241             m_view.clip_vcodec->setText(props.value("videocodec"));
242         if (props.contains("fps")) {
243             m_view.clip_fps->setText(props.value("fps"));
244             if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
245         }
246         if (props.contains("aspect_ratio"))
247             m_view.clip_ratio->setText(props.value("aspect_ratio"));
248         int width = 180.0 * KdenliveSettings::project_display_ratio();
249         if (width % 2 == 1) width++;
250         QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
251         m_view.clip_thumb->setPixmap(pix);
252         if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
253     } else {
254         m_view.tabWidget->removeTab(IMAGETAB);
255         m_view.tabWidget->removeTab(SLIDETAB);
256         m_view.tabWidget->removeTab(COLORTAB);
257         m_view.tabWidget->removeTab(VIDEOTAB);
258         m_view.clip_thumb->setHidden(true);
259     }
260
261     if (t != SLIDESHOW && t != COLOR) {
262         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
263         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
264     } else {
265         m_view.clip_filesize->setHidden(true);
266         m_view.label_size->setHidden(true);
267     }
268     m_view.clip_duration->setInputMask(tc.inputMask());
269     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
270     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
271     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
272
273     // markers
274     m_view.marker_new->setIcon(KIcon("document-new"));
275     m_view.marker_new->setToolTip(i18n("Add marker"));
276     m_view.marker_edit->setIcon(KIcon("document-properties"));
277     m_view.marker_edit->setToolTip(i18n("Edit marker"));
278     m_view.marker_delete->setIcon(KIcon("trash-empty"));
279     m_view.marker_delete->setToolTip(i18n("Delete marker"));
280
281     slotFillMarkersList();
282     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
283     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
284     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
285     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
286
287     //adjustSize();
288 }
289
290
291 // Used for multiple clips editing
292 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
293         QDialog(parent),
294         m_clip(NULL),
295         m_tc(tc),
296         m_fps(0),
297         m_count(0),
298         m_clipNeedsRefresh(false),
299         m_clipNeedsReLoad(false)
300 {
301     setFont(KGlobalSettings::toolBarFont());
302     m_view.setupUi(this);
303     QMap <QString, QString> props = cliplist.at(0)->properties();
304     m_old_props = commonproperties;
305
306     if (commonproperties.contains("force_aspect_ratio") && !commonproperties.value("force_aspect_ratio").isEmpty() && commonproperties.value("force_aspect_ratio").toDouble() > 0) {
307         m_view.clip_force_ar->setChecked(true);
308         m_view.clip_ar->setEnabled(true);
309         m_view.clip_ar->setValue(commonproperties.value("force_aspect_ratio").toDouble());
310     }
311
312     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
313         m_view.clip_force_framerate->setChecked(true);
314         m_view.clip_framerate->setEnabled(true);
315         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
316     }
317
318     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
319         m_view.clip_force_progressive->setChecked(true);
320         m_view.clip_progressive->setEnabled(true);
321         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
322     }
323
324     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
325         m_view.clip_force_threads->setChecked(true);
326         m_view.clip_threads->setEnabled(true);
327         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
328     }
329
330     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
331         m_view.clip_force_vindex->setChecked(true);
332         m_view.clip_vindex->setEnabled(true);
333         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
334     }
335
336     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
337         m_view.clip_force_aindex->setChecked(true);
338         m_view.clip_aindex->setEnabled(true);
339         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
340     }
341
342     if (props.contains("audio_max")) {
343         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
344     }
345
346     if (props.contains("video_max")) {
347         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
348     }
349
350     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
351     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
352     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
353     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
354     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
355     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
356
357     m_view.tabWidget->removeTab(METATAB);
358     m_view.tabWidget->removeTab(MARKERTAB);
359     m_view.tabWidget->removeTab(IMAGETAB);
360     m_view.tabWidget->removeTab(SLIDETAB);
361     m_view.tabWidget->removeTab(COLORTAB);
362     m_view.tabWidget->removeTab(AUDIOTAB);
363     m_view.tabWidget->removeTab(VIDEOTAB);
364
365     m_view.clip_path->setHidden(true);
366     m_view.label_path->setHidden(true);
367     m_view.label_description->setHidden(true);
368     m_view.label_size->setHidden(true);
369     m_view.clip_filesize->setHidden(true);
370     m_view.clip_filesize->setHidden(true);
371     m_view.clip_path->setHidden(true);
372     m_view.clip_description->setHidden(true);
373     m_view.clip_thumb->setHidden(true);
374     m_view.label_duration->setHidden(true);
375     m_view.clip_duration->setHidden(true);
376
377     if (commonproperties.contains("out")) {
378         if (commonproperties.value("out").toInt() > 0) {
379             m_view.clip_force_out->setChecked(true);
380             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
381         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
382     } else {
383         m_view.clip_force_out->setHidden(true);
384         m_view.clip_out->setHidden(true);
385     }
386 }
387
388
389
390 void ClipProperties::slotEnableLuma(int state)
391 {
392     bool enable = false;
393     if (state == Qt::Checked) enable = true;
394     m_view.luma_duration->setEnabled(enable);
395     m_view.luma_duration_frames->setEnabled(enable);
396     m_view.slide_luma->setEnabled(enable);
397     if (enable) {
398         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
399     } else m_view.luma_file->setEnabled(false);
400     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
401     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
402 }
403
404 void ClipProperties::slotEnableLumaFile(int state)
405 {
406     bool enable = false;
407     if (state == Qt::Checked) enable = true;
408     m_view.luma_file->setEnabled(enable);
409     m_view.luma_softness->setEnabled(enable);
410     m_view.label_softness->setEnabled(enable);
411 }
412
413 void ClipProperties::slotFillMarkersList()
414 {
415     m_view.markers_list->clear();
416     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
417     for (int count = 0; count < marks.count(); ++count) {
418         QString time = m_tc.getTimecode(marks[count].time());
419         QStringList itemtext;
420         itemtext << time << marks[count].comment();
421         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
422     }
423 }
424
425 void ClipProperties::slotAddMarker()
426 {
427     CommentedTime marker(GenTime(), i18n("Marker"));
428     MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
429     if (d.exec() == QDialog::Accepted) {
430         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
431     }
432     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
433 }
434
435 void ClipProperties::slotEditMarker()
436 {
437     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
438     int pos = m_view.markers_list->currentIndex().row();
439     if (pos < 0 || pos > marks.count() - 1) return;
440     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
441     if (d.exec() == QDialog::Accepted) {
442         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
443     }
444     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
445 }
446
447 void ClipProperties::slotDeleteMarker()
448 {
449     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
450     int pos = m_view.markers_list->currentIndex().row();
451     if (pos < 0 || pos > marks.count() - 1) return;
452     emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
453
454     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
455 }
456
457 const QString &ClipProperties::clipId() const
458 {
459     return m_clip->getId();
460 }
461
462
463 QMap <QString, QString> ClipProperties::properties()
464 {
465     QMap <QString, QString> props;
466     CLIPTYPE t = UNKNOWN;
467     if (m_clip != NULL) {
468         t = m_clip->clipType();
469         m_old_props = m_clip->properties();
470     }
471
472     double aspect = m_view.clip_ar->value();
473     if (m_view.clip_force_ar->isChecked()) {
474         if (aspect != m_old_props.value("force_aspect_ratio").toDouble()) {
475             props["force_aspect_ratio"] = QString::number(aspect);
476             m_clipNeedsRefresh = true;
477         }
478     } else if (m_old_props.contains("force_aspect_ratio")) {
479         props["force_aspect_ratio"].clear();
480         m_clipNeedsRefresh = true;
481     }
482
483     double fps = m_view.clip_framerate->value();
484     if (m_view.clip_force_framerate->isChecked()) {
485         if (fps != m_old_props.value("force_fps").toDouble()) {
486             props["force_fps"] = QString::number(fps);
487             m_clipNeedsRefresh = true;
488         }
489     } else if (m_old_props.contains("force_fps")) {
490         props["force_fps"].clear();
491         m_clipNeedsRefresh = true;
492     }
493
494     int progressive = m_view.clip_progressive->value();
495     if (m_view.clip_force_progressive->isChecked()) {
496         if (progressive != m_old_props.value("force_progressive").toInt()) {
497             props["force_progressive"] = QString::number(progressive);
498         }
499     } else if (m_old_props.contains("force_progressive")) {
500         props["force_progressive"].clear();
501     }
502
503     int threads = m_view.clip_threads->value();
504     if (m_view.clip_force_threads->isChecked()) {
505         if (threads != m_old_props.value("threads").toInt()) {
506             props["threads"] = QString::number(threads);
507         }
508     } else if (m_old_props.contains("threads")) {
509         props["threads"].clear();
510     }
511
512     int vindex = m_view.clip_vindex->value();
513     if (m_view.clip_force_vindex->isChecked()) {
514         if (vindex != m_old_props.value("video_index").toInt()) {
515             props["video_index"] = QString::number(vindex);
516         }
517     } else if (m_old_props.contains("video_index")) {
518         props["video_index"].clear();
519     }
520
521     int aindex = m_view.clip_aindex->value();
522     if (m_view.clip_force_aindex->isChecked()) {
523         if (aindex != m_old_props.value("audio_index").toInt()) {
524             props["audio_index"] = QString::number(aindex);
525         }
526     } else if (m_old_props.contains("audio_index")) {
527         props["audio_index"].clear();
528     }
529
530     // If we adjust several clips, return now
531     if (m_clip == NULL) {
532         if (m_view.clip_out->isEnabled()) {
533             int duration = m_tc.getFrameCount(m_view.clip_out->text());
534             if (duration != m_old_props.value("out").toInt()) {
535                 props["out"] = QString::number(duration - 1);
536             }
537         }
538         return props;
539     }
540
541     if (m_old_props.value("description") != m_view.clip_description->text())
542         props["description"] = m_view.clip_description->text();
543
544     if (t == COLOR) {
545         QString new_color = m_view.clip_color->color().name();
546         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
547             m_clipNeedsRefresh = true;
548             props["colour"] = "0x" + new_color.right(6) + "ff";
549         }
550         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
551         if (duration != m_clip->duration().frames(m_fps)) {
552             props["out"] = QString::number(duration - 1);
553         }
554     } else if (t == IMAGE) {
555         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
556             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
557             //m_clipNeedsRefresh = true;
558         }
559         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
560         if (duration != m_clip->duration().frames(m_fps)) {
561             props["out"] = QString::number(duration - 1);
562         }
563     } else if (t == SLIDESHOW) {
564         QString value = QString::number((int) m_view.slide_loop->isChecked());
565         if (m_old_props.value("loop") != value) props["loop"] = value;
566         value = QString::number((int) m_view.slide_fade->isChecked());
567         if (m_old_props.value("fade") != value) props["fade"] = value;
568         value = QString::number((int) m_view.luma_softness->value());
569         if (m_old_props.value("softness") != value) props["softness"] = value;
570
571         QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
572         QString new_path = m_view.clip_path->text() + extension;
573         if (new_path != m_old_props.value("resource")) {
574             m_clipNeedsReLoad = true;
575             props["resource"] = new_path;
576             kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
577         }
578         int duration;
579         if (m_view.slide_duration_format->currentIndex() == 1) {
580             // we are in frames mode
581             duration = m_view.slide_duration_frames->value();
582         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
583         if (duration != m_old_props.value("ttl").toInt()) {
584             m_clipNeedsRefresh = true;
585             props["ttl"] = QString::number(duration);
586             props["out"] = QString::number(duration * m_count);
587         }
588
589         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
590             m_clipNeedsRefresh = true;
591             props["out"] = QString::number(duration * m_count - 1);
592         }
593         if (m_view.slide_fade->isChecked()) {
594             int luma_duration;
595             if (m_view.slide_duration_format->currentIndex() == 1) {
596                 // we are in frames mode
597                 luma_duration = m_view.luma_duration_frames->value();
598             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
599             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
600                 m_clipNeedsRefresh = true;
601                 props["luma_duration"] = QString::number(luma_duration);
602             }
603             QString lumaFile;
604             if (m_view.slide_luma->isChecked())
605                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
606             if (lumaFile != m_old_props.value("luma_file")) {
607                 m_clipNeedsRefresh = true;
608                 props["luma_file"] = lumaFile;
609             }
610         } else {
611             if (!m_old_props.value("luma_file").isEmpty()) {
612                 props["luma_file"].clear();
613             }
614         }
615
616     }
617     return props;
618 }
619
620 bool ClipProperties::needsTimelineRefresh() const
621 {
622     return m_clipNeedsRefresh;
623 }
624
625 bool ClipProperties::needsTimelineReload() const
626 {
627     return m_clipNeedsReLoad;
628 }
629
630 void ClipProperties::parseFolder()
631 {
632
633     QDir dir(m_view.clip_path->text());
634     QStringList filters;
635     filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
636     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
637
638     dir.setNameFilters(filters);
639     QStringList result = dir.entryList(QDir::Files);
640     m_count = result.count();
641     if (m_count == 0) {
642         // no images, do not accept that
643         m_view.slide_info->setText(i18n("No image found"));
644         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
645         return;
646     }
647     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
648     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
649     QDomElement xml = m_clip->toXML();
650     xml.setAttribute("resource", m_view.clip_path->text() + extension);
651     int width = 180.0 * KdenliveSettings::project_display_ratio();
652     if (width % 2 == 1) width++;
653     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, width, 180);
654     QMap <QString, QString> props = m_clip->properties();
655     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
656     m_view.clip_thumb->setPixmap(pix);
657 }
658
659 void ClipProperties::slotCheckMaxLength()
660 {
661     if (m_clip->maxDuration() == GenTime()) return;
662     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
663     if (duration > m_clip->maxDuration().frames(m_fps)) {
664         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
665     }
666 }
667
668 void ClipProperties::slotUpdateDurationFormat(int ix)
669 {
670     bool framesFormat = ix == 1;
671     if (framesFormat) {
672         // switching to frames count, update widget
673         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
674         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
675         m_view.slide_duration->setHidden(true);
676         m_view.luma_duration->setHidden(true);
677         m_view.slide_duration_frames->setHidden(false);
678         m_view.luma_duration_frames->setHidden(false);
679     } else {
680         // switching to timecode format
681         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
682         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
683         m_view.slide_duration_frames->setHidden(true);
684         m_view.luma_duration_frames->setHidden(true);
685         m_view.slide_duration->setHidden(false);
686         m_view.luma_duration->setHidden(false);
687     }
688 }
689
690 #include "clipproperties.moc"
691
692