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