]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
7981f9537cb666953525e5fcc801e6b24da59875
[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
439         int width = 180.0 * KdenliveSettings::project_display_ratio();
440         if (width % 2 == 1) width++;
441         QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
442         QPixmap framedPix(pix.width(), pix.height());
443         framedPix.fill(Qt::transparent);
444         QPainter p(&framedPix);
445         p.setRenderHint(QPainter::Antialiasing, true);
446         QPainterPath path;
447         path.addRoundedRect(0.5, 0.5, framedPix.width() - 1, framedPix.height() - 1, 4, 4);
448         p.setClipPath(path);
449         p.drawPixmap(0, 0, pix);
450         p.end();
451         
452         m_view.clip_thumb->setPixmap(framedPix);
453         if (t == IMAGE || t == VIDEO || t == PLAYLIST) m_view.tabWidget->removeTab(AUDIOTAB);
454     } else {
455         m_view.tabWidget->removeTab(IMAGETAB);
456         m_view.tabWidget->removeTab(SLIDETAB);
457         m_view.tabWidget->removeTab(COLORTAB);
458         m_view.tabWidget->removeTab(VIDEOTAB);
459         m_view.clip_thumb->setHidden(true);
460     }
461
462     if (t != SLIDESHOW && t != COLOR) {
463         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
464         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
465     } else {
466         m_view.clip_filesize->setHidden(true);
467         m_view.label_size->setHidden(true);
468     }
469     m_view.clip_duration->setInputMask(tc.mask());
470     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
471     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
472     else {
473         connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
474         connect(m_view.clip_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
475     }
476
477     // markers
478     m_view.marker_new->setIcon(KIcon("document-new"));
479     m_view.marker_new->setToolTip(i18n("Add marker"));
480     m_view.marker_edit->setIcon(KIcon("document-properties"));
481     m_view.marker_edit->setToolTip(i18n("Edit marker"));
482     m_view.marker_delete->setIcon(KIcon("trash-empty"));
483     m_view.marker_delete->setToolTip(i18n("Delete marker"));
484     m_view.marker_save->setIcon(KIcon("document-save-as"));
485     m_view.marker_save->setToolTip(i18n("Save markers"));
486     m_view.marker_load->setIcon(KIcon("document-open"));
487     m_view.marker_load->setToolTip(i18n("Load markers"));
488     m_view.analysis_delete->setIcon(KIcon("trash-empty"));
489     m_view.analysis_delete->setToolTip(i18n("Delete analysis data"));
490     m_view.analysis_load->setIcon(KIcon("document-open"));
491     m_view.analysis_load->setToolTip(i18n("Load analysis data"));
492     m_view.analysis_save->setIcon(KIcon("document-save-as"));
493     m_view.analysis_save->setToolTip(i18n("Save analysis data"));
494
495         // Check for Nepomuk metadata
496 #ifdef USE_NEPOMUK
497 #if KDE_IS_VERSION(4,6,0)
498     if (!url.isEmpty()) {
499         Nepomuk::ResourceManager::instance()->init();
500         Nepomuk::Resource res( url.path() );
501         // Check if file has a license
502         if (res.hasProperty(Nepomuk::Vocabulary::NIE::license())) {
503             QString ltype = res.property(Nepomuk::Vocabulary::NIE::licenseType()).toString();
504             m_view.clip_license->setText(i18n("License: %1", res.property(Nepomuk::Vocabulary::NIE::license()).toString()));
505             if (ltype.startsWith("http")) {
506                 m_view.clip_license->setUrl(ltype);
507                 connect(m_view.clip_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
508             }
509         }
510         else m_view.clip_license->setHidden(true);
511     }
512     else m_view.clip_license->setHidden(true);
513 #else
514     m_view.clip_license->setHidden(true);
515 #endif
516 #else
517     m_view.clip_license->setHidden(true);
518 #endif
519     
520     slotFillMarkersList(m_clip);
521     slotUpdateAnalysisData(m_clip);
522     
523     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
524     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
525     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
526     connect(m_view.marker_save, SIGNAL(clicked()), this, SLOT(slotSaveMarkers()));
527     connect(m_view.marker_load, SIGNAL(clicked()), this, SLOT(slotLoadMarkers()));
528     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
529     
530     connect(m_view.analysis_delete, SIGNAL(clicked()), this, SLOT(slotDeleteAnalysis()));
531     connect(m_view.analysis_save, SIGNAL(clicked()), this, SLOT(slotSaveAnalysis()));
532     connect(m_view.analysis_load, SIGNAL(clicked()), this, SLOT(slotLoadAnalysis()));
533     
534     connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
535     connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
536     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
537     adjustSize();
538 }
539
540
541 // Used for multiple clips editing
542 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
543     QDialog(parent),
544     m_clip(NULL),
545     m_tc(tc),
546     m_fps(0),
547     m_count(0),
548     m_clipNeedsRefresh(false),
549     m_clipNeedsReLoad(false)
550 {
551     setFont(KGlobalSettings::toolBarFont());
552     m_view.setupUi(this);
553     QString title = windowTitle();
554     title.append(' ' + i18np("(%1 clip)", "(%1 clips)", cliplist.count()));
555     setWindowTitle(title);
556     QMap <QString, QString> props = cliplist.at(0)->properties();
557     m_old_props = commonproperties;
558
559     if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
560         m_view.clip_force_ar->setChecked(true);
561         m_view.clip_ar_num->setEnabled(true);
562         m_view.clip_ar_den->setEnabled(true);
563         m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
564         m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
565     }
566
567     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
568         m_view.clip_force_framerate->setChecked(true);
569         m_view.clip_framerate->setEnabled(true);
570         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
571     }
572
573     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
574         m_view.clip_force_progressive->setChecked(true);
575         m_view.clip_progressive->setEnabled(true);
576         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
577     }
578
579     if (commonproperties.contains("force_tff") && !commonproperties.value("force_tff").isEmpty()) {
580         m_view.clip_force_fieldorder->setChecked(true);
581         m_view.clip_fieldorder->setEnabled(true);
582         m_view.clip_fieldorder->setCurrentIndex(commonproperties.value("force_tff").toInt());
583     }
584     
585     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
586         m_view.clip_force_threads->setChecked(true);
587         m_view.clip_threads->setEnabled(true);
588         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
589     }
590
591     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
592         m_view.clip_force_vindex->setChecked(true);
593         m_view.clip_vindex->setEnabled(true);
594         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
595     }
596
597     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
598         m_view.clip_force_aindex->setChecked(true);
599         m_view.clip_aindex->setEnabled(true);
600         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
601     }
602
603     if (props.contains("audio_max")) {
604         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
605     }
606
607     if (props.contains("video_max")) {
608         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
609     }
610     
611     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
612     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
613     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
614     
615     if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
616         m_view.clip_force_colorspace->setChecked(true);
617         m_view.clip_colorspace->setEnabled(true);
618         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
619     }
620     
621     if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
622         m_view.clip_full_luma->setChecked(true);
623     }
624     
625     if (commonproperties.contains("transparency")) {
626         // image transparency checkbox
627         int transparency = commonproperties.value("transparency").toInt();
628         if (transparency == 0) {
629             m_view.clip_force_transparency->setChecked(true);
630         }
631         else if (transparency == 1) {
632             m_view.clip_force_transparency->setChecked(true);
633             m_view.clip_transparency->setCurrentIndex(1);
634         }
635     }
636     else {
637         m_view.clip_force_transparency->setHidden(true);
638         m_view.clip_transparency->setHidden(true);
639     }
640     
641
642     connect(m_view.clip_force_transparency, SIGNAL(toggled(bool)), m_view.clip_transparency, SLOT(setEnabled(bool)));
643     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
644     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
645     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
646     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
647     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
648     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
649     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
650     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
651
652     m_view.tabWidget->removeTab(METATAB);
653     m_view.tabWidget->removeTab(MARKERTAB);
654     m_view.tabWidget->removeTab(IMAGETAB);
655     m_view.tabWidget->removeTab(SLIDETAB);
656     m_view.tabWidget->removeTab(COLORTAB);
657     m_view.tabWidget->removeTab(AUDIOTAB);
658     m_view.tabWidget->removeTab(VIDEOTAB);
659
660     m_view.clip_path->setHidden(true);
661     m_view.label_path->setHidden(true);
662     m_view.label_description->setHidden(true);
663     m_view.label_size->setHidden(true);
664     m_view.clip_filesize->setHidden(true);
665     m_view.clip_filesize->setHidden(true);
666     m_view.clip_path->setHidden(true);
667     m_view.clip_description->setHidden(true);
668     m_view.clip_thumb->setHidden(true);
669     m_view.label_duration->setHidden(true);
670     m_view.clip_duration->setHidden(true);
671
672     if (commonproperties.contains("out")) {
673         if (commonproperties.value("out").toInt() > 0) {
674             m_view.clip_force_out->setChecked(true);
675             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
676         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
677     } else {
678         m_view.clip_force_out->setHidden(true);
679         m_view.clip_out->setHidden(true);
680     }
681 }
682
683 ClipProperties::~ClipProperties()
684 {
685     QAbstractItemDelegate *del1 = m_view.clip_vproperties->itemDelegate();
686     if (del1) delete del1;
687     QAbstractItemDelegate *del2 = m_view.clip_aproperties->itemDelegate();
688     if (del2) delete del2;
689 }
690
691 void ClipProperties::slotApplyProperties()
692 {
693     if (m_clip != NULL) {
694         QMap <QString, QString> props = properties();
695         emit applyNewClipProperties(m_clip->getId(), m_clip->currentProperties(props), props, needsTimelineRefresh(), needsTimelineReload());
696     }
697     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
698 }
699
700 void ClipProperties::disableClipId(const QString &id)
701 {
702     if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
703         if (m_clip->getId() == id) {
704             // clip was removed from project, close this properties dialog
705             close();
706         }
707     }
708 }
709
710 void ClipProperties::slotModified()
711 {
712     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
713 }
714
715
716 void ClipProperties::slotEnableLuma(int state)
717 {
718     bool enable = false;
719     if (state == Qt::Checked) enable = true;
720     m_view.luma_duration->setEnabled(enable);
721     m_view.luma_duration_frames->setEnabled(enable);
722     m_view.slide_luma->setEnabled(enable);
723     if (enable) {
724         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
725     } else m_view.luma_file->setEnabled(false);
726     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
727     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
728 }
729
730 void ClipProperties::slotEnableLumaFile(int state)
731 {
732     bool enable = false;
733     if (state == Qt::Checked) enable = true;
734     m_view.luma_file->setEnabled(enable);
735     m_view.luma_softness->setEnabled(enable);
736     m_view.label_softness->setEnabled(enable);
737 }
738
739 void ClipProperties::slotUpdateAnalysisData(DocClipBase *clip)
740 {
741     if (m_clip != clip) return;
742     m_view.analysis_list->clear();
743     QMap <QString, QString> analysis = clip->analysisData();
744     m_view.analysis_box->setHidden(analysis.isEmpty());
745     QMap<QString, QString>::const_iterator i = analysis.constBegin();
746     while (i != analysis.constEnd()) {
747         QStringList itemtext;
748         itemtext << i.key() << i.value();
749         (void) new QTreeWidgetItem(m_view.analysis_list, itemtext);
750         ++i;
751     }
752 }
753
754 void ClipProperties::slotFillMarkersList(DocClipBase *clip)
755 {
756     if (m_clip != clip) return;
757     m_view.markers_list->clear();
758     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
759     for (int count = 0; count < marks.count(); ++count) {
760         QString time = m_tc.getTimecode(marks[count].time());
761         QStringList itemtext;
762         itemtext << time << marks.at(count).comment();
763         QTreeWidgetItem *item = new QTreeWidgetItem(m_view.markers_list, itemtext);
764         item->setData(0, Qt::DecorationRole, CommentedTime::markerColor(marks.at(count).markerType()));
765     }
766 }
767
768 void ClipProperties::slotAddMarker()
769 {
770     CommentedTime marker(GenTime(), i18n("Marker"));
771     QPointer<MarkerDialog> d = new MarkerDialog(m_clip, marker,
772                                           m_tc, i18n("Add Marker"), this);
773     if (d->exec() == QDialog::Accepted) {
774         emit addMarker(m_clip->getId(), d->newMarker());
775     }
776     delete d;
777 }
778
779 void ClipProperties::slotSaveMarkers()
780 {
781     emit saveMarkers(m_clip->getId());
782 }
783
784 void ClipProperties::slotLoadMarkers()
785 {
786     emit loadMarkers(m_clip->getId());
787 }
788
789 void ClipProperties::slotEditMarker()
790 {
791     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
792     int pos = m_view.markers_list->currentIndex().row();
793     if (pos < 0 || pos > marks.count() - 1) return;
794     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
795     if (d.exec() == QDialog::Accepted) {
796         emit addMarker(m_clip->getId(), d.newMarker());
797     }
798 }
799
800 void ClipProperties::slotDeleteMarker()
801 {
802     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
803     QList < CommentedTime > toDelete;
804     for (int i = 0; i < marks.count(); i++) {
805         if (m_view.markers_list->topLevelItem(i)->isSelected()) {
806             CommentedTime marker = marks.at(i);
807             marker.setMarkerType(-1);
808             toDelete << marker;
809         }
810     }
811     for (int i = 0; i < toDelete.count(); i++)
812         emit addMarker(m_clip->getId(), toDelete.at(i));
813 }
814
815 void ClipProperties::slotDeleteAnalysis()
816 {
817     QTreeWidgetItem *current = m_view.analysis_list->currentItem();
818     if (current) emit deleteAnalysis(m_clip->getId(), current->text(0));
819 }
820
821 const QString &ClipProperties::clipId() const
822 {
823     return m_clip->getId();
824 }
825
826
827 QMap <QString, QString> ClipProperties::properties()
828 {
829     QMap <QString, QString> props;
830     QLocale locale;
831     CLIPTYPE t = UNKNOWN;
832     if (m_clip != NULL) {
833         t = m_clip->clipType();
834         m_old_props = m_clip->properties();
835     }
836
837     int aspectNumerator = m_view.clip_ar_num->value();
838     int aspectDenominator = m_view.clip_ar_den->value();
839     if (m_view.clip_force_ar->isChecked()) {
840         if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
841             aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
842             props["force_aspect_num"] = QString::number(aspectNumerator);
843             props["force_aspect_den"] = QString::number(aspectDenominator);
844             props["force_aspect_ratio"].clear();
845             m_clipNeedsRefresh = true;
846         }
847     } else {
848         if (m_old_props.contains("force_aspect_num") && !m_old_props.value("force_aspect_num").isEmpty()) {
849             props["force_aspect_num"].clear();
850             m_clipNeedsRefresh = true;
851         }
852         if (m_old_props.contains("force_aspect_den") && !m_old_props.value("force_aspect_den").isEmpty()) {
853             props["force_aspect_den"].clear();
854             m_clipNeedsRefresh = true;
855         }
856     }
857
858     double fps = m_view.clip_framerate->value();
859     if (m_view.clip_force_framerate->isChecked()) {
860         if (fps != m_old_props.value("force_fps").toDouble()) {
861             props["force_fps"] = locale.toString(fps);
862             m_clipNeedsRefresh = true;
863         }
864     } else if (m_old_props.contains("force_fps") && !m_old_props.value("force_fps").isEmpty()) {
865         props["force_fps"].clear();
866         m_clipNeedsRefresh = true;
867     }
868
869     int progressive = m_view.clip_progressive->value();
870     if (m_view.clip_force_progressive->isChecked()) {
871         if (progressive != m_old_props.value("force_progressive").toInt()) {
872             props["force_progressive"] = QString::number(progressive);
873         }
874     } else if (m_old_props.contains("force_progressive") && !m_old_props.value("force_progressive").isEmpty()) {
875         props["force_progressive"].clear();
876     }
877
878     int fieldOrder = m_view.clip_fieldorder->currentIndex();
879     if (m_view.clip_force_fieldorder->isChecked()) {
880         if (fieldOrder != m_old_props.value("force_tff").toInt()) {
881             props["force_tff"] = QString::number(fieldOrder);
882         }
883     } else if (m_old_props.contains("force_tff") && !m_old_props.value("force_tff").isEmpty()) {
884         props["force_tff"].clear();
885     }
886
887     int threads = m_view.clip_threads->value();
888     if (m_view.clip_force_threads->isChecked()) {
889         if (threads != m_old_props.value("threads").toInt()) {
890             props["threads"] = QString::number(threads);
891         }
892     } else if (m_old_props.contains("threads") && !m_old_props.value("threads").isEmpty()) {
893         props["threads"].clear();
894     }
895
896     int vindex = m_view.clip_vindex->value();
897     if (m_view.clip_force_vindex->isChecked()) {
898         if (vindex != m_old_props.value("video_index").toInt()) {
899             props["video_index"] = QString::number(vindex);
900         }
901     } else if (m_old_props.contains("video_index") && !m_old_props.value("video_index").isEmpty()) {
902         props["video_index"].clear();
903     }
904
905     int aindex = m_view.clip_aindex->value();
906     if (m_view.clip_force_aindex->isChecked()) {
907         if (aindex != m_old_props.value("audio_index").toInt()) {
908             props["audio_index"] = QString::number(aindex);
909         }
910     } else if (m_old_props.contains("audio_index") && !m_old_props.value("audio_index").isEmpty()) {
911         props["audio_index"].clear();
912     }
913     
914     int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
915     if (m_view.clip_force_colorspace->isChecked()) {
916         if (colorspace != m_old_props.value("force_colorspace").toInt()) {
917             props["force_colorspace"] = QString::number(colorspace);
918             m_clipNeedsRefresh = true;
919         }
920     } else if (m_old_props.contains("force_colorspace") && !m_old_props.value("force_colorspace").isEmpty()) {
921         props["force_colorspace"].clear();
922         m_clipNeedsRefresh = true;
923     }
924
925     if (m_view.clip_full_luma->isChecked()) {
926         props["full_luma"] = QString::number(1);
927         m_clipNeedsRefresh = true;
928     } else if (m_old_props.contains("full_luma") && !m_old_props.value("full_luma").isEmpty()) {
929         props["full_luma"].clear();
930         m_clipNeedsRefresh = true;
931     }
932     
933     if (m_view.clip_force_transparency->isChecked()) {
934         QString transp = QString::number(m_view.clip_transparency->currentIndex());
935         if (transp != m_old_props.value("transparency")) props["transparency"] = transp;
936     }
937
938     // If we adjust several clips, return now
939     if (m_clip == NULL) {
940         if (m_view.clip_out->isEnabled()) {
941             int duration = m_tc.getFrameCount(m_view.clip_out->text());
942             if (duration != m_old_props.value("out").toInt()) {
943                 props["out"] = QString::number(duration - 1);
944             }
945         }
946         return props;
947     }
948
949     if (m_old_props.value("description") != m_view.clip_description->text())
950         props["description"] = m_view.clip_description->text();
951
952     if (t == COLOR) {
953         QString new_color = m_view.clip_color->color().name();
954         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
955             m_clipNeedsRefresh = true;
956             props["colour"] = "0x" + new_color.right(6) + "ff";
957         }
958         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
959         if (duration != m_clip->duration().frames(m_fps)) {
960             props["out"] = QString::number(duration - 1);
961         }
962     } else if (t == IMAGE) {
963         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
964             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
965             //m_clipNeedsRefresh = true;
966         }
967         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
968         if (duration != m_clip->duration().frames(m_fps)) {
969             props["out"] = QString::number(duration - 1);
970         }
971     } else if (t == SLIDESHOW) {
972         QString value = QString::number((int) m_view.slide_loop->isChecked());
973         if (m_old_props.value("loop") != value) props["loop"] = value;
974         value = QString::number((int) m_view.slide_crop->isChecked());
975         if (m_old_props.value("crop") != value) props["crop"] = value;
976         value = QString::number((int) m_view.slide_fade->isChecked());
977         if (m_old_props.value("fade") != value) props["fade"] = value;
978         value = QString::number((int) m_view.luma_softness->value());
979         if (m_old_props.value("softness") != value) props["softness"] = value;
980
981         bool isMime = !(m_view.clip_path->text().contains('%'));
982         if (isMime) {
983             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
984             QString new_path = m_view.clip_path->text() + extension;
985             if (new_path != m_old_props.value("resource")) {
986                 m_clipNeedsReLoad = true;
987                 props["resource"] = new_path;
988                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
989             }
990         }
991         int duration;
992         if (m_view.slide_duration_format->currentIndex() == 1) {
993             // we are in frames mode
994             duration = m_view.slide_duration_frames->value();
995         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
996         if (duration != m_old_props.value("ttl").toInt()) {
997             m_clipNeedsRefresh = true;
998             props["ttl"] = QString::number(duration);
999             props["length"] = QString::number(duration * m_count);
1000         }
1001
1002         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
1003             m_clipNeedsRefresh = true;
1004             props["out"] = QString::number(duration * m_count - 1);
1005         }
1006         if (m_view.slide_fade->isChecked()) {
1007             int luma_duration;
1008             if (m_view.slide_duration_format->currentIndex() == 1) {
1009                 // we are in frames mode
1010                 luma_duration = m_view.luma_duration_frames->value();
1011             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
1012             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
1013                 m_clipNeedsRefresh = true;
1014                 props["luma_duration"] = QString::number(luma_duration);
1015             }
1016             QString lumaFile;
1017             if (m_view.slide_luma->isChecked())
1018                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
1019             if (lumaFile != m_old_props.value("luma_file")) {
1020                 m_clipNeedsRefresh = true;
1021                 props["luma_file"] = lumaFile;
1022             }
1023         } else {
1024             if (!m_old_props.value("luma_file").isEmpty()) {
1025                 props["luma_file"].clear();
1026             }
1027         }
1028
1029         QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
1030         if (animation != m_old_props.value("animation")) {
1031             if (animation.isEmpty()) {
1032                 props["animation"].clear();
1033             } else {
1034                 props["animation"] = animation;
1035             }
1036             m_clipNeedsRefresh = true;
1037         }
1038     }
1039     return props;
1040 }
1041
1042 bool ClipProperties::needsTimelineRefresh() const
1043 {
1044     return m_clipNeedsRefresh;
1045 }
1046
1047 bool ClipProperties::needsTimelineReload() const
1048 {
1049     return m_clipNeedsReLoad;
1050 }
1051
1052
1053 void ClipProperties::parseFolder()
1054 {
1055     QString path = m_view.clip_path->text();
1056     bool isMime = !(path.contains('%'));
1057     if (!isMime) path = KUrl(path).directory();
1058     QDir dir(path);
1059
1060     QStringList filters;
1061     QString extension;
1062
1063     if (isMime) {
1064         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
1065         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1066         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1067         dir.setNameFilters(filters);
1068     }
1069
1070     QStringList result = dir.entryList(QDir::Files);
1071
1072     if (!isMime) {
1073         // find pattern
1074         QString filter = KUrl(m_view.clip_path->text()).fileName();
1075         QString ext = filter.section('.', -1);
1076         filter = filter.section('%', 0, -2);
1077         QString regexp = '^' + filter + "\\d+\\." + ext + '$';
1078         QRegExp rx(regexp);
1079         QStringList entries;
1080         foreach(const QString & path, result) {
1081             if (rx.exactMatch(path)) entries << path;
1082         }
1083         result = entries;
1084     }
1085
1086     m_count = result.count();
1087     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
1088     if (m_count == 0) {
1089         // no images, do not accept that
1090         m_view.slide_info->setText(i18n("No image found"));
1091         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
1092         return;
1093     }
1094     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
1095     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
1096     QDomElement xml = m_clip->toXML();
1097     xml.setAttribute("resource", m_view.clip_path->text() + extension);
1098     int width = 180.0 * KdenliveSettings::project_display_ratio();
1099     if (width % 2 == 1) width++;
1100     QString filePath = m_view.clip_path->text();
1101     if (isMime) filePath.append(extension);
1102     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
1103     QMap <QString, QString> props = m_clip->properties();
1104     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
1105     m_view.clip_thumb->setPixmap(pix);
1106 }
1107
1108 void ClipProperties::slotCheckMaxLength()
1109 {
1110     if (m_clip->maxDuration() == GenTime()) return;
1111     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1112     if (duration > m_clip->maxDuration().frames(m_fps)) {
1113         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
1114     }
1115 }
1116
1117 void ClipProperties::slotUpdateDurationFormat(int ix)
1118 {
1119     bool framesFormat = ix == 1;
1120     if (framesFormat) {
1121         // switching to frames count, update widget
1122         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
1123         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
1124         m_view.slide_duration->setHidden(true);
1125         m_view.luma_duration->setHidden(true);
1126         m_view.slide_duration_frames->setHidden(false);
1127         m_view.luma_duration_frames->setHidden(false);
1128     } else {
1129         // switching to timecode format
1130         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
1131         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
1132         m_view.slide_duration_frames->setHidden(true);
1133         m_view.luma_duration_frames->setHidden(true);
1134         m_view.slide_duration->setHidden(false);
1135         m_view.luma_duration->setHidden(false);
1136     }
1137 }
1138
1139 void ClipProperties::slotDeleteProxy()
1140 {
1141       QString proxy = m_clip->getProperty("proxy");
1142       if (proxy.isEmpty()) return;
1143       emit deleteProxy(proxy);
1144       if (m_proxyContainer) delete m_proxyContainer;
1145 }
1146
1147 void ClipProperties::slotOpenUrl(const QString &url)
1148 {
1149     new KRun(KUrl(url), this);
1150 }
1151
1152 #include "clipproperties.moc"
1153
1154
1155