]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
Project tree sub-clips and clip properties dialog thumbnails are now created in anoth...
[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 #include <kdeversion.h>
31 #include <KUrlLabel>
32 #include <KRun>
33
34 #ifdef USE_NEPOMUK
35 #if KDE_IS_VERSION(4,6,0)
36 #include <Nepomuk/Variant>
37 #include <Nepomuk/Resource>
38 #include <Nepomuk/ResourceManager>
39 #include <Nepomuk/Vocabulary/NIE>
40 #endif
41 #endif
42
43
44 #include <QDir>
45 #include <QPainter>
46
47
48 static const int VIDEOTAB = 0;
49 static const int AUDIOTAB = 1;
50 static const int COLORTAB = 2;
51 static const int SLIDETAB = 3;
52 static const int IMAGETAB = 4;
53 static const int MARKERTAB = 5;
54 static const int METATAB = 6;
55 static const int ADVANCEDTAB = 7;
56
57
58 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
59     QDialog(parent),
60     m_clip(clip),
61     m_tc(tc),
62     m_fps(fps),
63     m_count(0),
64     m_clipNeedsRefresh(false),
65     m_clipNeedsReLoad(false)
66 {
67     setAttribute(Qt::WA_DeleteOnClose, true);
68     setFont(KGlobalSettings::toolBarFont());
69     m_view.setupUi(this);
70     
71     // force transparency is only for group properties, so hide it
72     m_view.clip_force_transparency->setHidden(true);
73     m_view.clip_transparency->setHidden(true);
74     
75     KUrl url = m_clip->fileURL();
76     m_view.clip_path->setText(url.path());
77     m_view.clip_description->setText(m_clip->description());
78     connect(m_view.clip_description, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
79
80     QMap <QString, QString> props = m_clip->properties();
81     m_view.clip_force_out->setHidden(true);
82     m_view.clip_out->setHidden(true);
83     
84     // New display aspect ratio support
85     if (props.contains("force_aspect_num") && props.value("force_aspect_num").toInt() > 0 &&
86         props.contains("force_aspect_den") && props.value("force_aspect_den").toInt() > 0) {
87         m_view.clip_force_ar->setChecked(true);
88         m_view.clip_ar_num->setEnabled(true);
89         m_view.clip_ar_den->setEnabled(true);
90         m_view.clip_ar_num->setValue(props.value("force_aspect_num").toInt());
91         m_view.clip_ar_den->setValue(props.value("force_aspect_den").toInt());
92     }
93     // Legacy support for pixel aspect ratio
94     else if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
95         m_view.clip_force_ar->setChecked(true);
96         m_view.clip_ar_num->setEnabled(true);
97         m_view.clip_ar_den->setEnabled(true);
98         if (props.contains("frame_size")) {
99             int width = props.value("force_aspect_ratio").toDouble() * props.value("frame_size").section('x', 0, 0).toInt();
100             int height = props.value("frame_size").section('x', 1, 1).toInt();
101             if (width > 0 && height > 0) {
102                 if ((width / height * 100) == 133) {
103                     width = 4;
104                     height = 3;
105                 }
106                 else if (int(width / height * 100) == 177) {
107                     width = 16;
108                     height = 9;
109                 }
110                 m_view.clip_ar_num->setValue(width);
111                 m_view.clip_ar_den->setValue(height);
112             }
113         }
114     }
115     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
116     connect(m_view.clip_ar_num, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
117     connect(m_view.clip_ar_den, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
118
119     if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
120         m_view.clip_force_framerate->setChecked(true);
121         m_view.clip_framerate->setEnabled(true);
122         m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
123     }
124     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
125     connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
126
127     if (props.contains("force_progressive")) {
128         m_view.clip_force_progressive->setChecked(true);
129         m_view.clip_progressive->setEnabled(true);
130         m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
131     }
132     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
133     connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
134
135     m_view.clip_fieldorder->addItem(i18n("Bottom first"), 0);
136     m_view.clip_fieldorder->addItem(i18n("Top first"), 1);
137     if (props.contains("force_tff")) {
138         m_view.clip_force_fieldorder->setChecked(true);
139         m_view.clip_fieldorder->setEnabled(true);
140         m_view.clip_fieldorder->setCurrentIndex(props.value("force_tff").toInt());
141     }
142     connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
143     connect(m_view.clip_fieldorder, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
144     
145     if (props.contains("threads") && props.value("threads").toInt() != 1) {
146         m_view.clip_force_threads->setChecked(true);
147         m_view.clip_threads->setEnabled(true);
148         m_view.clip_threads->setValue(props.value("threads").toInt());
149     }
150     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
151     connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
152
153     if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
154         m_view.clip_force_vindex->setChecked(true);
155         m_view.clip_vindex->setEnabled(true);
156         m_view.clip_vindex->setValue(props.value("video_index").toInt());
157     }
158     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
159     connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
160
161     if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
162         m_view.clip_force_aindex->setChecked(true);
163         m_view.clip_aindex->setEnabled(true);
164         m_view.clip_aindex->setValue(props.value("audio_index").toInt());
165     }
166     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
167     connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
168
169     if (props.contains("audio_max")) {
170         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
171     }
172
173     if (props.contains("video_max")) {
174         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
175     }
176     
177     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
178     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
179     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
180     if (props.contains("force_colorspace")) {
181         m_view.clip_force_colorspace->setChecked(true);
182         m_view.clip_colorspace->setEnabled(true);
183         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("force_colorspace").toInt()));
184     } else if (props.contains("colorspace")) {
185         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("colorspace").toInt()));
186     }
187     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
188     connect(m_view.clip_colorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
189     
190     if (props.contains("full_luma")) {
191         m_view.clip_full_luma->setChecked(true);
192     }
193     connect(m_view.clip_full_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
194
195     // Check for Metadata
196     QMap<QString, QString> meta = m_clip->metadata();
197     QMap<QString, QString>::const_iterator i = meta.constBegin();
198     while (i != meta.constEnd()) {
199         QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
200         metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
201         metaitem->setText(1, i.value());
202         ++i;
203     }
204
205     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
206     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
207     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
208     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
209     connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), m_view.clip_fieldorder, SLOT(setEnabled(bool)));
210     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
211     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
212     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
213     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
214
215     if (props.contains("audiocodec"))
216         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
217
218     if (props.contains("channels"))
219         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
220
221     if (props.contains("frequency"))
222         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
223     
224
225     CLIPTYPE t = m_clip->clipType();
226     
227     if (props.contains("proxy") && props.value("proxy") != "-") {
228         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, KUrl(props.value("proxy")), true);
229         QFrame* line = new QFrame();
230         line->setFrameShape(QFrame::HLine);
231         line->setFrameShadow(QFrame::Sunken);
232         m_proxyContainer = new QFrame();
233         m_proxyContainer->setFrameShape(QFrame::NoFrame);
234         QHBoxLayout *l = new QHBoxLayout;
235         l->addWidget(new QLabel(i18n("Proxy clip: %1", KIO::convertSize(f.size()))));
236         l->addStretch(5);
237         QPushButton *pb = new QPushButton(i18n("Delete proxy"));
238         l->addWidget(pb);
239         connect(pb, SIGNAL(clicked()), this, SLOT(slotDeleteProxy()));
240         m_proxyContainer->setLayout(l);
241         if (t == IMAGE) {
242             m_view.tab_image->layout()->addWidget(line);
243             m_view.tab_image->layout()->addWidget(m_proxyContainer);
244         }
245         else if (t == AUDIO) {
246             m_view.tab_audio->layout()->addWidget(line);
247             m_view.tab_audio->layout()->addWidget(m_proxyContainer);
248         }
249         else {
250             m_view.tab_video->layout()->addWidget(line);
251             m_view.tab_video->layout()->addWidget(m_proxyContainer);
252         }
253     }
254     
255     if (t != AUDIO && t != AV) {
256         m_view.clip_force_aindex->setEnabled(false);
257     }
258
259     if (t != VIDEO && t != AV) {
260         m_view.clip_force_vindex->setEnabled(false);
261     }
262
263     if (t == PLAYLIST)
264         m_view.tabWidget->setTabText(VIDEOTAB, i18n("Playlist"));
265
266     if (t == IMAGE) {
267         m_view.tabWidget->removeTab(SLIDETAB);
268         m_view.tabWidget->removeTab(COLORTAB);
269         m_view.tabWidget->removeTab(AUDIOTAB);
270         m_view.tabWidget->removeTab(VIDEOTAB);
271         if (props.contains("frame_size"))
272             m_view.image_size->setText(props.value("frame_size"));
273         if (props.contains("transparency"))
274             m_view.image_transparency->setChecked(props.value("transparency").toInt());
275         connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
276         int width = 180.0 * KdenliveSettings::project_display_ratio();
277         if (width % 2 == 1) width++;
278         m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
279     } else if (t == COLOR) {
280         m_view.clip_path->setEnabled(false);
281         m_view.tabWidget->removeTab(METATAB);
282         m_view.tabWidget->removeTab(IMAGETAB);
283         m_view.tabWidget->removeTab(SLIDETAB);
284         m_view.tabWidget->removeTab(AUDIOTAB);
285         m_view.tabWidget->removeTab(VIDEOTAB);
286         m_view.clip_thumb->setHidden(true);
287         m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
288         connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
289     } else if (t == SLIDESHOW) {
290         if (url.fileName().startsWith(".all.")) {
291             // the image sequence is defined by mimetype
292             m_view.clip_path->setText(url.directory());
293         } else {
294             // the image sequence is defined by pattern
295             m_view.slide_type_label->setHidden(true);
296             m_view.image_type->setHidden(true);
297             m_view.clip_path->setText(url.path());
298         }
299
300         m_view.tabWidget->removeTab(METATAB);
301         m_view.tabWidget->removeTab(IMAGETAB);
302         m_view.tabWidget->removeTab(COLORTAB);
303         m_view.tabWidget->removeTab(AUDIOTAB);
304         m_view.tabWidget->removeTab(VIDEOTAB);
305
306         //WARNING: Keep in sync with slideshowclip.cpp
307         m_view.image_type->addItem("JPG (*.jpg)", "jpg");
308         m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
309         m_view.image_type->addItem("PNG (*.png)", "png");
310         m_view.image_type->addItem("BMP (*.bmp)", "bmp");
311         m_view.image_type->addItem("GIF (*.gif)", "gif");
312         m_view.image_type->addItem("TGA (*.tga)", "tga");
313         m_view.image_type->addItem("TIF (*.tif)", "tif");
314         m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
315         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
316         m_view.animation->addItem(i18n("None"), QString());
317         m_view.animation->addItem(i18n("Pan"), "Pan");
318         m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
319         m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
320         m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
321         m_view.animation->addItem(i18n("Zoom"), "Zoom");
322         m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
323
324         m_view.slide_loop->setChecked(props.value("loop").toInt());
325         m_view.slide_crop->setChecked(props.value("crop").toInt());
326         m_view.slide_fade->setChecked(props.value("fade").toInt());
327         m_view.luma_softness->setValue(props.value("softness").toInt());
328         if (!props.value("animation").isEmpty())
329             m_view.animation->setCurrentItem(props.value("animation"));
330         else
331             m_view.animation->setCurrentIndex(0);
332         QString path = props.value("resource");
333         QString ext = path.section('.', -1);
334         for (int i = 0; i < m_view.image_type->count(); i++) {
335             if (m_view.image_type->itemData(i).toString() == ext) {
336                 m_view.image_type->setCurrentIndex(i);
337                 break;
338             }
339         }
340         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
341
342         m_view.slide_duration_format->addItem(i18n("hh:mm:ss:ff"));
343         m_view.slide_duration_format->addItem(i18n("Frames"));
344         connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
345         m_view.slide_duration_frames->setHidden(true);
346         m_view.luma_duration_frames->setHidden(true);
347
348         parseFolder();
349
350         m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
351         QString lumaFile = props.value("luma_file");
352
353         // Check for Kdenlive installed luma files
354         QStringList filters;
355         filters << "*.pgm" << "*.png";
356
357         QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
358         foreach(const QString & folder, customLumas) {
359             QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
360             foreach(const QString & fname, filesnames) {
361                 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
362                 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
363             }
364         }
365
366         // Check for MLT lumas
367         QString profilePath = KdenliveSettings::mltpath();
368         QString folder = profilePath.section('/', 0, -3);
369         folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
370         QDir lumafolder(folder);
371         QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
372         foreach(const QString & fname, filesnames) {
373             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
374             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
375         }
376
377         if (!lumaFile.isEmpty()) {
378             m_view.slide_luma->setChecked(true);
379             m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
380         } else m_view.luma_file->setEnabled(false);
381         slotEnableLuma(m_view.slide_fade->checkState());
382         slotEnableLumaFile(m_view.slide_luma->checkState());
383
384         connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
385         connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
386         connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
387         connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
388         connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
389         connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
390         connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
391         connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
392         connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
393         connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
394
395
396         connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
397         connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
398         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
399
400     } else if (t != AUDIO) {
401         m_view.tabWidget->removeTab(IMAGETAB);
402         m_view.tabWidget->removeTab(SLIDETAB);
403         m_view.tabWidget->removeTab(COLORTAB);
404
405         PropertiesViewDelegate *del1 = new PropertiesViewDelegate(this);
406         PropertiesViewDelegate *del2 = new PropertiesViewDelegate(this);
407         m_view.clip_vproperties->setItemDelegate(del1);
408         m_view.clip_aproperties->setItemDelegate(del2);
409         m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
410         m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
411
412         if (props.contains("videocodec"))
413             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
414
415         if (props.contains("frame_size"))
416             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
417
418         if (props.contains("fps")) {
419             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
420             if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
421         }
422
423         if (props.contains("progressive")) {
424             int scanning = props.value("progressive").toInt();
425             QString txt = scanning == 1 ? i18n("Progressive") : i18n("Interlaced");
426             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Scanning") << txt);
427         }
428         
429         if (props.contains("aspect_ratio"))
430             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
431
432         if (props.contains("pix_fmt"))
433             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
434
435         if (props.contains("colorspace"))
436             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
437         
438         m_view.clip_thumb->setMinimumSize(180 * KdenliveSettings::project_display_ratio(), 180);
439         
440         if (t == IMAGE || t == VIDEO || t == PLAYLIST) m_view.tabWidget->removeTab(AUDIOTAB);
441     } else {
442         m_view.tabWidget->removeTab(IMAGETAB);
443         m_view.tabWidget->removeTab(SLIDETAB);
444         m_view.tabWidget->removeTab(COLORTAB);
445         m_view.tabWidget->removeTab(VIDEOTAB);
446         m_view.clip_thumb->setHidden(true);
447     }
448
449     if (t != SLIDESHOW && t != COLOR) {
450         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
451         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
452     } else {
453         m_view.clip_filesize->setHidden(true);
454         m_view.label_size->setHidden(true);
455     }
456     m_view.clip_duration->setInputMask(tc.mask());
457     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
458     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
459     else {
460         connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
461         connect(m_view.clip_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
462     }
463
464     // markers
465     m_view.marker_new->setIcon(KIcon("document-new"));
466     m_view.marker_new->setToolTip(i18n("Add marker"));
467     m_view.marker_edit->setIcon(KIcon("document-properties"));
468     m_view.marker_edit->setToolTip(i18n("Edit marker"));
469     m_view.marker_delete->setIcon(KIcon("trash-empty"));
470     m_view.marker_delete->setToolTip(i18n("Delete marker"));
471     m_view.marker_save->setIcon(KIcon("document-save-as"));
472     m_view.marker_save->setToolTip(i18n("Save markers"));
473     m_view.marker_load->setIcon(KIcon("document-open"));
474     m_view.marker_load->setToolTip(i18n("Load markers"));
475     m_view.analysis_delete->setIcon(KIcon("trash-empty"));
476     m_view.analysis_delete->setToolTip(i18n("Delete analysis data"));
477     m_view.analysis_load->setIcon(KIcon("document-open"));
478     m_view.analysis_load->setToolTip(i18n("Load analysis data"));
479     m_view.analysis_save->setIcon(KIcon("document-save-as"));
480     m_view.analysis_save->setToolTip(i18n("Save analysis data"));
481
482         // Check for Nepomuk metadata
483 #ifdef USE_NEPOMUK
484 #if KDE_IS_VERSION(4,6,0)
485     if (!url.isEmpty()) {
486         Nepomuk::ResourceManager::instance()->init();
487         Nepomuk::Resource res( url.path() );
488         // Check if file has a license
489         if (res.hasProperty(Nepomuk::Vocabulary::NIE::license())) {
490             QString ltype = res.property(Nepomuk::Vocabulary::NIE::licenseType()).toString();
491             m_view.clip_license->setText(i18n("License: %1", res.property(Nepomuk::Vocabulary::NIE::license()).toString()));
492             if (ltype.startsWith("http")) {
493                 m_view.clip_license->setUrl(ltype);
494                 connect(m_view.clip_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
495             }
496         }
497         else m_view.clip_license->setHidden(true);
498     }
499     else m_view.clip_license->setHidden(true);
500 #else
501     m_view.clip_license->setHidden(true);
502 #endif
503 #else
504     m_view.clip_license->setHidden(true);
505 #endif
506     
507     slotFillMarkersList(m_clip);
508     slotUpdateAnalysisData(m_clip);
509     
510     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
511     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
512     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
513     connect(m_view.marker_save, SIGNAL(clicked()), this, SLOT(slotSaveMarkers()));
514     connect(m_view.marker_load, SIGNAL(clicked()), this, SLOT(slotLoadMarkers()));
515     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
516     
517     connect(m_view.analysis_delete, SIGNAL(clicked()), this, SLOT(slotDeleteAnalysis()));
518     connect(m_view.analysis_save, SIGNAL(clicked()), this, SLOT(slotSaveAnalysis()));
519     connect(m_view.analysis_load, SIGNAL(clicked()), this, SLOT(slotLoadAnalysis()));
520     
521     connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
522     connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
523     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
524     adjustSize();
525 }
526
527
528 // Used for multiple clips editing
529 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
530     QDialog(parent),
531     m_clip(NULL),
532     m_tc(tc),
533     m_fps(0),
534     m_count(0),
535     m_clipNeedsRefresh(false),
536     m_clipNeedsReLoad(false)
537 {
538     setFont(KGlobalSettings::toolBarFont());
539     m_view.setupUi(this);
540     QString title = windowTitle();
541     title.append(' ' + i18np("(%1 clip)", "(%1 clips)", cliplist.count()));
542     setWindowTitle(title);
543     QMap <QString, QString> props = cliplist.at(0)->properties();
544     m_old_props = commonproperties;
545
546     if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
547         m_view.clip_force_ar->setChecked(true);
548         m_view.clip_ar_num->setEnabled(true);
549         m_view.clip_ar_den->setEnabled(true);
550         m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
551         m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
552     }
553
554     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
555         m_view.clip_force_framerate->setChecked(true);
556         m_view.clip_framerate->setEnabled(true);
557         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
558     }
559
560     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
561         m_view.clip_force_progressive->setChecked(true);
562         m_view.clip_progressive->setEnabled(true);
563         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
564     }
565
566     if (commonproperties.contains("force_tff") && !commonproperties.value("force_tff").isEmpty()) {
567         m_view.clip_force_fieldorder->setChecked(true);
568         m_view.clip_fieldorder->setEnabled(true);
569         m_view.clip_fieldorder->setCurrentIndex(commonproperties.value("force_tff").toInt());
570     }
571     
572     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
573         m_view.clip_force_threads->setChecked(true);
574         m_view.clip_threads->setEnabled(true);
575         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
576     }
577
578     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
579         m_view.clip_force_vindex->setChecked(true);
580         m_view.clip_vindex->setEnabled(true);
581         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
582     }
583
584     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
585         m_view.clip_force_aindex->setChecked(true);
586         m_view.clip_aindex->setEnabled(true);
587         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
588     }
589
590     if (props.contains("audio_max")) {
591         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
592     }
593
594     if (props.contains("video_max")) {
595         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
596     }
597     
598     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
599     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
600     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
601     
602     if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
603         m_view.clip_force_colorspace->setChecked(true);
604         m_view.clip_colorspace->setEnabled(true);
605         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
606     }
607     
608     if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
609         m_view.clip_full_luma->setChecked(true);
610     }
611     
612     if (commonproperties.contains("transparency")) {
613         // image transparency checkbox
614         int transparency = commonproperties.value("transparency").toInt();
615         if (transparency == 0) {
616             m_view.clip_force_transparency->setChecked(true);
617         }
618         else if (transparency == 1) {
619             m_view.clip_force_transparency->setChecked(true);
620             m_view.clip_transparency->setCurrentIndex(1);
621         }
622     }
623     else {
624         m_view.clip_force_transparency->setHidden(true);
625         m_view.clip_transparency->setHidden(true);
626     }
627     
628
629     connect(m_view.clip_force_transparency, SIGNAL(toggled(bool)), m_view.clip_transparency, SLOT(setEnabled(bool)));
630     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
631     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
632     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
633     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
634     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
635     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
636     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
637     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
638
639     m_view.tabWidget->removeTab(METATAB);
640     m_view.tabWidget->removeTab(MARKERTAB);
641     m_view.tabWidget->removeTab(IMAGETAB);
642     m_view.tabWidget->removeTab(SLIDETAB);
643     m_view.tabWidget->removeTab(COLORTAB);
644     m_view.tabWidget->removeTab(AUDIOTAB);
645     m_view.tabWidget->removeTab(VIDEOTAB);
646
647     m_view.clip_path->setHidden(true);
648     m_view.label_path->setHidden(true);
649     m_view.label_description->setHidden(true);
650     m_view.label_size->setHidden(true);
651     m_view.clip_filesize->setHidden(true);
652     m_view.clip_filesize->setHidden(true);
653     m_view.clip_path->setHidden(true);
654     m_view.clip_description->setHidden(true);
655     m_view.clip_thumb->setHidden(true);
656     m_view.label_duration->setHidden(true);
657     m_view.clip_duration->setHidden(true);
658
659     if (commonproperties.contains("out")) {
660         if (commonproperties.value("out").toInt() > 0) {
661             m_view.clip_force_out->setChecked(true);
662             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
663         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
664     } else {
665         m_view.clip_force_out->setHidden(true);
666         m_view.clip_out->setHidden(true);
667     }
668 }
669
670 ClipProperties::~ClipProperties()
671 {
672     QAbstractItemDelegate *del1 = m_view.clip_vproperties->itemDelegate();
673     if (del1) delete del1;
674     QAbstractItemDelegate *del2 = m_view.clip_aproperties->itemDelegate();
675     if (del2) delete del2;
676 }
677
678 void ClipProperties::slotGotThumbnail(const QString &id, QImage img)
679 {
680     if (id != m_clip->getId()) return;
681     QPixmap framedPix(img.width(), img.height());
682     framedPix.fill(Qt::transparent);
683     QPainter p(&framedPix);
684     p.setRenderHint(QPainter::Antialiasing, true);
685     QPainterPath path;
686     path.addRoundedRect(0.5, 0.5, framedPix.width() - 1, framedPix.height() - 1, 4, 4);
687     p.setClipPath(path);
688     p.drawImage(0, 0, img);
689     p.end();
690     m_view.clip_thumb->setPixmap(framedPix);
691 }
692
693 void ClipProperties::slotApplyProperties()
694 {
695     if (m_clip != NULL) {
696         QMap <QString, QString> props = properties();
697         emit applyNewClipProperties(m_clip->getId(), m_clip->currentProperties(props), props, needsTimelineRefresh(), needsTimelineReload());
698     }
699     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
700 }
701
702 void ClipProperties::disableClipId(const QString &id)
703 {
704     if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
705         if (m_clip->getId() == id) {
706             // clip was removed from project, close this properties dialog
707             close();
708         }
709     }
710 }
711
712 void ClipProperties::slotModified()
713 {
714     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
715 }
716
717
718 void ClipProperties::slotEnableLuma(int state)
719 {
720     bool enable = false;
721     if (state == Qt::Checked) enable = true;
722     m_view.luma_duration->setEnabled(enable);
723     m_view.luma_duration_frames->setEnabled(enable);
724     m_view.slide_luma->setEnabled(enable);
725     if (enable) {
726         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
727     } else m_view.luma_file->setEnabled(false);
728     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
729     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
730 }
731
732 void ClipProperties::slotEnableLumaFile(int state)
733 {
734     bool enable = false;
735     if (state == Qt::Checked) enable = true;
736     m_view.luma_file->setEnabled(enable);
737     m_view.luma_softness->setEnabled(enable);
738     m_view.label_softness->setEnabled(enable);
739 }
740
741 void ClipProperties::slotUpdateAnalysisData(DocClipBase *clip)
742 {
743     if (m_clip != clip) return;
744     m_view.analysis_list->clear();
745     QMap <QString, QString> analysis = clip->analysisData();
746     m_view.analysis_box->setHidden(analysis.isEmpty());
747     QMap<QString, QString>::const_iterator i = analysis.constBegin();
748     while (i != analysis.constEnd()) {
749         QStringList itemtext;
750         itemtext << i.key() << i.value();
751         (void) new QTreeWidgetItem(m_view.analysis_list, itemtext);
752         ++i;
753     }
754 }
755
756 void ClipProperties::slotFillMarkersList(DocClipBase *clip)
757 {
758     if (m_clip != clip) return;
759     m_view.markers_list->clear();
760     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
761     for (int count = 0; count < marks.count(); ++count) {
762         QString time = m_tc.getTimecode(marks[count].time());
763         QStringList itemtext;
764         itemtext << time << marks.at(count).comment();
765         QTreeWidgetItem *item = new QTreeWidgetItem(m_view.markers_list, itemtext);
766         item->setData(0, Qt::DecorationRole, CommentedTime::markerColor(marks.at(count).markerType()));
767     }
768 }
769
770 void ClipProperties::slotAddMarker()
771 {
772     CommentedTime marker(GenTime(), i18n("Marker"));
773     QPointer<MarkerDialog> d = new MarkerDialog(m_clip, marker,
774                                           m_tc, i18n("Add Marker"), this);
775     if (d->exec() == QDialog::Accepted) {
776         QList <CommentedTime> markers;
777         markers << d->newMarker();
778         emit addMarkers(m_clip->getId(), markers);
779     }
780     delete d;
781 }
782
783 void ClipProperties::slotSaveMarkers()
784 {
785     emit saveMarkers(m_clip->getId());
786 }
787
788 void ClipProperties::slotLoadMarkers()
789 {
790     emit loadMarkers(m_clip->getId());
791 }
792
793 void ClipProperties::slotEditMarker()
794 {
795     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
796     int pos = m_view.markers_list->currentIndex().row();
797     if (pos < 0 || pos > marks.count() - 1) return;
798     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
799     if (d.exec() == QDialog::Accepted) {
800         QList <CommentedTime> markers;
801         markers << d.newMarker();
802         emit addMarkers(m_clip->getId(), markers);
803     }
804 }
805
806 void ClipProperties::slotDeleteMarker()
807 {
808     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
809     QList < CommentedTime > toDelete;
810     for (int i = 0; i < marks.count(); i++) {
811         if (m_view.markers_list->topLevelItem(i)->isSelected()) {
812             CommentedTime marker = marks.at(i);
813             marker.setMarkerType(-1);
814             toDelete << marker;
815         }
816     }
817     emit addMarkers(m_clip->getId(), toDelete);
818 }
819
820 void ClipProperties::slotDeleteAnalysis()
821 {
822     QTreeWidgetItem *current = m_view.analysis_list->currentItem();
823     if (current) emit deleteAnalysis(m_clip->getId(), current->text(0));
824 }
825
826 const QString &ClipProperties::clipId() const
827 {
828     return m_clip->getId();
829 }
830
831
832 QMap <QString, QString> ClipProperties::properties()
833 {
834     QMap <QString, QString> props;
835     QLocale locale;
836     CLIPTYPE t = UNKNOWN;
837     if (m_clip != NULL) {
838         t = m_clip->clipType();
839         m_old_props = m_clip->properties();
840     }
841
842     int aspectNumerator = m_view.clip_ar_num->value();
843     int aspectDenominator = m_view.clip_ar_den->value();
844     if (m_view.clip_force_ar->isChecked()) {
845         if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
846             aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
847             props["force_aspect_num"] = QString::number(aspectNumerator);
848             props["force_aspect_den"] = QString::number(aspectDenominator);
849             props["force_aspect_ratio"].clear();
850             m_clipNeedsRefresh = true;
851         }
852     } else {
853         if (m_old_props.contains("force_aspect_num") && !m_old_props.value("force_aspect_num").isEmpty()) {
854             props["force_aspect_num"].clear();
855             m_clipNeedsRefresh = true;
856         }
857         if (m_old_props.contains("force_aspect_den") && !m_old_props.value("force_aspect_den").isEmpty()) {
858             props["force_aspect_den"].clear();
859             m_clipNeedsRefresh = true;
860         }
861     }
862
863     double fps = m_view.clip_framerate->value();
864     if (m_view.clip_force_framerate->isChecked()) {
865         if (fps != m_old_props.value("force_fps").toDouble()) {
866             props["force_fps"] = locale.toString(fps);
867             m_clipNeedsRefresh = true;
868         }
869     } else if (m_old_props.contains("force_fps") && !m_old_props.value("force_fps").isEmpty()) {
870         props["force_fps"].clear();
871         m_clipNeedsRefresh = true;
872     }
873
874     int progressive = m_view.clip_progressive->value();
875     if (m_view.clip_force_progressive->isChecked()) {
876         if (progressive != m_old_props.value("force_progressive").toInt()) {
877             props["force_progressive"] = QString::number(progressive);
878         }
879     } else if (m_old_props.contains("force_progressive") && !m_old_props.value("force_progressive").isEmpty()) {
880         props["force_progressive"].clear();
881     }
882
883     int fieldOrder = m_view.clip_fieldorder->currentIndex();
884     if (m_view.clip_force_fieldorder->isChecked()) {
885         if (fieldOrder != m_old_props.value("force_tff").toInt()) {
886             props["force_tff"] = QString::number(fieldOrder);
887         }
888     } else if (m_old_props.contains("force_tff") && !m_old_props.value("force_tff").isEmpty()) {
889         props["force_tff"].clear();
890     }
891
892     int threads = m_view.clip_threads->value();
893     if (m_view.clip_force_threads->isChecked()) {
894         if (threads != m_old_props.value("threads").toInt()) {
895             props["threads"] = QString::number(threads);
896         }
897     } else if (m_old_props.contains("threads") && !m_old_props.value("threads").isEmpty()) {
898         props["threads"].clear();
899     }
900
901     int vindex = m_view.clip_vindex->value();
902     if (m_view.clip_force_vindex->isChecked()) {
903         if (vindex != m_old_props.value("video_index").toInt()) {
904             props["video_index"] = QString::number(vindex);
905         }
906     } else if (m_old_props.contains("video_index") && !m_old_props.value("video_index").isEmpty()) {
907         props["video_index"].clear();
908     }
909
910     int aindex = m_view.clip_aindex->value();
911     if (m_view.clip_force_aindex->isChecked()) {
912         if (aindex != m_old_props.value("audio_index").toInt()) {
913             props["audio_index"] = QString::number(aindex);
914         }
915     } else if (m_old_props.contains("audio_index") && !m_old_props.value("audio_index").isEmpty()) {
916         props["audio_index"].clear();
917     }
918     
919     int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
920     if (m_view.clip_force_colorspace->isChecked()) {
921         if (colorspace != m_old_props.value("force_colorspace").toInt()) {
922             props["force_colorspace"] = QString::number(colorspace);
923             m_clipNeedsRefresh = true;
924         }
925     } else if (m_old_props.contains("force_colorspace") && !m_old_props.value("force_colorspace").isEmpty()) {
926         props["force_colorspace"].clear();
927         m_clipNeedsRefresh = true;
928     }
929
930     if (m_view.clip_full_luma->isChecked()) {
931         props["full_luma"] = QString::number(1);
932         m_clipNeedsRefresh = true;
933     } else if (m_old_props.contains("full_luma") && !m_old_props.value("full_luma").isEmpty()) {
934         props["full_luma"].clear();
935         m_clipNeedsRefresh = true;
936     }
937     
938     if (m_view.clip_force_transparency->isChecked()) {
939         QString transp = QString::number(m_view.clip_transparency->currentIndex());
940         if (transp != m_old_props.value("transparency")) props["transparency"] = transp;
941     }
942
943     // If we adjust several clips, return now
944     if (m_clip == NULL) {
945         if (m_view.clip_out->isEnabled()) {
946             int duration = m_tc.getFrameCount(m_view.clip_out->text());
947             if (duration != m_old_props.value("out").toInt()) {
948                 props["out"] = QString::number(duration - 1);
949             }
950         }
951         return props;
952     }
953
954     if (m_old_props.value("description") != m_view.clip_description->text())
955         props["description"] = m_view.clip_description->text();
956
957     if (t == COLOR) {
958         QString new_color = m_view.clip_color->color().name();
959         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
960             m_clipNeedsRefresh = true;
961             props["colour"] = "0x" + new_color.right(6) + "ff";
962         }
963         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
964         if (duration != m_clip->duration().frames(m_fps)) {
965             props["out"] = QString::number(duration - 1);
966         }
967     } else if (t == IMAGE) {
968         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
969             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
970             //m_clipNeedsRefresh = true;
971         }
972         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
973         if (duration != m_clip->duration().frames(m_fps)) {
974             props["out"] = QString::number(duration - 1);
975         }
976     } else if (t == SLIDESHOW) {
977         QString value = QString::number((int) m_view.slide_loop->isChecked());
978         if (m_old_props.value("loop") != value) props["loop"] = value;
979         value = QString::number((int) m_view.slide_crop->isChecked());
980         if (m_old_props.value("crop") != value) props["crop"] = value;
981         value = QString::number((int) m_view.slide_fade->isChecked());
982         if (m_old_props.value("fade") != value) props["fade"] = value;
983         value = QString::number((int) m_view.luma_softness->value());
984         if (m_old_props.value("softness") != value) props["softness"] = value;
985
986         bool isMime = !(m_view.clip_path->text().contains('%'));
987         if (isMime) {
988             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
989             QString new_path = m_view.clip_path->text() + extension;
990             if (new_path != m_old_props.value("resource")) {
991                 m_clipNeedsReLoad = true;
992                 props["resource"] = new_path;
993                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
994             }
995         }
996         int duration;
997         if (m_view.slide_duration_format->currentIndex() == 1) {
998             // we are in frames mode
999             duration = m_view.slide_duration_frames->value();
1000         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
1001         if (duration != m_old_props.value("ttl").toInt()) {
1002             m_clipNeedsRefresh = true;
1003             props["ttl"] = QString::number(duration);
1004             props["length"] = QString::number(duration * m_count);
1005         }
1006
1007         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
1008             m_clipNeedsRefresh = true;
1009             props["out"] = QString::number(duration * m_count - 1);
1010         }
1011         if (m_view.slide_fade->isChecked()) {
1012             int luma_duration;
1013             if (m_view.slide_duration_format->currentIndex() == 1) {
1014                 // we are in frames mode
1015                 luma_duration = m_view.luma_duration_frames->value();
1016             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
1017             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
1018                 m_clipNeedsRefresh = true;
1019                 props["luma_duration"] = QString::number(luma_duration);
1020             }
1021             QString lumaFile;
1022             if (m_view.slide_luma->isChecked())
1023                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
1024             if (lumaFile != m_old_props.value("luma_file")) {
1025                 m_clipNeedsRefresh = true;
1026                 props["luma_file"] = lumaFile;
1027             }
1028         } else {
1029             if (!m_old_props.value("luma_file").isEmpty()) {
1030                 props["luma_file"].clear();
1031             }
1032         }
1033
1034         QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
1035         if (animation != m_old_props.value("animation")) {
1036             if (animation.isEmpty()) {
1037                 props["animation"].clear();
1038             } else {
1039                 props["animation"] = animation;
1040             }
1041             m_clipNeedsRefresh = true;
1042         }
1043     }
1044     return props;
1045 }
1046
1047 bool ClipProperties::needsTimelineRefresh() const
1048 {
1049     return m_clipNeedsRefresh;
1050 }
1051
1052 bool ClipProperties::needsTimelineReload() const
1053 {
1054     return m_clipNeedsReLoad;
1055 }
1056
1057
1058 void ClipProperties::parseFolder()
1059 {
1060     QString path = m_view.clip_path->text();
1061     bool isMime = !(path.contains('%'));
1062     if (!isMime) path = KUrl(path).directory();
1063     QDir dir(path);
1064
1065     QStringList filters;
1066     QString extension;
1067
1068     if (isMime) {
1069         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
1070         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1071         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1072         dir.setNameFilters(filters);
1073     }
1074
1075     QStringList result = dir.entryList(QDir::Files);
1076
1077     if (!isMime) {
1078         // find pattern
1079         QString filter = KUrl(m_view.clip_path->text()).fileName();
1080         QString ext = filter.section('.', -1);
1081         filter = filter.section('%', 0, -2);
1082         QString regexp = '^' + filter + "\\d+\\." + ext + '$';
1083         QRegExp rx(regexp);
1084         QStringList entries;
1085         foreach(const QString & path, result) {
1086             if (rx.exactMatch(path)) entries << path;
1087         }
1088         result = entries;
1089     }
1090
1091     m_count = result.count();
1092     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
1093     if (m_count == 0) {
1094         // no images, do not accept that
1095         m_view.slide_info->setText(i18n("No image found"));
1096         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
1097         return;
1098     }
1099     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
1100     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
1101     QDomElement xml = m_clip->toXML();
1102     xml.setAttribute("resource", m_view.clip_path->text() + extension);
1103     int width = 180.0 * KdenliveSettings::project_display_ratio();
1104     if (width % 2 == 1) width++;
1105     QString filePath = m_view.clip_path->text();
1106     if (isMime) filePath.append(extension);
1107     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
1108     QMap <QString, QString> props = m_clip->properties();
1109     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
1110     m_view.clip_thumb->setPixmap(pix);
1111 }
1112
1113 void ClipProperties::slotCheckMaxLength()
1114 {
1115     if (m_clip->maxDuration() == GenTime()) return;
1116     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1117     if (duration > m_clip->maxDuration().frames(m_fps)) {
1118         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
1119     }
1120 }
1121
1122 void ClipProperties::slotUpdateDurationFormat(int ix)
1123 {
1124     bool framesFormat = ix == 1;
1125     if (framesFormat) {
1126         // switching to frames count, update widget
1127         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
1128         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
1129         m_view.slide_duration->setHidden(true);
1130         m_view.luma_duration->setHidden(true);
1131         m_view.slide_duration_frames->setHidden(false);
1132         m_view.luma_duration_frames->setHidden(false);
1133     } else {
1134         // switching to timecode format
1135         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
1136         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
1137         m_view.slide_duration_frames->setHidden(true);
1138         m_view.luma_duration_frames->setHidden(true);
1139         m_view.slide_duration->setHidden(false);
1140         m_view.luma_duration->setHidden(false);
1141     }
1142 }
1143
1144 void ClipProperties::slotDeleteProxy()
1145 {
1146       QString proxy = m_clip->getProperty("proxy");
1147       if (proxy.isEmpty()) return;
1148       emit deleteProxy(proxy);
1149       if (m_proxyContainer) delete m_proxyContainer;
1150 }
1151
1152 void ClipProperties::slotOpenUrl(const QString &url)
1153 {
1154     new KRun(KUrl(url), this);
1155 }
1156
1157 #include "clipproperties.moc"
1158
1159
1160