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)
52 setAttribute(Qt::WA_DeleteOnClose, true);
53 setFont(KGlobalSettings::toolBarFont());
56 // force transparency is only for group properties, so hide it
57 m_view.clip_force_transparency->setHidden(true);
58 m_view.clip_transparency->setHidden(true);
60 KUrl url = m_clip->fileURL();
61 m_view.clip_path->setText(url.path());
62 m_view.clip_description->setText(m_clip->description());
63 connect(m_view.clip_description, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
65 QMap <QString, QString> props = m_clip->properties();
66 m_view.clip_force_out->setHidden(true);
67 m_view.clip_out->setHidden(true);
69 // New display aspect ratio support
70 if (props.contains("force_aspect_num") && props.value("force_aspect_num").toInt() > 0 &&
71 props.contains("force_aspect_den") && props.value("force_aspect_den").toInt() > 0) {
72 m_view.clip_force_ar->setChecked(true);
73 m_view.clip_ar_num->setEnabled(true);
74 m_view.clip_ar_den->setEnabled(true);
75 m_view.clip_ar_num->setValue(props.value("force_aspect_num").toInt());
76 m_view.clip_ar_den->setValue(props.value("force_aspect_den").toInt());
78 // Legacy support for pixel aspect ratio
79 else if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
80 m_view.clip_force_ar->setChecked(true);
81 m_view.clip_ar_num->setEnabled(true);
82 m_view.clip_ar_den->setEnabled(true);
83 if (props.contains("frame_size")) {
84 int width = props.value("force_aspect_ratio").toDouble() * props.value("frame_size").section('x', 0, 0).toInt();
85 int height = props.value("frame_size").section('x', 1, 1).toInt();
86 if (width > 0 && height > 0) {
87 if ((width / height * 100) == 133) {
91 else if (int(width / height * 100) == 177) {
95 m_view.clip_ar_num->setValue(width);
96 m_view.clip_ar_den->setValue(height);
100 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
101 connect(m_view.clip_ar_num, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
102 connect(m_view.clip_ar_den, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
104 if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
105 m_view.clip_force_framerate->setChecked(true);
106 m_view.clip_framerate->setEnabled(true);
107 m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
109 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
110 connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
112 if (props.contains("force_progressive")) {
113 m_view.clip_force_progressive->setChecked(true);
114 m_view.clip_progressive->setEnabled(true);
115 m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
117 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
118 connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
120 m_view.clip_fieldorder->addItem(i18n("Bottom first"), 0);
121 m_view.clip_fieldorder->addItem(i18n("Top first"), 1);
122 if (props.contains("force_tff")) {
123 m_view.clip_force_fieldorder->setChecked(true);
124 m_view.clip_fieldorder->setEnabled(true);
125 m_view.clip_fieldorder->setCurrentIndex(props.value("force_tff").toInt());
127 connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
128 connect(m_view.clip_fieldorder, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
130 if (props.contains("threads") && props.value("threads").toInt() != 1) {
131 m_view.clip_force_threads->setChecked(true);
132 m_view.clip_threads->setEnabled(true);
133 m_view.clip_threads->setValue(props.value("threads").toInt());
135 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
136 connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
138 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
139 m_view.clip_force_vindex->setChecked(true);
140 m_view.clip_vindex->setEnabled(true);
141 m_view.clip_vindex->setValue(props.value("video_index").toInt());
143 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
144 connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
146 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
147 m_view.clip_force_aindex->setChecked(true);
148 m_view.clip_aindex->setEnabled(true);
149 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
151 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
152 connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
154 if (props.contains("audio_max")) {
155 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
158 if (props.contains("video_max")) {
159 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
162 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
163 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
164 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
165 if (props.contains("force_colorspace")) {
166 m_view.clip_force_colorspace->setChecked(true);
167 m_view.clip_colorspace->setEnabled(true);
168 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("force_colorspace").toInt()));
169 } else if (props.contains("colorspace")) {
170 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("colorspace").toInt()));
172 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
173 connect(m_view.clip_colorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
175 if (props.contains("full_luma")) {
176 m_view.clip_full_luma->setChecked(true);
178 connect(m_view.clip_full_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
180 // Check for Metadata
181 QMap<QString, QString> meta = m_clip->metadata();
182 QMap<QString, QString>::const_iterator i = meta.constBegin();
183 while (i != meta.constEnd()) {
184 QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
185 metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
186 metaitem->setText(1, i.value());
190 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
191 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
192 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
193 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
194 connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), m_view.clip_fieldorder, SLOT(setEnabled(bool)));
195 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
196 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
197 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
198 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
200 if (props.contains("audiocodec"))
201 new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
203 if (props.contains("channels"))
204 new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
206 if (props.contains("frequency"))
207 new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
210 CLIPTYPE t = m_clip->clipType();
212 if (props.contains("proxy") && props.value("proxy") != "-") {
213 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, KUrl(props.value("proxy")), true);
214 QFrame* line = new QFrame();
215 line->setFrameShape(QFrame::HLine);
216 line->setFrameShadow(QFrame::Sunken);
217 m_proxyContainer = new QFrame();
218 m_proxyContainer->setFrameShape(QFrame::NoFrame);
219 QHBoxLayout *l = new QHBoxLayout;
220 l->addWidget(new QLabel(i18n("Proxy clip: %1").arg(KIO::convertSize(f.size()))));
222 QPushButton *pb = new QPushButton(i18n("Delete proxy"));
224 connect(pb, SIGNAL(clicked()), this, SLOT(slotDeleteProxy()));
225 m_proxyContainer->setLayout(l);
227 m_view.tab_image->layout()->addWidget(line);
228 m_view.tab_image->layout()->addWidget(m_proxyContainer);
230 else if (t == AUDIO) {
231 m_view.tab_audio->layout()->addWidget(line);
232 m_view.tab_audio->layout()->addWidget(m_proxyContainer);
235 m_view.tab_video->layout()->addWidget(line);
236 m_view.tab_video->layout()->addWidget(m_proxyContainer);
240 if (t != AUDIO && t != AV) {
241 m_view.clip_force_aindex->setEnabled(false);
244 if (t != VIDEO && t != AV) {
245 m_view.clip_force_vindex->setEnabled(false);
249 m_view.tabWidget->removeTab(SLIDETAB);
250 m_view.tabWidget->removeTab(COLORTAB);
251 m_view.tabWidget->removeTab(AUDIOTAB);
252 m_view.tabWidget->removeTab(VIDEOTAB);
253 if (props.contains("frame_size"))
254 m_view.image_size->setText(props.value("frame_size"));
255 if (props.contains("transparency"))
256 m_view.image_transparency->setChecked(props.value("transparency").toInt());
257 connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
258 int width = 180.0 * KdenliveSettings::project_display_ratio();
259 if (width % 2 == 1) width++;
260 m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
261 } else if (t == COLOR) {
262 m_view.clip_path->setEnabled(false);
263 m_view.tabWidget->removeTab(METATAB);
264 m_view.tabWidget->removeTab(IMAGETAB);
265 m_view.tabWidget->removeTab(SLIDETAB);
266 m_view.tabWidget->removeTab(AUDIOTAB);
267 m_view.tabWidget->removeTab(VIDEOTAB);
268 m_view.clip_thumb->setHidden(true);
269 m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
270 connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
271 } else if (t == SLIDESHOW) {
272 if (url.fileName().startsWith(".all.")) {
273 // the image sequence is defined by mimetype
274 m_view.clip_path->setText(url.directory());
276 // the image sequence is defined by pattern
277 m_view.slide_type_label->setHidden(true);
278 m_view.image_type->setHidden(true);
279 m_view.clip_path->setText(url.path());
282 m_view.tabWidget->removeTab(METATAB);
283 m_view.tabWidget->removeTab(IMAGETAB);
284 m_view.tabWidget->removeTab(COLORTAB);
285 m_view.tabWidget->removeTab(AUDIOTAB);
286 m_view.tabWidget->removeTab(VIDEOTAB);
288 //WARNING: Keep in sync with slideshowclip.cpp
289 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
290 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
291 m_view.image_type->addItem("PNG (*.png)", "png");
292 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
293 m_view.image_type->addItem("GIF (*.gif)", "gif");
294 m_view.image_type->addItem("TGA (*.tga)", "tga");
295 m_view.image_type->addItem("TIF (*.tif)", "tif");
296 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
297 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
298 m_view.animation->addItem(i18n("None"), QString());
299 m_view.animation->addItem(i18n("Pan"), "Pan");
300 m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
301 m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
302 m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
303 m_view.animation->addItem(i18n("Zoom"), "Zoom");
304 m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
306 m_view.slide_loop->setChecked(props.value("loop").toInt());
307 m_view.slide_crop->setChecked(props.value("crop").toInt());
308 m_view.slide_fade->setChecked(props.value("fade").toInt());
309 m_view.luma_softness->setValue(props.value("softness").toInt());
310 if (!props.value("animation").isEmpty())
311 m_view.animation->setCurrentItem(props.value("animation"));
313 m_view.animation->setCurrentIndex(0);
314 QString path = props.value("resource");
315 QString ext = path.section('.', -1);
316 for (int i = 0; i < m_view.image_type->count(); i++) {
317 if (m_view.image_type->itemData(i).toString() == ext) {
318 m_view.image_type->setCurrentIndex(i);
322 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
324 m_view.slide_duration_format->addItem(i18n("hh:mm:ss:ff"));
325 m_view.slide_duration_format->addItem(i18n("Frames"));
326 connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
327 m_view.slide_duration_frames->setHidden(true);
328 m_view.luma_duration_frames->setHidden(true);
332 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
333 QString lumaFile = props.value("luma_file");
335 // Check for Kdenlive installed luma files
337 filters << "*.pgm" << "*.png";
339 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
340 foreach(const QString & folder, customLumas) {
341 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
342 foreach(const QString & fname, filesnames) {
343 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
344 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
348 // Check for MLT lumas
349 QString profilePath = KdenliveSettings::mltpath();
350 QString folder = profilePath.section('/', 0, -3);
351 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
352 QDir lumafolder(folder);
353 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
354 foreach(const QString & fname, filesnames) {
355 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
356 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
359 if (!lumaFile.isEmpty()) {
360 m_view.slide_luma->setChecked(true);
361 m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
362 } else m_view.luma_file->setEnabled(false);
363 slotEnableLuma(m_view.slide_fade->checkState());
364 slotEnableLumaFile(m_view.slide_luma->checkState());
366 connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
367 connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
368 connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
369 connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
370 connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
371 connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
372 connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
373 connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
374 connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
375 connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
378 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
379 connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
380 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
382 } else if (t != AUDIO) {
383 m_view.tabWidget->removeTab(IMAGETAB);
384 m_view.tabWidget->removeTab(SLIDETAB);
385 m_view.tabWidget->removeTab(COLORTAB);
387 PropertiesViewDelegate *del1 = new PropertiesViewDelegate(this);
388 PropertiesViewDelegate *del2 = new PropertiesViewDelegate(this);
389 m_view.clip_vproperties->setItemDelegate(del1);
390 m_view.clip_aproperties->setItemDelegate(del2);
391 m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
392 m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
394 if (props.contains("videocodec"))
395 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
397 if (props.contains("frame_size"))
398 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
400 if (props.contains("fps")) {
401 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
402 if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
405 if (props.contains("progressive")) {
406 int scanning = props.value("progressive").toInt();
407 QString txt = scanning == 1 ? i18n("Progressive") : i18n("Interlaced");
408 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Scanning") << txt);
411 if (props.contains("aspect_ratio"))
412 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
414 if (props.contains("pix_fmt"))
415 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
417 if (props.contains("colorspace"))
418 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
421 int width = 180.0 * KdenliveSettings::project_display_ratio();
422 if (width % 2 == 1) width++;
423 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
424 m_view.clip_thumb->setPixmap(pix);
425 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
427 m_view.tabWidget->removeTab(IMAGETAB);
428 m_view.tabWidget->removeTab(SLIDETAB);
429 m_view.tabWidget->removeTab(COLORTAB);
430 m_view.tabWidget->removeTab(VIDEOTAB);
431 m_view.clip_thumb->setHidden(true);
434 if (t != SLIDESHOW && t != COLOR) {
435 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
436 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
438 m_view.clip_filesize->setHidden(true);
439 m_view.label_size->setHidden(true);
441 m_view.clip_duration->setInputMask(tc.mask());
442 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
443 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
445 connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
446 connect(m_view.clip_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
450 m_view.marker_new->setIcon(KIcon("document-new"));
451 m_view.marker_new->setToolTip(i18n("Add marker"));
452 m_view.marker_edit->setIcon(KIcon("document-properties"));
453 m_view.marker_edit->setToolTip(i18n("Edit marker"));
454 m_view.marker_delete->setIcon(KIcon("trash-empty"));
455 m_view.marker_delete->setToolTip(i18n("Delete marker"));
457 slotFillMarkersList();
458 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
459 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
460 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
461 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
463 connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
464 connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
465 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
470 // Used for multiple clips editing
471 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
477 m_clipNeedsRefresh(false),
478 m_clipNeedsReLoad(false)
480 setFont(KGlobalSettings::toolBarFont());
481 m_view.setupUi(this);
482 QString title = windowTitle();
483 title.append(" " + i18np("(%1 clip)", "(%1 clips)", cliplist.count()));
484 setWindowTitle(title);
485 QMap <QString, QString> props = cliplist.at(0)->properties();
486 m_old_props = commonproperties;
488 if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
489 m_view.clip_force_ar->setChecked(true);
490 m_view.clip_ar_num->setEnabled(true);
491 m_view.clip_ar_den->setEnabled(true);
492 m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
493 m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
496 if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
497 m_view.clip_force_framerate->setChecked(true);
498 m_view.clip_framerate->setEnabled(true);
499 m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
502 if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
503 m_view.clip_force_progressive->setChecked(true);
504 m_view.clip_progressive->setEnabled(true);
505 m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
508 if (commonproperties.contains("force_tff") && !commonproperties.value("force_tff").isEmpty()) {
509 m_view.clip_force_fieldorder->setChecked(true);
510 m_view.clip_fieldorder->setEnabled(true);
511 m_view.clip_fieldorder->setCurrentIndex(commonproperties.value("force_tff").toInt());
514 if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
515 m_view.clip_force_threads->setChecked(true);
516 m_view.clip_threads->setEnabled(true);
517 m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
520 if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
521 m_view.clip_force_vindex->setChecked(true);
522 m_view.clip_vindex->setEnabled(true);
523 m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
526 if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
527 m_view.clip_force_aindex->setChecked(true);
528 m_view.clip_aindex->setEnabled(true);
529 m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
532 if (props.contains("audio_max")) {
533 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
536 if (props.contains("video_max")) {
537 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
540 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
541 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
542 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
544 if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
545 m_view.clip_force_colorspace->setChecked(true);
546 m_view.clip_colorspace->setEnabled(true);
547 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
550 if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
551 m_view.clip_full_luma->setChecked(true);
554 if (commonproperties.contains("transparency")) {
555 // image transparency checkbox
556 int transparency = commonproperties.value("transparency").toInt();
557 if (transparency == 0) {
558 m_view.clip_force_transparency->setChecked(true);
560 else if (transparency == 1) {
561 m_view.clip_force_transparency->setChecked(true);
562 m_view.clip_transparency->setCurrentIndex(1);
566 m_view.clip_force_transparency->setHidden(true);
567 m_view.clip_transparency->setHidden(true);
571 connect(m_view.clip_force_transparency, SIGNAL(toggled(bool)), m_view.clip_transparency, SLOT(setEnabled(bool)));
572 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
573 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
574 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
575 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
576 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
577 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
578 connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
579 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
581 m_view.tabWidget->removeTab(METATAB);
582 m_view.tabWidget->removeTab(MARKERTAB);
583 m_view.tabWidget->removeTab(IMAGETAB);
584 m_view.tabWidget->removeTab(SLIDETAB);
585 m_view.tabWidget->removeTab(COLORTAB);
586 m_view.tabWidget->removeTab(AUDIOTAB);
587 m_view.tabWidget->removeTab(VIDEOTAB);
589 m_view.clip_path->setHidden(true);
590 m_view.label_path->setHidden(true);
591 m_view.label_description->setHidden(true);
592 m_view.label_size->setHidden(true);
593 m_view.clip_filesize->setHidden(true);
594 m_view.clip_filesize->setHidden(true);
595 m_view.clip_path->setHidden(true);
596 m_view.clip_description->setHidden(true);
597 m_view.clip_thumb->setHidden(true);
598 m_view.label_duration->setHidden(true);
599 m_view.clip_duration->setHidden(true);
601 if (commonproperties.contains("out")) {
602 if (commonproperties.value("out").toInt() > 0) {
603 m_view.clip_force_out->setChecked(true);
604 m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
605 } else m_view.clip_out->setText(KdenliveSettings::image_duration());
607 m_view.clip_force_out->setHidden(true);
608 m_view.clip_out->setHidden(true);
612 ClipProperties::~ClipProperties()
614 QAbstractItemDelegate *del1 = m_view.clip_vproperties->itemDelegate();
615 if (del1) delete del1;
616 QAbstractItemDelegate *del2 = m_view.clip_aproperties->itemDelegate();
617 if (del2) delete del2;
620 void ClipProperties::slotApplyProperties()
622 if (m_clip != NULL) {
623 QMap <QString, QString> props = properties();
624 emit applyNewClipProperties(m_clip->getId(), m_clip->currentProperties(props), props, needsTimelineRefresh(), needsTimelineReload());
626 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
629 void ClipProperties::disableClipId(const QString &id)
631 if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
632 if (m_clip->getId() == id) {
633 // clip was removed from project, close this properties dialog
639 void ClipProperties::slotModified()
641 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
645 void ClipProperties::slotEnableLuma(int state)
648 if (state == Qt::Checked) enable = true;
649 m_view.luma_duration->setEnabled(enable);
650 m_view.luma_duration_frames->setEnabled(enable);
651 m_view.slide_luma->setEnabled(enable);
653 m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
654 } else m_view.luma_file->setEnabled(false);
655 m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
656 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
659 void ClipProperties::slotEnableLumaFile(int state)
662 if (state == Qt::Checked) enable = true;
663 m_view.luma_file->setEnabled(enable);
664 m_view.luma_softness->setEnabled(enable);
665 m_view.label_softness->setEnabled(enable);
668 void ClipProperties::slotFillMarkersList()
670 m_view.markers_list->clear();
671 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
672 for (int count = 0; count < marks.count(); ++count) {
673 QString time = m_tc.getTimecode(marks[count].time());
674 QStringList itemtext;
675 itemtext << time << marks[count].comment();
676 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
680 void ClipProperties::slotAddMarker()
682 CommentedTime marker(GenTime(), i18n("Marker"));
683 MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
684 if (d.exec() == QDialog::Accepted) {
685 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
687 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
690 void ClipProperties::slotEditMarker()
692 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
693 int pos = m_view.markers_list->currentIndex().row();
694 if (pos < 0 || pos > marks.count() - 1) return;
695 MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
696 if (d.exec() == QDialog::Accepted) {
697 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
699 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
702 void ClipProperties::slotDeleteMarker()
704 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
705 int pos = m_view.markers_list->currentIndex().row();
706 if (pos < 0 || pos > marks.count() - 1) return;
707 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
709 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
712 const QString &ClipProperties::clipId() const
714 return m_clip->getId();
718 QMap <QString, QString> ClipProperties::properties()
720 QMap <QString, QString> props;
722 CLIPTYPE t = UNKNOWN;
723 if (m_clip != NULL) {
724 t = m_clip->clipType();
725 m_old_props = m_clip->properties();
728 int aspectNumerator = m_view.clip_ar_num->value();
729 int aspectDenominator = m_view.clip_ar_den->value();
730 if (m_view.clip_force_ar->isChecked()) {
731 if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
732 aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
733 props["force_aspect_num"] = QString::number(aspectNumerator);
734 props["force_aspect_den"] = QString::number(aspectDenominator);
735 props["force_aspect_ratio"].clear();
736 m_clipNeedsRefresh = true;
739 if (m_old_props.contains("force_aspect_num") && !m_old_props.value("force_aspect_num").isEmpty()) {
740 props["force_aspect_num"].clear();
741 m_clipNeedsRefresh = true;
743 if (m_old_props.contains("force_aspect_den") && !m_old_props.value("force_aspect_den").isEmpty()) {
744 props["force_aspect_den"].clear();
745 m_clipNeedsRefresh = true;
749 double fps = m_view.clip_framerate->value();
750 if (m_view.clip_force_framerate->isChecked()) {
751 if (fps != m_old_props.value("force_fps").toDouble()) {
752 props["force_fps"] = locale.toString(fps);
753 m_clipNeedsRefresh = true;
755 } else if (m_old_props.contains("force_fps") && !m_old_props.value("force_fps").isEmpty()) {
756 props["force_fps"].clear();
757 m_clipNeedsRefresh = true;
760 int progressive = m_view.clip_progressive->value();
761 if (m_view.clip_force_progressive->isChecked()) {
762 if (progressive != m_old_props.value("force_progressive").toInt()) {
763 props["force_progressive"] = QString::number(progressive);
765 } else if (m_old_props.contains("force_progressive") && !m_old_props.value("force_progressive").isEmpty()) {
766 props["force_progressive"].clear();
769 int fieldOrder = m_view.clip_fieldorder->currentIndex();
770 if (m_view.clip_force_fieldorder->isChecked()) {
771 if (fieldOrder != m_old_props.value("force_tff").toInt()) {
772 props["force_tff"] = QString::number(fieldOrder);
774 } else if (m_old_props.contains("force_tff") && !m_old_props.value("force_tff").isEmpty()) {
775 props["force_tff"].clear();
778 int threads = m_view.clip_threads->value();
779 if (m_view.clip_force_threads->isChecked()) {
780 if (threads != m_old_props.value("threads").toInt()) {
781 props["threads"] = QString::number(threads);
783 } else if (m_old_props.contains("threads") && !m_old_props.value("threads").isEmpty()) {
784 props["threads"].clear();
787 int vindex = m_view.clip_vindex->value();
788 if (m_view.clip_force_vindex->isChecked()) {
789 if (vindex != m_old_props.value("video_index").toInt()) {
790 props["video_index"] = QString::number(vindex);
792 } else if (m_old_props.contains("video_index") && !m_old_props.value("video_index").isEmpty()) {
793 props["video_index"].clear();
796 int aindex = m_view.clip_aindex->value();
797 if (m_view.clip_force_aindex->isChecked()) {
798 if (aindex != m_old_props.value("audio_index").toInt()) {
799 props["audio_index"] = QString::number(aindex);
801 } else if (m_old_props.contains("audio_index") && !m_old_props.value("audio_index").isEmpty()) {
802 props["audio_index"].clear();
805 int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
806 if (m_view.clip_force_colorspace->isChecked()) {
807 if (colorspace != m_old_props.value("force_colorspace").toInt()) {
808 props["force_colorspace"] = QString::number(colorspace);
809 m_clipNeedsRefresh = true;
811 } else if (m_old_props.contains("force_colorspace") && !m_old_props.value("force_colorspace").isEmpty()) {
812 props["force_colorspace"].clear();
813 m_clipNeedsRefresh = true;
816 if (m_view.clip_full_luma->isChecked()) {
817 props["full_luma"] = QString::number(1);
818 m_clipNeedsRefresh = true;
819 } else if (m_old_props.contains("full_luma") && !m_old_props.value("full_luma").isEmpty()) {
820 props["full_luma"].clear();
821 m_clipNeedsRefresh = true;
824 if (m_view.clip_force_transparency->isChecked()) {
825 QString transp = QString::number(m_view.clip_transparency->currentIndex());
826 if (transp != m_old_props.value("transparency")) props["transparency"] = transp;
829 // If we adjust several clips, return now
830 if (m_clip == NULL) {
831 if (m_view.clip_out->isEnabled()) {
832 int duration = m_tc.getFrameCount(m_view.clip_out->text());
833 if (duration != m_old_props.value("out").toInt()) {
834 props["out"] = QString::number(duration - 1);
840 if (m_old_props.value("description") != m_view.clip_description->text())
841 props["description"] = m_view.clip_description->text();
844 QString new_color = m_view.clip_color->color().name();
845 if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
846 m_clipNeedsRefresh = true;
847 props["colour"] = "0x" + new_color.right(6) + "ff";
849 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
850 if (duration != m_clip->duration().frames(m_fps)) {
851 props["out"] = QString::number(duration - 1);
853 } else if (t == IMAGE) {
854 if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
855 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
856 //m_clipNeedsRefresh = true;
858 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
859 if (duration != m_clip->duration().frames(m_fps)) {
860 props["out"] = QString::number(duration - 1);
862 } else if (t == SLIDESHOW) {
863 QString value = QString::number((int) m_view.slide_loop->isChecked());
864 if (m_old_props.value("loop") != value) props["loop"] = value;
865 value = QString::number((int) m_view.slide_crop->isChecked());
866 if (m_old_props.value("crop") != value) props["crop"] = value;
867 value = QString::number((int) m_view.slide_fade->isChecked());
868 if (m_old_props.value("fade") != value) props["fade"] = value;
869 value = QString::number((int) m_view.luma_softness->value());
870 if (m_old_props.value("softness") != value) props["softness"] = value;
872 bool isMime = !(m_view.clip_path->text().contains('%'));
874 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
875 QString new_path = m_view.clip_path->text() + extension;
876 if (new_path != m_old_props.value("resource")) {
877 m_clipNeedsReLoad = true;
878 props["resource"] = new_path;
879 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
883 if (m_view.slide_duration_format->currentIndex() == 1) {
884 // we are in frames mode
885 duration = m_view.slide_duration_frames->value();
886 } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
887 if (duration != m_old_props.value("ttl").toInt()) {
888 m_clipNeedsRefresh = true;
889 props["ttl"] = QString::number(duration);
890 props["length"] = QString::number(duration * m_count);
893 if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
894 m_clipNeedsRefresh = true;
895 props["out"] = QString::number(duration * m_count - 1);
897 if (m_view.slide_fade->isChecked()) {
899 if (m_view.slide_duration_format->currentIndex() == 1) {
900 // we are in frames mode
901 luma_duration = m_view.luma_duration_frames->value();
902 } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
903 if (luma_duration != m_old_props.value("luma_duration").toInt()) {
904 m_clipNeedsRefresh = true;
905 props["luma_duration"] = QString::number(luma_duration);
908 if (m_view.slide_luma->isChecked())
909 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
910 if (lumaFile != m_old_props.value("luma_file")) {
911 m_clipNeedsRefresh = true;
912 props["luma_file"] = lumaFile;
915 if (!m_old_props.value("luma_file").isEmpty()) {
916 props["luma_file"].clear();
920 QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
921 if (animation != m_old_props.value("animation")) {
922 if (animation.isEmpty()) {
923 props["animation"].clear();
925 props["animation"] = animation;
927 m_clipNeedsRefresh = true;
933 bool ClipProperties::needsTimelineRefresh() const
935 return m_clipNeedsRefresh;
938 bool ClipProperties::needsTimelineReload() const
940 return m_clipNeedsReLoad;
944 void ClipProperties::parseFolder()
946 QString path = m_view.clip_path->text();
947 bool isMime = !(path.contains('%'));
948 if (!isMime) path = KUrl(path).directory();
955 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
956 filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
957 extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
958 dir.setNameFilters(filters);
961 QStringList result = dir.entryList(QDir::Files);
965 QString filter = KUrl(m_view.clip_path->text()).fileName();
966 QString ext = filter.section('.', -1);
967 filter = filter.section('%', 0, -2);
968 QString regexp = "^" + filter + "\\d+\\." + ext + "$";
971 foreach(const QString & path, result) {
972 if (rx.exactMatch(path)) entries << path;
977 m_count = result.count();
978 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
980 // no images, do not accept that
981 m_view.slide_info->setText(i18n("No image found"));
982 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
985 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
986 m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
987 QDomElement xml = m_clip->toXML();
988 xml.setAttribute("resource", m_view.clip_path->text() + extension);
989 int width = 180.0 * KdenliveSettings::project_display_ratio();
990 if (width % 2 == 1) width++;
991 QString filePath = m_view.clip_path->text();
992 if (isMime) filePath.append(extension);
993 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
994 QMap <QString, QString> props = m_clip->properties();
995 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
996 m_view.clip_thumb->setPixmap(pix);
999 void ClipProperties::slotCheckMaxLength()
1001 if (m_clip->maxDuration() == GenTime()) return;
1002 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1003 if (duration > m_clip->maxDuration().frames(m_fps)) {
1004 m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
1008 void ClipProperties::slotUpdateDurationFormat(int ix)
1010 bool framesFormat = ix == 1;
1012 // switching to frames count, update widget
1013 m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
1014 m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
1015 m_view.slide_duration->setHidden(true);
1016 m_view.luma_duration->setHidden(true);
1017 m_view.slide_duration_frames->setHidden(false);
1018 m_view.luma_duration_frames->setHidden(false);
1020 // switching to timecode format
1021 m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
1022 m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
1023 m_view.slide_duration_frames->setHidden(true);
1024 m_view.luma_duration_frames->setHidden(true);
1025 m_view.slide_duration->setHidden(false);
1026 m_view.luma_duration->setHidden(false);
1030 void ClipProperties::slotDeleteProxy()
1032 QString proxy = m_clip->getProperty("proxy");
1033 if (proxy.isEmpty()) return;
1034 emit deleteProxy(proxy);
1035 if (m_proxyContainer) delete m_proxyContainer;
1038 #include "clipproperties.moc"