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