]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
* Add preliminary support for Blackmagic HDMI capture card
[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         bool isMime = true;
160         if (url.fileName().startsWith(".all.")) {
161             // the image sequence is defined by mimetype
162             m_view.clip_path->setText(url.directory());
163         } else {
164             // the image sequence is defined by pattern
165             m_view.slide_type_label->setHidden(true);
166             m_view.image_type->setHidden(true);
167             m_view.clip_path->setText(url.path());
168             isMime = false;
169         }
170
171         m_view.tabWidget->removeTab(METATAB);
172         m_view.tabWidget->removeTab(IMAGETAB);
173         m_view.tabWidget->removeTab(COLORTAB);
174         m_view.tabWidget->removeTab(AUDIOTAB);
175         m_view.tabWidget->removeTab(VIDEOTAB);
176
177         //WARNING: Keep in sync with slideshowclip.cpp
178         m_view.image_type->addItem("JPG (*.jpg)", "jpg");
179         m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
180         m_view.image_type->addItem("PNG (*.png)", "png");
181         m_view.image_type->addItem("BMP (*.bmp)", "bmp");
182         m_view.image_type->addItem("GIF (*.gif)", "gif");
183         m_view.image_type->addItem("TGA (*.tga)", "tga");
184         m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
185         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
186         m_view.animation->addItem(i18n("None"), QString());
187         m_view.animation->addItem(i18n("Pan"), "Pan");
188         m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
189         m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
190         m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
191         m_view.animation->addItem(i18n("Zoom"), "Zoom");
192         m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
193
194         m_view.slide_loop->setChecked(props.value("loop").toInt());
195         m_view.slide_crop->setChecked(props.value("crop").toInt());
196         m_view.slide_fade->setChecked(props.value("fade").toInt());
197         m_view.luma_softness->setValue(props.value("softness").toInt());
198         if (!props.value("animation").isEmpty())
199             m_view.animation->setCurrentItem(props.value("animation"));
200         else
201             m_view.animation->setCurrentIndex(0);
202         QString path = props.value("resource");
203         QString ext = path.section('.', -1);
204         for (int i = 0; i < m_view.image_type->count(); i++) {
205             if (m_view.image_type->itemData(i).toString() == ext) {
206                 m_view.image_type->setCurrentIndex(i);
207                 break;
208             }
209         }
210         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
211
212         m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
213         m_view.slide_duration_format->addItem(i18n("Frames"));
214         connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
215         m_view.slide_duration_frames->setHidden(true);
216         m_view.luma_duration_frames->setHidden(true);
217
218         parseFolder();
219
220         m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
221         QString lumaFile = props.value("luma_file");
222
223         // Check for Kdenlive installed luma files
224         QStringList filters;
225         filters << "*.pgm" << "*.png";
226
227         QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
228         foreach(const QString &folder, customLumas) {
229             QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
230             foreach(const QString &fname, filesnames) {
231                 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
232                 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
233             }
234         }
235
236         // Check for MLT lumas
237         QString profilePath = KdenliveSettings::mltpath();
238         QString folder = profilePath.section('/', 0, -3);
239         folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
240         QDir lumafolder(folder);
241         QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
242         foreach(const QString &fname, filesnames) {
243             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
244             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
245         }
246
247         if (!lumaFile.isEmpty()) {
248             m_view.slide_luma->setChecked(true);
249             m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
250         } else m_view.luma_file->setEnabled(false);
251         slotEnableLuma(m_view.slide_fade->checkState());
252         slotEnableLumaFile(m_view.slide_luma->checkState());
253         connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
254         connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
255
256         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
257     } else if (t != AUDIO) {
258         m_view.tabWidget->removeTab(IMAGETAB);
259         m_view.tabWidget->removeTab(SLIDETAB);
260         m_view.tabWidget->removeTab(COLORTAB);
261         if (props.contains("frame_size"))
262             m_view.clip_size->setText(props.value("frame_size"));
263         if (props.contains("videocodec"))
264             m_view.clip_vcodec->setText(props.value("videocodec"));
265         if (props.contains("fps")) {
266             m_view.clip_fps->setText(props.value("fps"));
267             if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
268         }
269         if (props.contains("aspect_ratio"))
270             m_view.clip_ratio->setText(props.value("aspect_ratio"));
271         int width = 180.0 * KdenliveSettings::project_display_ratio();
272         if (width % 2 == 1) width++;
273         QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
274         m_view.clip_thumb->setPixmap(pix);
275         if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
276     } else {
277         m_view.tabWidget->removeTab(IMAGETAB);
278         m_view.tabWidget->removeTab(SLIDETAB);
279         m_view.tabWidget->removeTab(COLORTAB);
280         m_view.tabWidget->removeTab(VIDEOTAB);
281         m_view.clip_thumb->setHidden(true);
282     }
283
284     if (t != SLIDESHOW && t != COLOR) {
285         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
286         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
287     } else {
288         m_view.clip_filesize->setHidden(true);
289         m_view.label_size->setHidden(true);
290     }
291     m_view.clip_duration->setInputMask("");
292     m_view.clip_duration->setValidator(tc.validator());
293     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
294     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
295     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
296
297     // markers
298     m_view.marker_new->setIcon(KIcon("document-new"));
299     m_view.marker_new->setToolTip(i18n("Add marker"));
300     m_view.marker_edit->setIcon(KIcon("document-properties"));
301     m_view.marker_edit->setToolTip(i18n("Edit marker"));
302     m_view.marker_delete->setIcon(KIcon("trash-empty"));
303     m_view.marker_delete->setToolTip(i18n("Delete marker"));
304
305     slotFillMarkersList();
306     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
307     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
308     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
309     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
310
311     //adjustSize();
312 }
313
314
315 // Used for multiple clips editing
316 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
317         QDialog(parent),
318         m_clip(NULL),
319         m_tc(tc),
320         m_fps(0),
321         m_count(0),
322         m_clipNeedsRefresh(false),
323         m_clipNeedsReLoad(false)
324 {
325     setFont(KGlobalSettings::toolBarFont());
326     m_view.setupUi(this);
327     QMap <QString, QString> props = cliplist.at(0)->properties();
328     m_old_props = commonproperties;
329
330     if (commonproperties.contains("force_aspect_ratio") && !commonproperties.value("force_aspect_ratio").isEmpty() && commonproperties.value("force_aspect_ratio").toDouble() > 0) {
331         m_view.clip_force_ar->setChecked(true);
332         m_view.clip_ar->setEnabled(true);
333         m_view.clip_ar->setValue(commonproperties.value("force_aspect_ratio").toDouble());
334     }
335
336     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
337         m_view.clip_force_framerate->setChecked(true);
338         m_view.clip_framerate->setEnabled(true);
339         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
340     }
341
342     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
343         m_view.clip_force_progressive->setChecked(true);
344         m_view.clip_progressive->setEnabled(true);
345         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
346     }
347
348     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
349         m_view.clip_force_threads->setChecked(true);
350         m_view.clip_threads->setEnabled(true);
351         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
352     }
353
354     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
355         m_view.clip_force_vindex->setChecked(true);
356         m_view.clip_vindex->setEnabled(true);
357         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
358     }
359
360     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
361         m_view.clip_force_aindex->setChecked(true);
362         m_view.clip_aindex->setEnabled(true);
363         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
364     }
365
366     if (props.contains("audio_max")) {
367         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
368     }
369
370     if (props.contains("video_max")) {
371         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
372     }
373
374     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
375     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
376     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
377     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
378     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
379     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
380
381     m_view.tabWidget->removeTab(METATAB);
382     m_view.tabWidget->removeTab(MARKERTAB);
383     m_view.tabWidget->removeTab(IMAGETAB);
384     m_view.tabWidget->removeTab(SLIDETAB);
385     m_view.tabWidget->removeTab(COLORTAB);
386     m_view.tabWidget->removeTab(AUDIOTAB);
387     m_view.tabWidget->removeTab(VIDEOTAB);
388
389     m_view.clip_path->setHidden(true);
390     m_view.label_path->setHidden(true);
391     m_view.label_description->setHidden(true);
392     m_view.label_size->setHidden(true);
393     m_view.clip_filesize->setHidden(true);
394     m_view.clip_filesize->setHidden(true);
395     m_view.clip_path->setHidden(true);
396     m_view.clip_description->setHidden(true);
397     m_view.clip_thumb->setHidden(true);
398     m_view.label_duration->setHidden(true);
399     m_view.clip_duration->setHidden(true);
400
401     if (commonproperties.contains("out")) {
402         if (commonproperties.value("out").toInt() > 0) {
403             m_view.clip_force_out->setChecked(true);
404             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
405         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
406     } else {
407         m_view.clip_force_out->setHidden(true);
408         m_view.clip_out->setHidden(true);
409     }
410 }
411
412
413
414 void ClipProperties::slotEnableLuma(int state)
415 {
416     bool enable = false;
417     if (state == Qt::Checked) enable = true;
418     m_view.luma_duration->setEnabled(enable);
419     m_view.luma_duration_frames->setEnabled(enable);
420     m_view.slide_luma->setEnabled(enable);
421     if (enable) {
422         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
423     } else m_view.luma_file->setEnabled(false);
424     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
425     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
426 }
427
428 void ClipProperties::slotEnableLumaFile(int state)
429 {
430     bool enable = false;
431     if (state == Qt::Checked) enable = true;
432     m_view.luma_file->setEnabled(enable);
433     m_view.luma_softness->setEnabled(enable);
434     m_view.label_softness->setEnabled(enable);
435 }
436
437 void ClipProperties::slotFillMarkersList()
438 {
439     m_view.markers_list->clear();
440     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
441     for (int count = 0; count < marks.count(); ++count) {
442         QString time = m_tc.getTimecode(marks[count].time());
443         QStringList itemtext;
444         itemtext << time << marks[count].comment();
445         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
446     }
447 }
448
449 void ClipProperties::slotAddMarker()
450 {
451     CommentedTime marker(GenTime(), i18n("Marker"));
452     MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
453     if (d.exec() == QDialog::Accepted) {
454         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
455     }
456     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
457 }
458
459 void ClipProperties::slotEditMarker()
460 {
461     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
462     int pos = m_view.markers_list->currentIndex().row();
463     if (pos < 0 || pos > marks.count() - 1) return;
464     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
465     if (d.exec() == QDialog::Accepted) {
466         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
467     }
468     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
469 }
470
471 void ClipProperties::slotDeleteMarker()
472 {
473     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
474     int pos = m_view.markers_list->currentIndex().row();
475     if (pos < 0 || pos > marks.count() - 1) return;
476     emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
477
478     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
479 }
480
481 const QString &ClipProperties::clipId() const
482 {
483     return m_clip->getId();
484 }
485
486
487 QMap <QString, QString> ClipProperties::properties()
488 {
489     QMap <QString, QString> props;
490     CLIPTYPE t = UNKNOWN;
491     if (m_clip != NULL) {
492         t = m_clip->clipType();
493         m_old_props = m_clip->properties();
494     }
495
496     double aspect = m_view.clip_ar->value();
497     if (m_view.clip_force_ar->isChecked()) {
498         if (aspect != m_old_props.value("force_aspect_ratio").toDouble()) {
499             props["force_aspect_ratio"] = QString::number(aspect);
500             m_clipNeedsRefresh = true;
501         }
502     } else if (m_old_props.contains("force_aspect_ratio")) {
503         props["force_aspect_ratio"].clear();
504         m_clipNeedsRefresh = true;
505     }
506
507     double fps = m_view.clip_framerate->value();
508     if (m_view.clip_force_framerate->isChecked()) {
509         if (fps != m_old_props.value("force_fps").toDouble()) {
510             props["force_fps"] = QString::number(fps);
511             m_clipNeedsRefresh = true;
512         }
513     } else if (m_old_props.contains("force_fps")) {
514         props["force_fps"].clear();
515         m_clipNeedsRefresh = true;
516     }
517
518     int progressive = m_view.clip_progressive->value();
519     if (m_view.clip_force_progressive->isChecked()) {
520         if (progressive != m_old_props.value("force_progressive").toInt()) {
521             props["force_progressive"] = QString::number(progressive);
522         }
523     } else if (m_old_props.contains("force_progressive")) {
524         props["force_progressive"].clear();
525     }
526
527     int threads = m_view.clip_threads->value();
528     if (m_view.clip_force_threads->isChecked()) {
529         if (threads != m_old_props.value("threads").toInt()) {
530             props["threads"] = QString::number(threads);
531         }
532     } else if (m_old_props.contains("threads")) {
533         props["threads"].clear();
534     }
535
536     int vindex = m_view.clip_vindex->value();
537     if (m_view.clip_force_vindex->isChecked()) {
538         if (vindex != m_old_props.value("video_index").toInt()) {
539             props["video_index"] = QString::number(vindex);
540         }
541     } else if (m_old_props.contains("video_index")) {
542         props["video_index"].clear();
543     }
544
545     int aindex = m_view.clip_aindex->value();
546     if (m_view.clip_force_aindex->isChecked()) {
547         if (aindex != m_old_props.value("audio_index").toInt()) {
548             props["audio_index"] = QString::number(aindex);
549         }
550     } else if (m_old_props.contains("audio_index")) {
551         props["audio_index"].clear();
552     }
553
554     // If we adjust several clips, return now
555     if (m_clip == NULL) {
556         if (m_view.clip_out->isEnabled()) {
557             int duration = m_tc.getFrameCount(m_view.clip_out->text());
558             if (duration != m_old_props.value("out").toInt()) {
559                 props["out"] = QString::number(duration - 1);
560             }
561         }
562         return props;
563     }
564
565     if (m_old_props.value("description") != m_view.clip_description->text())
566         props["description"] = m_view.clip_description->text();
567
568     if (t == COLOR) {
569         QString new_color = m_view.clip_color->color().name();
570         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
571             m_clipNeedsRefresh = true;
572             props["colour"] = "0x" + new_color.right(6) + "ff";
573         }
574         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
575         if (duration != m_clip->duration().frames(m_fps)) {
576             props["out"] = QString::number(duration - 1);
577         }
578     } else if (t == IMAGE) {
579         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
580             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
581             //m_clipNeedsRefresh = true;
582         }
583         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
584         if (duration != m_clip->duration().frames(m_fps)) {
585             props["out"] = QString::number(duration - 1);
586         }
587     } else if (t == SLIDESHOW) {
588         QString value = QString::number((int) m_view.slide_loop->isChecked());
589         if (m_old_props.value("loop") != value) props["loop"] = value;
590         value = QString::number((int) m_view.slide_crop->isChecked());
591         if (m_old_props.value("crop") != value) props["crop"] = value;
592         value = QString::number((int) m_view.slide_fade->isChecked());
593         if (m_old_props.value("fade") != value) props["fade"] = value;
594         value = QString::number((int) m_view.luma_softness->value());
595         if (m_old_props.value("softness") != value) props["softness"] = value;
596         
597         bool isMime = !(m_view.clip_path->text().contains('%'));
598         if (isMime) {
599             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
600             QString new_path = m_view.clip_path->text() + extension;
601             if (new_path != m_old_props.value("resource")) {
602                 m_clipNeedsReLoad = true;
603                 props["resource"] = new_path;
604                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
605             }
606         }
607         int duration;
608         if (m_view.slide_duration_format->currentIndex() == 1) {
609             // we are in frames mode
610             duration = m_view.slide_duration_frames->value();
611         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
612         if (duration != m_old_props.value("ttl").toInt()) {
613             m_clipNeedsRefresh = true;
614             props["ttl"] = QString::number(duration);
615             props["out"] = QString::number(duration * m_count - 1);
616         }
617
618         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
619             m_clipNeedsRefresh = true;
620             props["out"] = QString::number(duration * m_count - 1);
621         }
622         if (m_view.slide_fade->isChecked()) {
623             int luma_duration;
624             if (m_view.slide_duration_format->currentIndex() == 1) {
625                 // we are in frames mode
626                 luma_duration = m_view.luma_duration_frames->value();
627             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
628             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
629                 m_clipNeedsRefresh = true;
630                 props["luma_duration"] = QString::number(luma_duration);
631             }
632             QString lumaFile;
633             if (m_view.slide_luma->isChecked())
634                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
635             if (lumaFile != m_old_props.value("luma_file")) {
636                 m_clipNeedsRefresh = true;
637                 props["luma_file"] = lumaFile;
638             }
639         } else {
640             if (!m_old_props.value("luma_file").isEmpty()) {
641                 props["luma_file"].clear();
642             }
643         }
644
645         QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
646         if (animation != m_old_props.value("animation")) {
647             if (animation.isEmpty()) {
648                 props["animation"].clear();
649             } else {
650                 props["animation"] = animation;
651             }
652             m_clipNeedsRefresh = true;
653         }
654     }
655     return props;
656 }
657
658 bool ClipProperties::needsTimelineRefresh() const
659 {
660     return m_clipNeedsRefresh;
661 }
662
663 bool ClipProperties::needsTimelineReload() const
664 {
665     return m_clipNeedsReLoad;
666 }
667
668
669 void ClipProperties::parseFolder()
670 {
671     QString path = m_view.clip_path->text();
672     bool isMime = !(path.contains('%'));
673     if (!isMime) path = KUrl(path).directory();
674     QDir dir(path);
675
676     QStringList filters;
677     QString extension;
678
679     if (isMime) {
680         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
681         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
682         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
683         dir.setNameFilters(filters);
684     }
685
686     QStringList result = dir.entryList(QDir::Files);
687
688     if (!isMime) {
689         // find pattern
690         QString filter = KUrl(m_view.clip_path->text()).fileName();
691         QString ext = filter.section('.', -1);
692         filter = filter.section('%', 0, -2);
693         QString regexp = "^" + filter + "\\d+\\." + ext + "$";
694         QRegExp rx(regexp);
695         QStringList entries;
696         foreach(const QString &path, result) {
697             if (rx.exactMatch(path)) entries << path;
698         }
699         result = entries;
700     }
701
702     m_count = result.count();
703     if (m_count == 0) {
704         // no images, do not accept that
705         m_view.slide_info->setText(i18n("No image found"));
706         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
707         return;
708     }
709     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
710     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
711     QDomElement xml = m_clip->toXML();
712     xml.setAttribute("resource", m_view.clip_path->text() + extension);
713     int width = 180.0 * KdenliveSettings::project_display_ratio();
714     if (width % 2 == 1) width++;
715     QString filePath = m_view.clip_path->text();
716     if (isMime) filePath.append(extension);
717     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
718     QMap <QString, QString> props = m_clip->properties();
719     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
720     m_view.clip_thumb->setPixmap(pix);
721 }
722
723 void ClipProperties::slotCheckMaxLength()
724 {
725     if (m_clip->maxDuration() == GenTime()) return;
726     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
727     if (duration > m_clip->maxDuration().frames(m_fps)) {
728         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
729     }
730 }
731
732 void ClipProperties::slotUpdateDurationFormat(int ix)
733 {
734     bool framesFormat = ix == 1;
735     if (framesFormat) {
736         // switching to frames count, update widget
737         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
738         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
739         m_view.slide_duration->setHidden(true);
740         m_view.luma_duration->setHidden(true);
741         m_view.slide_duration_frames->setHidden(false);
742         m_view.luma_duration_frames->setHidden(false);
743     } else {
744         // switching to timecode format
745         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
746         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
747         m_view.slide_duration_frames->setHidden(true);
748         m_view.luma_duration_frames->setHidden(true);
749         m_view.slide_duration->setHidden(false);
750         m_view.luma_duration->setHidden(false);
751     }
752 }
753
754 #include "clipproperties.moc"
755
756