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