]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
1d5e39ee5dce7e62cce42b33e7d3b7fee1bf9933
[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         QList <CommentedTime> markers;
775         markers << d->newMarker();
776         emit addMarkers(m_clip->getId(), markers);
777     }
778     delete d;
779 }
780
781 void ClipProperties::slotSaveMarkers()
782 {
783     emit saveMarkers(m_clip->getId());
784 }
785
786 void ClipProperties::slotLoadMarkers()
787 {
788     emit loadMarkers(m_clip->getId());
789 }
790
791 void ClipProperties::slotEditMarker()
792 {
793     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
794     int pos = m_view.markers_list->currentIndex().row();
795     if (pos < 0 || pos > marks.count() - 1) return;
796     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
797     if (d.exec() == QDialog::Accepted) {
798         QList <CommentedTime> markers;
799         markers << d.newMarker();
800         emit addMarkers(m_clip->getId(), markers);
801     }
802 }
803
804 void ClipProperties::slotDeleteMarker()
805 {
806     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
807     QList < CommentedTime > toDelete;
808     for (int i = 0; i < marks.count(); i++) {
809         if (m_view.markers_list->topLevelItem(i)->isSelected()) {
810             CommentedTime marker = marks.at(i);
811             marker.setMarkerType(-1);
812             toDelete << marker;
813         }
814     }
815     emit addMarkers(m_clip->getId(), toDelete);
816 }
817
818 void ClipProperties::slotDeleteAnalysis()
819 {
820     QTreeWidgetItem *current = m_view.analysis_list->currentItem();
821     if (current) emit deleteAnalysis(m_clip->getId(), current->text(0));
822 }
823
824 const QString &ClipProperties::clipId() const
825 {
826     return m_clip->getId();
827 }
828
829
830 QMap <QString, QString> ClipProperties::properties()
831 {
832     QMap <QString, QString> props;
833     QLocale locale;
834     CLIPTYPE t = UNKNOWN;
835     if (m_clip != NULL) {
836         t = m_clip->clipType();
837         m_old_props = m_clip->properties();
838     }
839
840     int aspectNumerator = m_view.clip_ar_num->value();
841     int aspectDenominator = m_view.clip_ar_den->value();
842     if (m_view.clip_force_ar->isChecked()) {
843         if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
844             aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
845             props["force_aspect_num"] = QString::number(aspectNumerator);
846             props["force_aspect_den"] = QString::number(aspectDenominator);
847             props["force_aspect_ratio"].clear();
848             m_clipNeedsRefresh = true;
849         }
850     } else {
851         if (m_old_props.contains("force_aspect_num") && !m_old_props.value("force_aspect_num").isEmpty()) {
852             props["force_aspect_num"].clear();
853             m_clipNeedsRefresh = true;
854         }
855         if (m_old_props.contains("force_aspect_den") && !m_old_props.value("force_aspect_den").isEmpty()) {
856             props["force_aspect_den"].clear();
857             m_clipNeedsRefresh = true;
858         }
859     }
860
861     double fps = m_view.clip_framerate->value();
862     if (m_view.clip_force_framerate->isChecked()) {
863         if (fps != m_old_props.value("force_fps").toDouble()) {
864             props["force_fps"] = locale.toString(fps);
865             m_clipNeedsRefresh = true;
866         }
867     } else if (m_old_props.contains("force_fps") && !m_old_props.value("force_fps").isEmpty()) {
868         props["force_fps"].clear();
869         m_clipNeedsRefresh = true;
870     }
871
872     int progressive = m_view.clip_progressive->value();
873     if (m_view.clip_force_progressive->isChecked()) {
874         if (progressive != m_old_props.value("force_progressive").toInt()) {
875             props["force_progressive"] = QString::number(progressive);
876         }
877     } else if (m_old_props.contains("force_progressive") && !m_old_props.value("force_progressive").isEmpty()) {
878         props["force_progressive"].clear();
879     }
880
881     int fieldOrder = m_view.clip_fieldorder->currentIndex();
882     if (m_view.clip_force_fieldorder->isChecked()) {
883         if (fieldOrder != m_old_props.value("force_tff").toInt()) {
884             props["force_tff"] = QString::number(fieldOrder);
885         }
886     } else if (m_old_props.contains("force_tff") && !m_old_props.value("force_tff").isEmpty()) {
887         props["force_tff"].clear();
888     }
889
890     int threads = m_view.clip_threads->value();
891     if (m_view.clip_force_threads->isChecked()) {
892         if (threads != m_old_props.value("threads").toInt()) {
893             props["threads"] = QString::number(threads);
894         }
895     } else if (m_old_props.contains("threads") && !m_old_props.value("threads").isEmpty()) {
896         props["threads"].clear();
897     }
898
899     int vindex = m_view.clip_vindex->value();
900     if (m_view.clip_force_vindex->isChecked()) {
901         if (vindex != m_old_props.value("video_index").toInt()) {
902             props["video_index"] = QString::number(vindex);
903         }
904     } else if (m_old_props.contains("video_index") && !m_old_props.value("video_index").isEmpty()) {
905         props["video_index"].clear();
906     }
907
908     int aindex = m_view.clip_aindex->value();
909     if (m_view.clip_force_aindex->isChecked()) {
910         if (aindex != m_old_props.value("audio_index").toInt()) {
911             props["audio_index"] = QString::number(aindex);
912         }
913     } else if (m_old_props.contains("audio_index") && !m_old_props.value("audio_index").isEmpty()) {
914         props["audio_index"].clear();
915     }
916     
917     int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
918     if (m_view.clip_force_colorspace->isChecked()) {
919         if (colorspace != m_old_props.value("force_colorspace").toInt()) {
920             props["force_colorspace"] = QString::number(colorspace);
921             m_clipNeedsRefresh = true;
922         }
923     } else if (m_old_props.contains("force_colorspace") && !m_old_props.value("force_colorspace").isEmpty()) {
924         props["force_colorspace"].clear();
925         m_clipNeedsRefresh = true;
926     }
927
928     if (m_view.clip_full_luma->isChecked()) {
929         props["full_luma"] = QString::number(1);
930         m_clipNeedsRefresh = true;
931     } else if (m_old_props.contains("full_luma") && !m_old_props.value("full_luma").isEmpty()) {
932         props["full_luma"].clear();
933         m_clipNeedsRefresh = true;
934     }
935     
936     if (m_view.clip_force_transparency->isChecked()) {
937         QString transp = QString::number(m_view.clip_transparency->currentIndex());
938         if (transp != m_old_props.value("transparency")) props["transparency"] = transp;
939     }
940
941     // If we adjust several clips, return now
942     if (m_clip == NULL) {
943         if (m_view.clip_out->isEnabled()) {
944             int duration = m_tc.getFrameCount(m_view.clip_out->text());
945             if (duration != m_old_props.value("out").toInt()) {
946                 props["out"] = QString::number(duration - 1);
947             }
948         }
949         return props;
950     }
951
952     if (m_old_props.value("description") != m_view.clip_description->text())
953         props["description"] = m_view.clip_description->text();
954
955     if (t == COLOR) {
956         QString new_color = m_view.clip_color->color().name();
957         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
958             m_clipNeedsRefresh = true;
959             props["colour"] = "0x" + new_color.right(6) + "ff";
960         }
961         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
962         if (duration != m_clip->duration().frames(m_fps)) {
963             props["out"] = QString::number(duration - 1);
964         }
965     } else if (t == IMAGE) {
966         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
967             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
968             //m_clipNeedsRefresh = true;
969         }
970         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
971         if (duration != m_clip->duration().frames(m_fps)) {
972             props["out"] = QString::number(duration - 1);
973         }
974     } else if (t == SLIDESHOW) {
975         QString value = QString::number((int) m_view.slide_loop->isChecked());
976         if (m_old_props.value("loop") != value) props["loop"] = value;
977         value = QString::number((int) m_view.slide_crop->isChecked());
978         if (m_old_props.value("crop") != value) props["crop"] = value;
979         value = QString::number((int) m_view.slide_fade->isChecked());
980         if (m_old_props.value("fade") != value) props["fade"] = value;
981         value = QString::number((int) m_view.luma_softness->value());
982         if (m_old_props.value("softness") != value) props["softness"] = value;
983
984         bool isMime = !(m_view.clip_path->text().contains('%'));
985         if (isMime) {
986             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
987             QString new_path = m_view.clip_path->text() + extension;
988             if (new_path != m_old_props.value("resource")) {
989                 m_clipNeedsReLoad = true;
990                 props["resource"] = new_path;
991                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
992             }
993         }
994         int duration;
995         if (m_view.slide_duration_format->currentIndex() == 1) {
996             // we are in frames mode
997             duration = m_view.slide_duration_frames->value();
998         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
999         if (duration != m_old_props.value("ttl").toInt()) {
1000             m_clipNeedsRefresh = true;
1001             props["ttl"] = QString::number(duration);
1002             props["length"] = QString::number(duration * m_count);
1003         }
1004
1005         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
1006             m_clipNeedsRefresh = true;
1007             props["out"] = QString::number(duration * m_count - 1);
1008         }
1009         if (m_view.slide_fade->isChecked()) {
1010             int luma_duration;
1011             if (m_view.slide_duration_format->currentIndex() == 1) {
1012                 // we are in frames mode
1013                 luma_duration = m_view.luma_duration_frames->value();
1014             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
1015             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
1016                 m_clipNeedsRefresh = true;
1017                 props["luma_duration"] = QString::number(luma_duration);
1018             }
1019             QString lumaFile;
1020             if (m_view.slide_luma->isChecked())
1021                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
1022             if (lumaFile != m_old_props.value("luma_file")) {
1023                 m_clipNeedsRefresh = true;
1024                 props["luma_file"] = lumaFile;
1025             }
1026         } else {
1027             if (!m_old_props.value("luma_file").isEmpty()) {
1028                 props["luma_file"].clear();
1029             }
1030         }
1031
1032         QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
1033         if (animation != m_old_props.value("animation")) {
1034             if (animation.isEmpty()) {
1035                 props["animation"].clear();
1036             } else {
1037                 props["animation"] = animation;
1038             }
1039             m_clipNeedsRefresh = true;
1040         }
1041     }
1042     return props;
1043 }
1044
1045 bool ClipProperties::needsTimelineRefresh() const
1046 {
1047     return m_clipNeedsRefresh;
1048 }
1049
1050 bool ClipProperties::needsTimelineReload() const
1051 {
1052     return m_clipNeedsReLoad;
1053 }
1054
1055
1056 void ClipProperties::parseFolder()
1057 {
1058     QString path = m_view.clip_path->text();
1059     bool isMime = !(path.contains('%'));
1060     if (!isMime) path = KUrl(path).directory();
1061     QDir dir(path);
1062
1063     QStringList filters;
1064     QString extension;
1065
1066     if (isMime) {
1067         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
1068         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1069         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1070         dir.setNameFilters(filters);
1071     }
1072
1073     QStringList result = dir.entryList(QDir::Files);
1074
1075     if (!isMime) {
1076         // find pattern
1077         QString filter = KUrl(m_view.clip_path->text()).fileName();
1078         QString ext = filter.section('.', -1);
1079         filter = filter.section('%', 0, -2);
1080         QString regexp = '^' + filter + "\\d+\\." + ext + '$';
1081         QRegExp rx(regexp);
1082         QStringList entries;
1083         foreach(const QString & path, result) {
1084             if (rx.exactMatch(path)) entries << path;
1085         }
1086         result = entries;
1087     }
1088
1089     m_count = result.count();
1090     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
1091     if (m_count == 0) {
1092         // no images, do not accept that
1093         m_view.slide_info->setText(i18n("No image found"));
1094         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
1095         return;
1096     }
1097     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
1098     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
1099     QDomElement xml = m_clip->toXML();
1100     xml.setAttribute("resource", m_view.clip_path->text() + extension);
1101     int width = 180.0 * KdenliveSettings::project_display_ratio();
1102     if (width % 2 == 1) width++;
1103     QString filePath = m_view.clip_path->text();
1104     if (isMime) filePath.append(extension);
1105     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
1106     QMap <QString, QString> props = m_clip->properties();
1107     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
1108     m_view.clip_thumb->setPixmap(pix);
1109 }
1110
1111 void ClipProperties::slotCheckMaxLength()
1112 {
1113     if (m_clip->maxDuration() == GenTime()) return;
1114     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1115     if (duration > m_clip->maxDuration().frames(m_fps)) {
1116         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
1117     }
1118 }
1119
1120 void ClipProperties::slotUpdateDurationFormat(int ix)
1121 {
1122     bool framesFormat = ix == 1;
1123     if (framesFormat) {
1124         // switching to frames count, update widget
1125         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
1126         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
1127         m_view.slide_duration->setHidden(true);
1128         m_view.luma_duration->setHidden(true);
1129         m_view.slide_duration_frames->setHidden(false);
1130         m_view.luma_duration_frames->setHidden(false);
1131     } else {
1132         // switching to timecode format
1133         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
1134         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
1135         m_view.slide_duration_frames->setHidden(true);
1136         m_view.luma_duration_frames->setHidden(true);
1137         m_view.slide_duration->setHidden(false);
1138         m_view.luma_duration->setHidden(false);
1139     }
1140 }
1141
1142 void ClipProperties::slotDeleteProxy()
1143 {
1144       QString proxy = m_clip->getProperty("proxy");
1145       if (proxy.isEmpty()) return;
1146       emit deleteProxy(proxy);
1147       if (m_proxyContainer) delete m_proxyContainer;
1148 }
1149
1150 void ClipProperties::slotOpenUrl(const QString &url)
1151 {
1152     new KRun(KUrl(url), this);
1153 }
1154
1155 #include "clipproperties.moc"
1156
1157
1158