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