1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "clipproperties.h"
22 #include "kdenlivesettings.h"
24 #include "markerdialog.h"
25 #include "profilesdialog.h"
27 #include <KStandardDirs>
33 static const int VIDEOTAB = 0;
34 static const int AUDIOTAB = 1;
35 static const int COLORTAB = 2;
36 static const int SLIDETAB = 3;
37 static const int IMAGETAB = 4;
38 static const int MARKERTAB = 5;
39 static const int METATAB = 6;
40 static const int ADVANCEDTAB = 7;
43 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
49 m_clipNeedsRefresh(false),
50 m_clipNeedsReLoad(false),
53 setAttribute(Qt::WA_DeleteOnClose, true);
54 setFont(KGlobalSettings::toolBarFont());
56 KUrl url = m_clip->fileURL();
57 m_view.clip_path->setText(url.path());
58 m_view.clip_description->setText(m_clip->description());
59 connect(m_view.clip_description, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
61 QMap <QString, QString> props = m_clip->properties();
62 m_view.clip_force_out->setHidden(true);
63 m_view.clip_out->setHidden(true);
65 // New display aspect ratio support
66 if (props.contains("force_aspect_num") && props.value("force_aspect_num").toInt() > 0 &&
67 props.contains("force_aspect_den") && props.value("force_aspect_den").toInt() > 0) {
68 m_view.clip_force_ar->setChecked(true);
69 m_view.clip_ar_num->setEnabled(true);
70 m_view.clip_ar_den->setEnabled(true);
71 m_view.clip_ar_num->setValue(props.value("force_aspect_num").toInt());
72 m_view.clip_ar_den->setValue(props.value("force_aspect_den").toInt());
74 // Legacy support for pixel aspect ratio
75 else if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
76 m_view.clip_force_ar->setChecked(true);
77 m_view.clip_ar_num->setEnabled(true);
78 m_view.clip_ar_den->setEnabled(true);
79 if (props.contains("frame_size")) {
80 int width = props.value("force_aspect_ratio").toDouble() * props.value("frame_size").section('x', 0, 0).toInt();
81 int height = props.value("frame_size").section('x', 1, 1).toInt();
82 if (width > 0 && height > 0) {
83 if ((width / height * 100) == 133) {
87 else if (int(width / height * 100) == 177) {
91 m_view.clip_ar_num->setValue(width);
92 m_view.clip_ar_den->setValue(height);
96 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
97 connect(m_view.clip_ar_num, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
98 connect(m_view.clip_ar_den, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
100 if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
101 m_view.clip_force_framerate->setChecked(true);
102 m_view.clip_framerate->setEnabled(true);
103 m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
105 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
106 connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
108 if (props.contains("force_progressive")) {
109 m_view.clip_force_progressive->setChecked(true);
110 m_view.clip_progressive->setEnabled(true);
111 m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
113 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
114 connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
116 if (props.contains("threads") && props.value("threads").toInt() != 1) {
117 m_view.clip_force_threads->setChecked(true);
118 m_view.clip_threads->setEnabled(true);
119 m_view.clip_threads->setValue(props.value("threads").toInt());
121 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
122 connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
124 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
125 m_view.clip_force_vindex->setChecked(true);
126 m_view.clip_vindex->setEnabled(true);
127 m_view.clip_vindex->setValue(props.value("video_index").toInt());
129 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
130 connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
132 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
133 m_view.clip_force_aindex->setChecked(true);
134 m_view.clip_aindex->setEnabled(true);
135 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
137 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
138 connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
140 if (props.contains("audio_max")) {
141 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
144 if (props.contains("video_max")) {
145 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
148 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
149 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
150 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
151 if (props.contains("force_colorspace")) {
152 m_view.clip_force_colorspace->setChecked(true);
153 m_view.clip_colorspace->setEnabled(true);
154 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("force_colorspace").toInt()));
155 } else if (props.contains("colorspace")) {
156 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("colorspace").toInt()));
158 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
159 connect(m_view.clip_colorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
161 if (props.contains("full_luma")) {
162 m_view.clip_full_luma->setChecked(true);
164 connect(m_view.clip_full_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
166 // Check for Metadata
167 QMap<QString, QString> meta = m_clip->metadata();
168 QMap<QString, QString>::const_iterator i = meta.constBegin();
169 while (i != meta.constEnd()) {
170 QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
171 metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
172 metaitem->setText(1, i.value());
176 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
177 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
178 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
179 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
180 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
181 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
182 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
183 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
185 if (props.contains("audiocodec"))
186 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
188 if (props.contains("channels"))
189 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
191 if (props.contains("frequency"))
192 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
194 CLIPTYPE t = m_clip->clipType();
195 if (t != AUDIO && t != AV) {
196 m_view.clip_force_aindex->setEnabled(false);
199 if (t != VIDEO && t != AV) {
200 m_view.clip_force_vindex->setEnabled(false);
204 m_view.tabWidget->removeTab(SLIDETAB);
205 m_view.tabWidget->removeTab(COLORTAB);
206 m_view.tabWidget->removeTab(AUDIOTAB);
207 m_view.tabWidget->removeTab(VIDEOTAB);
208 if (props.contains("frame_size"))
209 m_view.image_size->setText(props.value("frame_size"));
210 if (props.contains("transparency"))
211 m_view.image_transparency->setChecked(props.value("transparency").toInt());
212 connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
213 int width = 180.0 * KdenliveSettings::project_display_ratio();
214 if (width % 2 == 1) width++;
215 m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
216 } else if (t == COLOR) {
217 m_view.clip_path->setEnabled(false);
218 m_view.tabWidget->removeTab(METATAB);
219 m_view.tabWidget->removeTab(IMAGETAB);
220 m_view.tabWidget->removeTab(SLIDETAB);
221 m_view.tabWidget->removeTab(AUDIOTAB);
222 m_view.tabWidget->removeTab(VIDEOTAB);
223 m_view.clip_thumb->setHidden(true);
224 m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
225 connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
226 } else if (t == SLIDESHOW) {
228 if (url.fileName().startsWith(".all.")) {
229 // the image sequence is defined by mimetype
230 m_view.clip_path->setText(url.directory());
232 // the image sequence is defined by pattern
233 m_view.slide_type_label->setHidden(true);
234 m_view.image_type->setHidden(true);
235 m_view.clip_path->setText(url.path());
239 m_view.tabWidget->removeTab(METATAB);
240 m_view.tabWidget->removeTab(IMAGETAB);
241 m_view.tabWidget->removeTab(COLORTAB);
242 m_view.tabWidget->removeTab(AUDIOTAB);
243 m_view.tabWidget->removeTab(VIDEOTAB);
245 //WARNING: Keep in sync with slideshowclip.cpp
246 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
247 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
248 m_view.image_type->addItem("PNG (*.png)", "png");
249 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
250 m_view.image_type->addItem("GIF (*.gif)", "gif");
251 m_view.image_type->addItem("TGA (*.tga)", "tga");
252 m_view.image_type->addItem("TIF (*.tif)", "tif");
253 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
254 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
255 m_view.animation->addItem(i18n("None"), QString());
256 m_view.animation->addItem(i18n("Pan"), "Pan");
257 m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
258 m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
259 m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
260 m_view.animation->addItem(i18n("Zoom"), "Zoom");
261 m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
263 m_view.slide_loop->setChecked(props.value("loop").toInt());
264 m_view.slide_crop->setChecked(props.value("crop").toInt());
265 m_view.slide_fade->setChecked(props.value("fade").toInt());
266 m_view.luma_softness->setValue(props.value("softness").toInt());
267 if (!props.value("animation").isEmpty())
268 m_view.animation->setCurrentItem(props.value("animation"));
270 m_view.animation->setCurrentIndex(0);
271 QString path = props.value("resource");
272 QString ext = path.section('.', -1);
273 for (int i = 0; i < m_view.image_type->count(); i++) {
274 if (m_view.image_type->itemData(i).toString() == ext) {
275 m_view.image_type->setCurrentIndex(i);
279 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
281 m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
282 m_view.slide_duration_format->addItem(i18n("Frames"));
283 connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
284 m_view.slide_duration_frames->setHidden(true);
285 m_view.luma_duration_frames->setHidden(true);
289 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
290 QString lumaFile = props.value("luma_file");
292 // Check for Kdenlive installed luma files
294 filters << "*.pgm" << "*.png";
296 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
297 foreach(const QString & folder, customLumas) {
298 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
299 foreach(const QString & fname, filesnames) {
300 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
301 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
305 // Check for MLT lumas
306 QString profilePath = KdenliveSettings::mltpath();
307 QString folder = profilePath.section('/', 0, -3);
308 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
309 QDir lumafolder(folder);
310 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
311 foreach(const QString & fname, filesnames) {
312 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
313 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
316 if (!lumaFile.isEmpty()) {
317 m_view.slide_luma->setChecked(true);
318 m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
319 } else m_view.luma_file->setEnabled(false);
320 slotEnableLuma(m_view.slide_fade->checkState());
321 slotEnableLumaFile(m_view.slide_luma->checkState());
323 connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
324 connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
325 connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
326 connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
327 connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
328 connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
329 connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
330 connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
331 connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
332 connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
335 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
336 connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
337 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
339 } else if (t != AUDIO) {
340 m_view.tabWidget->removeTab(IMAGETAB);
341 m_view.tabWidget->removeTab(SLIDETAB);
342 m_view.tabWidget->removeTab(COLORTAB);
346 m_propsDelegate = new PropertiesViewDelegate(this);
347 m_view.clip_vproperties->setItemDelegate(m_propsDelegate);
348 m_view.clip_aproperties->setItemDelegate(m_propsDelegate);
349 m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
350 m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
352 if (props.contains("videocodec"))
353 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
355 if (props.contains("frame_size"))
356 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
358 if (props.contains("fps")) {
359 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
360 if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
362 if (props.contains("aspect_ratio"))
363 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
365 if (props.contains("pix_fmt"))
366 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
368 if (props.contains("colorspace"))
369 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
371 int width = 180.0 * KdenliveSettings::project_display_ratio();
372 if (width % 2 == 1) width++;
373 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
374 m_view.clip_thumb->setPixmap(pix);
375 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
377 m_view.tabWidget->removeTab(IMAGETAB);
378 m_view.tabWidget->removeTab(SLIDETAB);
379 m_view.tabWidget->removeTab(COLORTAB);
380 m_view.tabWidget->removeTab(VIDEOTAB);
381 m_view.clip_thumb->setHidden(true);
384 if (t != SLIDESHOW && t != COLOR) {
385 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
386 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
388 m_view.clip_filesize->setHidden(true);
389 m_view.label_size->setHidden(true);
391 m_view.clip_duration->setInputMask("");
392 m_view.clip_duration->setValidator(tc.validator());
393 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
394 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
395 else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
398 m_view.marker_new->setIcon(KIcon("document-new"));
399 m_view.marker_new->setToolTip(i18n("Add marker"));
400 m_view.marker_edit->setIcon(KIcon("document-properties"));
401 m_view.marker_edit->setToolTip(i18n("Edit marker"));
402 m_view.marker_delete->setIcon(KIcon("trash-empty"));
403 m_view.marker_delete->setToolTip(i18n("Delete marker"));
405 slotFillMarkersList();
406 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
407 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
408 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
409 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
411 connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
412 connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
413 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
418 // Used for multiple clips editing
419 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
425 m_clipNeedsRefresh(false),
426 m_clipNeedsReLoad(false)
428 setFont(KGlobalSettings::toolBarFont());
429 m_view.setupUi(this);
430 QMap <QString, QString> props = cliplist.at(0)->properties();
431 m_old_props = commonproperties;
433 if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
434 m_view.clip_force_ar->setChecked(true);
435 m_view.clip_ar_num->setEnabled(true);
436 m_view.clip_ar_den->setEnabled(true);
437 m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
438 m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
441 if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
442 m_view.clip_force_framerate->setChecked(true);
443 m_view.clip_framerate->setEnabled(true);
444 m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
447 if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
448 m_view.clip_force_progressive->setChecked(true);
449 m_view.clip_progressive->setEnabled(true);
450 m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
453 if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
454 m_view.clip_force_threads->setChecked(true);
455 m_view.clip_threads->setEnabled(true);
456 m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
459 if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
460 m_view.clip_force_vindex->setChecked(true);
461 m_view.clip_vindex->setEnabled(true);
462 m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
465 if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
466 m_view.clip_force_aindex->setChecked(true);
467 m_view.clip_aindex->setEnabled(true);
468 m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
471 if (props.contains("audio_max")) {
472 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
475 if (props.contains("video_max")) {
476 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
479 if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
480 m_view.clip_force_colorspace->setChecked(true);
481 m_view.clip_colorspace->setEnabled(true);
482 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
485 if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
486 m_view.clip_full_luma->setChecked(true);
489 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
490 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
491 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
492 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
493 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
494 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
495 connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
496 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
498 m_view.tabWidget->removeTab(METATAB);
499 m_view.tabWidget->removeTab(MARKERTAB);
500 m_view.tabWidget->removeTab(IMAGETAB);
501 m_view.tabWidget->removeTab(SLIDETAB);
502 m_view.tabWidget->removeTab(COLORTAB);
503 m_view.tabWidget->removeTab(AUDIOTAB);
504 m_view.tabWidget->removeTab(VIDEOTAB);
506 m_view.clip_path->setHidden(true);
507 m_view.label_path->setHidden(true);
508 m_view.label_description->setHidden(true);
509 m_view.label_size->setHidden(true);
510 m_view.clip_filesize->setHidden(true);
511 m_view.clip_filesize->setHidden(true);
512 m_view.clip_path->setHidden(true);
513 m_view.clip_description->setHidden(true);
514 m_view.clip_thumb->setHidden(true);
515 m_view.label_duration->setHidden(true);
516 m_view.clip_duration->setHidden(true);
518 if (commonproperties.contains("out")) {
519 if (commonproperties.value("out").toInt() > 0) {
520 m_view.clip_force_out->setChecked(true);
521 m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
522 } else m_view.clip_out->setText(KdenliveSettings::image_duration());
524 m_view.clip_force_out->setHidden(true);
525 m_view.clip_out->setHidden(true);
529 ClipProperties::~ClipProperties()
531 if (m_propsDelegate) delete m_propsDelegate;
534 void ClipProperties::slotApplyProperties()
537 emit applyNewClipProperties(m_clip->getId(), m_clip->properties(), properties(), needsTimelineRefresh(), needsTimelineReload());
538 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
541 void ClipProperties::disableClipId(const QString &id)
543 if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
544 if (m_clip->getId() == id) {
545 // clip was removed from project, close this properties dialog
551 void ClipProperties::slotModified()
553 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
557 void ClipProperties::slotEnableLuma(int state)
560 if (state == Qt::Checked) enable = true;
561 m_view.luma_duration->setEnabled(enable);
562 m_view.luma_duration_frames->setEnabled(enable);
563 m_view.slide_luma->setEnabled(enable);
565 m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
566 } else m_view.luma_file->setEnabled(false);
567 m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
568 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
571 void ClipProperties::slotEnableLumaFile(int state)
574 if (state == Qt::Checked) enable = true;
575 m_view.luma_file->setEnabled(enable);
576 m_view.luma_softness->setEnabled(enable);
577 m_view.label_softness->setEnabled(enable);
580 void ClipProperties::slotFillMarkersList()
582 m_view.markers_list->clear();
583 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
584 for (int count = 0; count < marks.count(); ++count) {
585 QString time = m_tc.getTimecode(marks[count].time());
586 QStringList itemtext;
587 itemtext << time << marks[count].comment();
588 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
592 void ClipProperties::slotAddMarker()
594 CommentedTime marker(GenTime(), i18n("Marker"));
595 MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
596 if (d.exec() == QDialog::Accepted) {
597 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
599 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
602 void ClipProperties::slotEditMarker()
604 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
605 int pos = m_view.markers_list->currentIndex().row();
606 if (pos < 0 || pos > marks.count() - 1) return;
607 MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
608 if (d.exec() == QDialog::Accepted) {
609 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
611 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
614 void ClipProperties::slotDeleteMarker()
616 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
617 int pos = m_view.markers_list->currentIndex().row();
618 if (pos < 0 || pos > marks.count() - 1) return;
619 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
621 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
624 const QString &ClipProperties::clipId() const
626 return m_clip->getId();
630 QMap <QString, QString> ClipProperties::properties()
632 QMap <QString, QString> props;
633 CLIPTYPE t = UNKNOWN;
634 if (m_clip != NULL) {
635 t = m_clip->clipType();
636 m_old_props = m_clip->properties();
639 int aspectNumerator = m_view.clip_ar_num->value();
640 int aspectDenominator = m_view.clip_ar_den->value();
641 if (m_view.clip_force_ar->isChecked()) {
642 if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
643 aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
644 props["force_aspect_num"] = QString::number(aspectNumerator);
645 props["force_aspect_den"] = QString::number(aspectDenominator);
646 props["force_aspect_ratio"].clear();
647 m_clipNeedsRefresh = true;
650 if (m_old_props.contains("force_aspect_num")) {
651 props["force_aspect_num"].clear();
652 m_clipNeedsRefresh = true;
654 if (m_old_props.contains("force_aspect_den")) {
655 props["force_aspect_den"].clear();
656 m_clipNeedsRefresh = true;
660 double fps = m_view.clip_framerate->value();
661 if (m_view.clip_force_framerate->isChecked()) {
662 if (fps != m_old_props.value("force_fps").toDouble()) {
663 props["force_fps"] = QString::number(fps);
664 m_clipNeedsRefresh = true;
666 } else if (m_old_props.contains("force_fps")) {
667 props["force_fps"].clear();
668 m_clipNeedsRefresh = true;
671 int progressive = m_view.clip_progressive->value();
672 if (m_view.clip_force_progressive->isChecked()) {
673 if (progressive != m_old_props.value("force_progressive").toInt()) {
674 props["force_progressive"] = QString::number(progressive);
676 } else if (m_old_props.contains("force_progressive")) {
677 props["force_progressive"].clear();
680 int threads = m_view.clip_threads->value();
681 if (m_view.clip_force_threads->isChecked()) {
682 if (threads != m_old_props.value("threads").toInt()) {
683 props["threads"] = QString::number(threads);
685 } else if (m_old_props.contains("threads")) {
686 props["threads"].clear();
689 int vindex = m_view.clip_vindex->value();
690 if (m_view.clip_force_vindex->isChecked()) {
691 if (vindex != m_old_props.value("video_index").toInt()) {
692 props["video_index"] = QString::number(vindex);
694 } else if (m_old_props.contains("video_index")) {
695 props["video_index"].clear();
698 int aindex = m_view.clip_aindex->value();
699 if (m_view.clip_force_aindex->isChecked()) {
700 if (aindex != m_old_props.value("audio_index").toInt()) {
701 props["audio_index"] = QString::number(aindex);
703 } else if (m_old_props.contains("audio_index")) {
704 props["audio_index"].clear();
707 int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
708 if (m_view.clip_force_colorspace->isChecked()) {
709 if (colorspace != m_old_props.value("force_colorspace").toInt()) {
710 props["force_colorspace"] = QString::number(colorspace);
711 m_clipNeedsRefresh = true;
713 } else if (m_old_props.contains("force_colorspace")) {
714 props["force_colorspace"].clear();
715 m_clipNeedsRefresh = true;
718 if (m_view.clip_full_luma->isChecked()) {
719 props["full_luma"] = QString::number(1);
720 m_clipNeedsRefresh = true;
721 } else if (m_old_props.contains("full_luma")) {
722 props["full_luma"].clear();
723 m_clipNeedsRefresh = true;
726 // If we adjust several clips, return now
727 if (m_clip == NULL) {
728 if (m_view.clip_out->isEnabled()) {
729 int duration = m_tc.getFrameCount(m_view.clip_out->text());
730 if (duration != m_old_props.value("out").toInt()) {
731 props["out"] = QString::number(duration - 1);
737 if (m_old_props.value("description") != m_view.clip_description->text())
738 props["description"] = m_view.clip_description->text();
741 QString new_color = m_view.clip_color->color().name();
742 if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
743 m_clipNeedsRefresh = true;
744 props["colour"] = "0x" + new_color.right(6) + "ff";
746 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
747 if (duration != m_clip->duration().frames(m_fps)) {
748 props["out"] = QString::number(duration - 1);
750 } else if (t == IMAGE) {
751 if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
752 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
753 //m_clipNeedsRefresh = true;
755 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
756 if (duration != m_clip->duration().frames(m_fps)) {
757 props["out"] = QString::number(duration - 1);
759 } else if (t == SLIDESHOW) {
760 QString value = QString::number((int) m_view.slide_loop->isChecked());
761 if (m_old_props.value("loop") != value) props["loop"] = value;
762 value = QString::number((int) m_view.slide_crop->isChecked());
763 if (m_old_props.value("crop") != value) props["crop"] = value;
764 value = QString::number((int) m_view.slide_fade->isChecked());
765 if (m_old_props.value("fade") != value) props["fade"] = value;
766 value = QString::number((int) m_view.luma_softness->value());
767 if (m_old_props.value("softness") != value) props["softness"] = value;
769 bool isMime = !(m_view.clip_path->text().contains('%'));
771 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
772 QString new_path = m_view.clip_path->text() + extension;
773 if (new_path != m_old_props.value("resource")) {
774 m_clipNeedsReLoad = true;
775 props["resource"] = new_path;
776 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
780 if (m_view.slide_duration_format->currentIndex() == 1) {
781 // we are in frames mode
782 duration = m_view.slide_duration_frames->value();
783 } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
784 if (duration != m_old_props.value("ttl").toInt()) {
785 m_clipNeedsRefresh = true;
786 props["ttl"] = QString::number(duration);
787 props["out"] = QString::number(duration * m_count - 1);
790 if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
791 m_clipNeedsRefresh = true;
792 props["out"] = QString::number(duration * m_count - 1);
794 if (m_view.slide_fade->isChecked()) {
796 if (m_view.slide_duration_format->currentIndex() == 1) {
797 // we are in frames mode
798 luma_duration = m_view.luma_duration_frames->value();
799 } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
800 if (luma_duration != m_old_props.value("luma_duration").toInt()) {
801 m_clipNeedsRefresh = true;
802 props["luma_duration"] = QString::number(luma_duration);
805 if (m_view.slide_luma->isChecked())
806 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
807 if (lumaFile != m_old_props.value("luma_file")) {
808 m_clipNeedsRefresh = true;
809 props["luma_file"] = lumaFile;
812 if (!m_old_props.value("luma_file").isEmpty()) {
813 props["luma_file"].clear();
817 QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
818 if (animation != m_old_props.value("animation")) {
819 if (animation.isEmpty()) {
820 props["animation"].clear();
822 props["animation"] = animation;
824 m_clipNeedsRefresh = true;
830 bool ClipProperties::needsTimelineRefresh() const
832 return m_clipNeedsRefresh;
835 bool ClipProperties::needsTimelineReload() const
837 return m_clipNeedsReLoad;
841 void ClipProperties::parseFolder()
843 QString path = m_view.clip_path->text();
844 bool isMime = !(path.contains('%'));
845 if (!isMime) path = KUrl(path).directory();
852 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
853 filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
854 extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
855 dir.setNameFilters(filters);
858 QStringList result = dir.entryList(QDir::Files);
862 QString filter = KUrl(m_view.clip_path->text()).fileName();
863 QString ext = filter.section('.', -1);
864 filter = filter.section('%', 0, -2);
865 QString regexp = "^" + filter + "\\d+\\." + ext + "$";
868 foreach(const QString & path, result) {
869 if (rx.exactMatch(path)) entries << path;
874 m_count = result.count();
875 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
877 // no images, do not accept that
878 m_view.slide_info->setText(i18n("No image found"));
879 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
882 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
883 m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
884 QDomElement xml = m_clip->toXML();
885 xml.setAttribute("resource", m_view.clip_path->text() + extension);
886 int width = 180.0 * KdenliveSettings::project_display_ratio();
887 if (width % 2 == 1) width++;
888 QString filePath = m_view.clip_path->text();
889 if (isMime) filePath.append(extension);
890 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
891 QMap <QString, QString> props = m_clip->properties();
892 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
893 m_view.clip_thumb->setPixmap(pix);
896 void ClipProperties::slotCheckMaxLength()
898 if (m_clip->maxDuration() == GenTime()) return;
899 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
900 if (duration > m_clip->maxDuration().frames(m_fps)) {
901 m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
905 void ClipProperties::slotUpdateDurationFormat(int ix)
907 bool framesFormat = ix == 1;
909 // switching to frames count, update widget
910 m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
911 m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
912 m_view.slide_duration->setHidden(true);
913 m_view.luma_duration->setHidden(true);
914 m_view.slide_duration_frames->setHidden(false);
915 m_view.luma_duration_frames->setHidden(false);
917 // switching to timecode format
918 m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
919 m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
920 m_view.slide_duration_frames->setHidden(true);
921 m_view.luma_duration_frames->setHidden(true);
922 m_view.slide_duration->setHidden(false);
923 m_view.luma_duration->setHidden(false);
927 #include "clipproperties.moc"