]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
89dcc6dc39978238d10a4a7780fc037ba5885dee
[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->setText(tc.getTimecode(m_clip->duration()));
269     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
270     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
271
272     // markers
273     m_view.marker_new->setIcon(KIcon("document-new"));
274     m_view.marker_new->setToolTip(i18n("Add marker"));
275     m_view.marker_edit->setIcon(KIcon("document-properties"));
276     m_view.marker_edit->setToolTip(i18n("Edit marker"));
277     m_view.marker_delete->setIcon(KIcon("trash-empty"));
278     m_view.marker_delete->setToolTip(i18n("Delete marker"));
279
280     slotFillMarkersList();
281     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
282     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
283     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
284     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
285
286     //adjustSize();
287 }
288
289
290 // Used for multiple clips editing
291 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
292         QDialog(parent),
293         m_clip(NULL),
294         m_tc(tc),
295         m_fps(0),
296         m_count(0),
297         m_clipNeedsRefresh(false),
298         m_clipNeedsReLoad(false)
299 {
300     setFont(KGlobalSettings::toolBarFont());
301     m_view.setupUi(this);
302     QMap <QString, QString> props = cliplist.at(0)->properties();
303     m_old_props = commonproperties;
304
305     if (commonproperties.contains("force_aspect_ratio") && !commonproperties.value("force_aspect_ratio").isEmpty() && commonproperties.value("force_aspect_ratio").toDouble() > 0) {
306         m_view.clip_force_ar->setChecked(true);
307         m_view.clip_ar->setEnabled(true);
308         m_view.clip_ar->setValue(commonproperties.value("force_aspect_ratio").toDouble());
309     }
310
311     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
312         m_view.clip_force_framerate->setChecked(true);
313         m_view.clip_framerate->setEnabled(true);
314         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
315     }
316
317     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
318         m_view.clip_force_progressive->setChecked(true);
319         m_view.clip_progressive->setEnabled(true);
320         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
321     }
322
323     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
324         m_view.clip_force_threads->setChecked(true);
325         m_view.clip_threads->setEnabled(true);
326         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
327     }
328
329     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
330         m_view.clip_force_vindex->setChecked(true);
331         m_view.clip_vindex->setEnabled(true);
332         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
333     }
334
335     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
336         m_view.clip_force_aindex->setChecked(true);
337         m_view.clip_aindex->setEnabled(true);
338         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
339     }
340
341     if (props.contains("audio_max")) {
342         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
343     }
344
345     if (props.contains("video_max")) {
346         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
347     }
348
349     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
350     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
351     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
352     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
353     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
354     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
355
356     m_view.tabWidget->removeTab(METATAB);
357     m_view.tabWidget->removeTab(MARKERTAB);
358     m_view.tabWidget->removeTab(IMAGETAB);
359     m_view.tabWidget->removeTab(SLIDETAB);
360     m_view.tabWidget->removeTab(COLORTAB);
361     m_view.tabWidget->removeTab(AUDIOTAB);
362     m_view.tabWidget->removeTab(VIDEOTAB);
363
364     m_view.clip_path->setHidden(true);
365     m_view.label_path->setHidden(true);
366     m_view.label_description->setHidden(true);
367     m_view.label_size->setHidden(true);
368     m_view.clip_filesize->setHidden(true);
369     m_view.clip_filesize->setHidden(true);
370     m_view.clip_path->setHidden(true);
371     m_view.clip_description->setHidden(true);
372     m_view.clip_thumb->setHidden(true);
373     m_view.label_duration->setHidden(true);
374     m_view.clip_duration->setHidden(true);
375
376     if (commonproperties.contains("out")) {
377         if (commonproperties.value("out").toInt() > 0) {
378             m_view.clip_force_out->setChecked(true);
379             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
380         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
381     } else {
382         m_view.clip_force_out->setHidden(true);
383         m_view.clip_out->setHidden(true);
384     }
385 }
386
387
388
389 void ClipProperties::slotEnableLuma(int state)
390 {
391     bool enable = false;
392     if (state == Qt::Checked) enable = true;
393     m_view.luma_duration->setEnabled(enable);
394     m_view.luma_duration_frames->setEnabled(enable);
395     m_view.slide_luma->setEnabled(enable);
396     if (enable) {
397         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
398     } else m_view.luma_file->setEnabled(false);
399     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
400     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
401 }
402
403 void ClipProperties::slotEnableLumaFile(int state)
404 {
405     bool enable = false;
406     if (state == Qt::Checked) enable = true;
407     m_view.luma_file->setEnabled(enable);
408     m_view.luma_softness->setEnabled(enable);
409     m_view.label_softness->setEnabled(enable);
410 }
411
412 void ClipProperties::slotFillMarkersList()
413 {
414     m_view.markers_list->clear();
415     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
416     for (int count = 0; count < marks.count(); ++count) {
417         QString time = m_tc.getTimecode(marks[count].time());
418         QStringList itemtext;
419         itemtext << time << marks[count].comment();
420         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
421     }
422 }
423
424 void ClipProperties::slotAddMarker()
425 {
426     CommentedTime marker(GenTime(), i18n("Marker"));
427     MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
428     if (d.exec() == QDialog::Accepted) {
429         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
430     }
431     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
432 }
433
434 void ClipProperties::slotEditMarker()
435 {
436     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
437     int pos = m_view.markers_list->currentIndex().row();
438     if (pos < 0 || pos > marks.count() - 1) return;
439     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
440     if (d.exec() == QDialog::Accepted) {
441         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
442     }
443     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
444 }
445
446 void ClipProperties::slotDeleteMarker()
447 {
448     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
449     int pos = m_view.markers_list->currentIndex().row();
450     if (pos < 0 || pos > marks.count() - 1) return;
451     emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
452
453     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
454 }
455
456 const QString &ClipProperties::clipId() const
457 {
458     return m_clip->getId();
459 }
460
461
462 QMap <QString, QString> ClipProperties::properties()
463 {
464     QMap <QString, QString> props;
465     CLIPTYPE t = UNKNOWN;
466     if (m_clip != NULL) {
467         t = m_clip->clipType();
468         m_old_props = m_clip->properties();
469     }
470
471     double aspect = m_view.clip_ar->value();
472     if (m_view.clip_force_ar->isChecked()) {
473         if (aspect != m_old_props.value("force_aspect_ratio").toDouble()) {
474             props["force_aspect_ratio"] = QString::number(aspect);
475             m_clipNeedsRefresh = true;
476         }
477     } else if (m_old_props.contains("force_aspect_ratio")) {
478         props["force_aspect_ratio"].clear();
479         m_clipNeedsRefresh = true;
480     }
481
482     double fps = m_view.clip_framerate->value();
483     if (m_view.clip_force_framerate->isChecked()) {
484         if (fps != m_old_props.value("force_fps").toDouble()) {
485             props["force_fps"] = QString::number(fps);
486             m_clipNeedsRefresh = true;
487         }
488     } else if (m_old_props.contains("force_fps")) {
489         props["force_fps"].clear();
490         m_clipNeedsRefresh = true;
491     }
492
493     int progressive = m_view.clip_progressive->value();
494     if (m_view.clip_force_progressive->isChecked()) {
495         if (progressive != m_old_props.value("force_progressive").toInt()) {
496             props["force_progressive"] = QString::number(progressive);
497         }
498     } else if (m_old_props.contains("force_progressive")) {
499         props["force_progressive"].clear();
500     }
501
502     int threads = m_view.clip_threads->value();
503     if (m_view.clip_force_threads->isChecked()) {
504         if (threads != m_old_props.value("threads").toInt()) {
505             props["threads"] = QString::number(threads);
506         }
507     } else if (m_old_props.contains("threads")) {
508         props["threads"].clear();
509     }
510
511     int vindex = m_view.clip_vindex->value();
512     if (m_view.clip_force_vindex->isChecked()) {
513         if (vindex != m_old_props.value("video_index").toInt()) {
514             props["video_index"] = QString::number(vindex);
515         }
516     } else if (m_old_props.contains("video_index")) {
517         props["video_index"].clear();
518     }
519
520     int aindex = m_view.clip_aindex->value();
521     if (m_view.clip_force_aindex->isChecked()) {
522         if (aindex != m_old_props.value("audio_index").toInt()) {
523             props["audio_index"] = QString::number(aindex);
524         }
525     } else if (m_old_props.contains("audio_index")) {
526         props["audio_index"].clear();
527     }
528
529     // If we adjust several clips, return now
530     if (m_clip == NULL) {
531         if (m_view.clip_out->isEnabled()) {
532             int duration = m_tc.getFrameCount(m_view.clip_out->text());
533             if (duration != m_old_props.value("out").toInt()) {
534                 props["out"] = QString::number(duration - 1);
535             }
536         }
537         return props;
538     }
539
540     if (m_old_props.value("description") != m_view.clip_description->text())
541         props["description"] = m_view.clip_description->text();
542
543     if (t == COLOR) {
544         QString new_color = m_view.clip_color->color().name();
545         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
546             m_clipNeedsRefresh = true;
547             props["colour"] = "0x" + new_color.right(6) + "ff";
548         }
549         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
550         if (duration != m_clip->duration().frames(m_fps)) {
551             props["out"] = QString::number(duration - 1);
552         }
553     } else if (t == IMAGE) {
554         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
555             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
556             //m_clipNeedsRefresh = true;
557         }
558         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
559         if (duration != m_clip->duration().frames(m_fps)) {
560             props["out"] = QString::number(duration - 1);
561         }
562     } else if (t == SLIDESHOW) {
563         QString value = QString::number((int) m_view.slide_loop->isChecked());
564         if (m_old_props.value("loop") != value) props["loop"] = value;
565         value = QString::number((int) m_view.slide_fade->isChecked());
566         if (m_old_props.value("fade") != value) props["fade"] = value;
567         value = QString::number((int) m_view.luma_softness->value());
568         if (m_old_props.value("softness") != value) props["softness"] = value;
569
570         QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
571         QString new_path = m_view.clip_path->text() + extension;
572         if (new_path != m_old_props.value("resource")) {
573             m_clipNeedsReLoad = true;
574             props["resource"] = new_path;
575             kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
576         }
577         int duration;
578         if (m_view.slide_duration_format->currentIndex() == 1) {
579             // we are in frames mode
580             duration = m_view.slide_duration_frames->value();
581         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
582         if (duration != m_old_props.value("ttl").toInt()) {
583             m_clipNeedsRefresh = true;
584             props["ttl"] = QString::number(duration);
585             props["out"] = QString::number(duration * m_count);
586         }
587
588         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
589             m_clipNeedsRefresh = true;
590             props["out"] = QString::number(duration * m_count - 1);
591         }
592         if (m_view.slide_fade->isChecked()) {
593             int luma_duration;
594             if (m_view.slide_duration_format->currentIndex() == 1) {
595                 // we are in frames mode
596                 luma_duration = m_view.luma_duration_frames->value();
597             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
598             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
599                 m_clipNeedsRefresh = true;
600                 props["luma_duration"] = QString::number(luma_duration);
601             }
602             QString lumaFile;
603             if (m_view.slide_luma->isChecked())
604                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
605             if (lumaFile != m_old_props.value("luma_file")) {
606                 m_clipNeedsRefresh = true;
607                 props["luma_file"] = lumaFile;
608             }
609         } else {
610             if (!m_old_props.value("luma_file").isEmpty()) {
611                 props["luma_file"].clear();
612             }
613         }
614
615     }
616     return props;
617 }
618
619 bool ClipProperties::needsTimelineRefresh() const
620 {
621     return m_clipNeedsRefresh;
622 }
623
624 bool ClipProperties::needsTimelineReload() const
625 {
626     return m_clipNeedsReLoad;
627 }
628
629 void ClipProperties::parseFolder()
630 {
631
632     QDir dir(m_view.clip_path->text());
633     QStringList filters;
634     filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
635     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
636
637     dir.setNameFilters(filters);
638     QStringList result = dir.entryList(QDir::Files);
639     m_count = result.count();
640     if (m_count == 0) {
641         // no images, do not accept that
642         m_view.slide_info->setText(i18n("No image found"));
643         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
644         return;
645     }
646     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
647     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
648     QDomElement xml = m_clip->toXML();
649     xml.setAttribute("resource", m_view.clip_path->text() + extension);
650     int width = 180.0 * KdenliveSettings::project_display_ratio();
651     if (width % 2 == 1) width++;
652     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, width, 180);
653     QMap <QString, QString> props = m_clip->properties();
654     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
655     m_view.clip_thumb->setPixmap(pix);
656 }
657
658 void ClipProperties::slotCheckMaxLength()
659 {
660     if (m_clip->maxDuration() == GenTime()) return;
661     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
662     if (duration > m_clip->maxDuration().frames(m_fps)) {
663         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
664     }
665 }
666
667 void ClipProperties::slotUpdateDurationFormat(int ix)
668 {
669     bool framesFormat = ix == 1;
670     if (framesFormat) {
671         // switching to frames count, update widget
672         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
673         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
674         m_view.slide_duration->setHidden(true);
675         m_view.luma_duration->setHidden(true);
676         m_view.slide_duration_frames->setHidden(false);
677         m_view.luma_duration_frames->setHidden(false);
678     } else {
679         // switching to timecode format
680         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
681         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
682         m_view.slide_duration_frames->setHidden(true);
683         m_view.luma_duration_frames->setHidden(true);
684         m_view.slide_duration->setHidden(false);
685         m_view.luma_duration->setHidden(false);
686     }
687 }
688
689 #include "clipproperties.moc"
690
691