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