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());
55 KUrl url = m_clip->fileURL();
56 m_view.clip_path->setText(url.path());
57 m_view.clip_description->setText(m_clip->description());
58 connect(m_view.clip_description, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
60 QMap <QString, QString> props = m_clip->properties();
61 m_view.clip_force_out->setHidden(true);
62 m_view.clip_out->setHidden(true);
64 // New display aspect ratio support
65 if (props.contains("force_aspect_num") && props.value("force_aspect_num").toInt() > 0 &&
66 props.contains("force_aspect_den") && props.value("force_aspect_den").toInt() > 0) {
67 m_view.clip_force_ar->setChecked(true);
68 m_view.clip_ar_num->setEnabled(true);
69 m_view.clip_ar_den->setEnabled(true);
70 m_view.clip_ar_num->setValue(props.value("force_aspect_num").toInt());
71 m_view.clip_ar_den->setValue(props.value("force_aspect_den").toInt());
73 // Legacy support for pixel aspect ratio
74 else if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
75 m_view.clip_force_ar->setChecked(true);
76 m_view.clip_ar_num->setEnabled(true);
77 m_view.clip_ar_den->setEnabled(true);
78 if (props.contains("frame_size")) {
79 int width = props.value("force_aspect_ratio").toDouble() * props.value("frame_size").section('x', 0, 0).toInt();
80 int height = props.value("frame_size").section('x', 1, 1).toInt();
81 if (width > 0 && height > 0) {
82 if ((width / height * 100) == 133) {
86 else if (int(width / height * 100) == 177) {
90 m_view.clip_ar_num->setValue(width);
91 m_view.clip_ar_den->setValue(height);
95 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
96 connect(m_view.clip_ar_num, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
97 connect(m_view.clip_ar_den, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
99 if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
100 m_view.clip_force_framerate->setChecked(true);
101 m_view.clip_framerate->setEnabled(true);
102 m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
104 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
105 connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
107 if (props.contains("force_progressive")) {
108 m_view.clip_force_progressive->setChecked(true);
109 m_view.clip_progressive->setEnabled(true);
110 m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
112 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
113 connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
115 m_view.clip_fieldorder->addItem(i18n("Bottom first"), 0);
116 m_view.clip_fieldorder->addItem(i18n("Top first"), 1);
117 if (props.contains("force_tff")) {
118 m_view.clip_force_fieldorder->setChecked(true);
119 m_view.clip_fieldorder->setEnabled(true);
120 m_view.clip_fieldorder->setCurrentIndex(props.value("force_tff").toInt());
122 connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
123 connect(m_view.clip_fieldorder, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
125 if (props.contains("threads") && props.value("threads").toInt() != 1) {
126 m_view.clip_force_threads->setChecked(true);
127 m_view.clip_threads->setEnabled(true);
128 m_view.clip_threads->setValue(props.value("threads").toInt());
130 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
131 connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
133 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
134 m_view.clip_force_vindex->setChecked(true);
135 m_view.clip_vindex->setEnabled(true);
136 m_view.clip_vindex->setValue(props.value("video_index").toInt());
138 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
139 connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
141 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
142 m_view.clip_force_aindex->setChecked(true);
143 m_view.clip_aindex->setEnabled(true);
144 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
146 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
147 connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
149 if (props.contains("audio_max")) {
150 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
153 if (props.contains("video_max")) {
154 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
157 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
158 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
159 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
160 if (props.contains("force_colorspace")) {
161 m_view.clip_force_colorspace->setChecked(true);
162 m_view.clip_colorspace->setEnabled(true);
163 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("force_colorspace").toInt()));
164 } else if (props.contains("colorspace")) {
165 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("colorspace").toInt()));
167 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
168 connect(m_view.clip_colorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
170 if (props.contains("full_luma")) {
171 m_view.clip_full_luma->setChecked(true);
173 connect(m_view.clip_full_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
175 // Check for Metadata
176 QMap<QString, QString> meta = m_clip->metadata();
177 QMap<QString, QString>::const_iterator i = meta.constBegin();
178 while (i != meta.constEnd()) {
179 QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
180 metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
181 metaitem->setText(1, i.value());
185 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
186 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
187 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
188 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
189 connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), m_view.clip_fieldorder, SLOT(setEnabled(bool)));
190 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
191 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
192 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
193 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
195 if (props.contains("audiocodec"))
196 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
198 if (props.contains("channels"))
199 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
201 if (props.contains("frequency"))
202 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
204 CLIPTYPE t = m_clip->clipType();
205 if (t != AUDIO && t != AV) {
206 m_view.clip_force_aindex->setEnabled(false);
209 if (t != VIDEO && t != AV) {
210 m_view.clip_force_vindex->setEnabled(false);
214 m_view.tabWidget->removeTab(SLIDETAB);
215 m_view.tabWidget->removeTab(COLORTAB);
216 m_view.tabWidget->removeTab(AUDIOTAB);
217 m_view.tabWidget->removeTab(VIDEOTAB);
218 if (props.contains("frame_size"))
219 m_view.image_size->setText(props.value("frame_size"));
220 if (props.contains("transparency"))
221 m_view.image_transparency->setChecked(props.value("transparency").toInt());
222 connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
223 int width = 180.0 * KdenliveSettings::project_display_ratio();
224 if (width % 2 == 1) width++;
225 m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
226 } else if (t == COLOR) {
227 m_view.clip_path->setEnabled(false);
228 m_view.tabWidget->removeTab(METATAB);
229 m_view.tabWidget->removeTab(IMAGETAB);
230 m_view.tabWidget->removeTab(SLIDETAB);
231 m_view.tabWidget->removeTab(AUDIOTAB);
232 m_view.tabWidget->removeTab(VIDEOTAB);
233 m_view.clip_thumb->setHidden(true);
234 m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
235 connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
236 } else if (t == SLIDESHOW) {
238 if (url.fileName().startsWith(".all.")) {
239 // the image sequence is defined by mimetype
240 m_view.clip_path->setText(url.directory());
242 // the image sequence is defined by pattern
243 m_view.slide_type_label->setHidden(true);
244 m_view.image_type->setHidden(true);
245 m_view.clip_path->setText(url.path());
249 m_view.tabWidget->removeTab(METATAB);
250 m_view.tabWidget->removeTab(IMAGETAB);
251 m_view.tabWidget->removeTab(COLORTAB);
252 m_view.tabWidget->removeTab(AUDIOTAB);
253 m_view.tabWidget->removeTab(VIDEOTAB);
255 //WARNING: Keep in sync with slideshowclip.cpp
256 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
257 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
258 m_view.image_type->addItem("PNG (*.png)", "png");
259 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
260 m_view.image_type->addItem("GIF (*.gif)", "gif");
261 m_view.image_type->addItem("TGA (*.tga)", "tga");
262 m_view.image_type->addItem("TIF (*.tif)", "tif");
263 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
264 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
265 m_view.animation->addItem(i18n("None"), QString());
266 m_view.animation->addItem(i18n("Pan"), "Pan");
267 m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
268 m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
269 m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
270 m_view.animation->addItem(i18n("Zoom"), "Zoom");
271 m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
273 m_view.slide_loop->setChecked(props.value("loop").toInt());
274 m_view.slide_crop->setChecked(props.value("crop").toInt());
275 m_view.slide_fade->setChecked(props.value("fade").toInt());
276 m_view.luma_softness->setValue(props.value("softness").toInt());
277 if (!props.value("animation").isEmpty())
278 m_view.animation->setCurrentItem(props.value("animation"));
280 m_view.animation->setCurrentIndex(0);
281 QString path = props.value("resource");
282 QString ext = path.section('.', -1);
283 for (int i = 0; i < m_view.image_type->count(); i++) {
284 if (m_view.image_type->itemData(i).toString() == ext) {
285 m_view.image_type->setCurrentIndex(i);
289 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
291 m_view.slide_duration_format->addItem(i18n("hh:mm:ss:ff"));
292 m_view.slide_duration_format->addItem(i18n("Frames"));
293 connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
294 m_view.slide_duration_frames->setHidden(true);
295 m_view.luma_duration_frames->setHidden(true);
299 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
300 QString lumaFile = props.value("luma_file");
302 // Check for Kdenlive installed luma files
304 filters << "*.pgm" << "*.png";
306 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
307 foreach(const QString & folder, customLumas) {
308 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
309 foreach(const QString & fname, filesnames) {
310 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
311 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
315 // Check for MLT lumas
316 QString profilePath = KdenliveSettings::mltpath();
317 QString folder = profilePath.section('/', 0, -3);
318 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
319 QDir lumafolder(folder);
320 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
321 foreach(const QString & fname, filesnames) {
322 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
323 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
326 if (!lumaFile.isEmpty()) {
327 m_view.slide_luma->setChecked(true);
328 m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
329 } else m_view.luma_file->setEnabled(false);
330 slotEnableLuma(m_view.slide_fade->checkState());
331 slotEnableLumaFile(m_view.slide_luma->checkState());
333 connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
334 connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
335 connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
336 connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
337 connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
338 connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
339 connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
340 connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
341 connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
342 connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
345 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
346 connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
347 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
349 } else if (t != AUDIO) {
350 m_view.tabWidget->removeTab(IMAGETAB);
351 m_view.tabWidget->removeTab(SLIDETAB);
352 m_view.tabWidget->removeTab(COLORTAB);
354 PropertiesViewDelegate *del1 = new PropertiesViewDelegate(this);
355 PropertiesViewDelegate *del2 = new PropertiesViewDelegate(this);
356 m_view.clip_vproperties->setItemDelegate(del1);
357 m_view.clip_aproperties->setItemDelegate(del2);
358 m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
359 m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
361 if (props.contains("videocodec"))
362 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
364 if (props.contains("frame_size"))
365 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
367 if (props.contains("fps")) {
368 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
369 if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
371 if (props.contains("aspect_ratio"))
372 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
374 if (props.contains("pix_fmt"))
375 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
377 if (props.contains("colorspace"))
378 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
380 int width = 180.0 * KdenliveSettings::project_display_ratio();
381 if (width % 2 == 1) width++;
382 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
383 m_view.clip_thumb->setPixmap(pix);
384 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
386 m_view.tabWidget->removeTab(IMAGETAB);
387 m_view.tabWidget->removeTab(SLIDETAB);
388 m_view.tabWidget->removeTab(COLORTAB);
389 m_view.tabWidget->removeTab(VIDEOTAB);
390 m_view.clip_thumb->setHidden(true);
393 if (t != SLIDESHOW && t != COLOR) {
394 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
395 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
397 m_view.clip_filesize->setHidden(true);
398 m_view.label_size->setHidden(true);
400 m_view.clip_duration->setInputMask("");
401 m_view.clip_duration->setValidator(tc.validator());
402 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
403 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
404 else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
407 m_view.marker_new->setIcon(KIcon("document-new"));
408 m_view.marker_new->setToolTip(i18n("Add marker"));
409 m_view.marker_edit->setIcon(KIcon("document-properties"));
410 m_view.marker_edit->setToolTip(i18n("Edit marker"));
411 m_view.marker_delete->setIcon(KIcon("trash-empty"));
412 m_view.marker_delete->setToolTip(i18n("Delete marker"));
414 slotFillMarkersList();
415 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
416 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
417 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
418 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
420 connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
421 connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
422 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
427 // Used for multiple clips editing
428 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
434 m_clipNeedsRefresh(false),
435 m_clipNeedsReLoad(false)
437 setFont(KGlobalSettings::toolBarFont());
438 m_view.setupUi(this);
439 QString title = windowTitle();
440 title.append(" " + i18np("(%1 clip)", "(%1 clips)", cliplist.count()).arg(cliplist.count()));
441 setWindowTitle(title);
442 QMap <QString, QString> props = cliplist.at(0)->properties();
443 m_old_props = commonproperties;
445 if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
446 m_view.clip_force_ar->setChecked(true);
447 m_view.clip_ar_num->setEnabled(true);
448 m_view.clip_ar_den->setEnabled(true);
449 m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
450 m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
453 if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
454 m_view.clip_force_framerate->setChecked(true);
455 m_view.clip_framerate->setEnabled(true);
456 m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
459 if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
460 m_view.clip_force_progressive->setChecked(true);
461 m_view.clip_progressive->setEnabled(true);
462 m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
465 if (commonproperties.contains("force_tff") && !commonproperties.value("force_tff").isEmpty()) {
466 m_view.clip_force_fieldorder->setChecked(true);
467 m_view.clip_fieldorder->setEnabled(true);
468 m_view.clip_fieldorder->setCurrentIndex(commonproperties.value("force_tff").toInt());
471 if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
472 m_view.clip_force_threads->setChecked(true);
473 m_view.clip_threads->setEnabled(true);
474 m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
477 if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
478 m_view.clip_force_vindex->setChecked(true);
479 m_view.clip_vindex->setEnabled(true);
480 m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
483 if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
484 m_view.clip_force_aindex->setChecked(true);
485 m_view.clip_aindex->setEnabled(true);
486 m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
489 if (props.contains("audio_max")) {
490 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
493 if (props.contains("video_max")) {
494 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
497 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
498 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
499 m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
501 if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
502 m_view.clip_force_colorspace->setChecked(true);
503 m_view.clip_colorspace->setEnabled(true);
504 m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
507 if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
508 m_view.clip_full_luma->setChecked(true);
511 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
512 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
513 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
514 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
515 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
516 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
517 connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
518 connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
520 m_view.tabWidget->removeTab(METATAB);
521 m_view.tabWidget->removeTab(MARKERTAB);
522 m_view.tabWidget->removeTab(IMAGETAB);
523 m_view.tabWidget->removeTab(SLIDETAB);
524 m_view.tabWidget->removeTab(COLORTAB);
525 m_view.tabWidget->removeTab(AUDIOTAB);
526 m_view.tabWidget->removeTab(VIDEOTAB);
528 m_view.clip_path->setHidden(true);
529 m_view.label_path->setHidden(true);
530 m_view.label_description->setHidden(true);
531 m_view.label_size->setHidden(true);
532 m_view.clip_filesize->setHidden(true);
533 m_view.clip_filesize->setHidden(true);
534 m_view.clip_path->setHidden(true);
535 m_view.clip_description->setHidden(true);
536 m_view.clip_thumb->setHidden(true);
537 m_view.label_duration->setHidden(true);
538 m_view.clip_duration->setHidden(true);
540 if (commonproperties.contains("out")) {
541 if (commonproperties.value("out").toInt() > 0) {
542 m_view.clip_force_out->setChecked(true);
543 m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
544 } else m_view.clip_out->setText(KdenliveSettings::image_duration());
546 m_view.clip_force_out->setHidden(true);
547 m_view.clip_out->setHidden(true);
551 ClipProperties::~ClipProperties()
553 QAbstractItemDelegate *del1 = m_view.clip_vproperties->itemDelegate();
554 if (del1) delete del1;
555 QAbstractItemDelegate *del2 = m_view.clip_aproperties->itemDelegate();
556 if (del2) delete del2;
559 void ClipProperties::slotApplyProperties()
562 emit applyNewClipProperties(m_clip->getId(), m_clip->properties(), properties(), needsTimelineRefresh(), needsTimelineReload());
563 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
566 void ClipProperties::disableClipId(const QString &id)
568 if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
569 if (m_clip->getId() == id) {
570 // clip was removed from project, close this properties dialog
576 void ClipProperties::slotModified()
578 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
582 void ClipProperties::slotEnableLuma(int state)
585 if (state == Qt::Checked) enable = true;
586 m_view.luma_duration->setEnabled(enable);
587 m_view.luma_duration_frames->setEnabled(enable);
588 m_view.slide_luma->setEnabled(enable);
590 m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
591 } else m_view.luma_file->setEnabled(false);
592 m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
593 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
596 void ClipProperties::slotEnableLumaFile(int state)
599 if (state == Qt::Checked) enable = true;
600 m_view.luma_file->setEnabled(enable);
601 m_view.luma_softness->setEnabled(enable);
602 m_view.label_softness->setEnabled(enable);
605 void ClipProperties::slotFillMarkersList()
607 m_view.markers_list->clear();
608 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
609 for (int count = 0; count < marks.count(); ++count) {
610 QString time = m_tc.getTimecode(marks[count].time());
611 QStringList itemtext;
612 itemtext << time << marks[count].comment();
613 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
617 void ClipProperties::slotAddMarker()
619 CommentedTime marker(GenTime(), i18n("Marker"));
620 MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
621 if (d.exec() == QDialog::Accepted) {
622 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
624 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
627 void ClipProperties::slotEditMarker()
629 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
630 int pos = m_view.markers_list->currentIndex().row();
631 if (pos < 0 || pos > marks.count() - 1) return;
632 MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
633 if (d.exec() == QDialog::Accepted) {
634 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
636 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
639 void ClipProperties::slotDeleteMarker()
641 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
642 int pos = m_view.markers_list->currentIndex().row();
643 if (pos < 0 || pos > marks.count() - 1) return;
644 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
646 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
649 const QString &ClipProperties::clipId() const
651 return m_clip->getId();
655 QMap <QString, QString> ClipProperties::properties()
657 QMap <QString, QString> props;
658 CLIPTYPE t = UNKNOWN;
659 if (m_clip != NULL) {
660 t = m_clip->clipType();
661 m_old_props = m_clip->properties();
664 int aspectNumerator = m_view.clip_ar_num->value();
665 int aspectDenominator = m_view.clip_ar_den->value();
666 if (m_view.clip_force_ar->isChecked()) {
667 if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
668 aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
669 props["force_aspect_num"] = QString::number(aspectNumerator);
670 props["force_aspect_den"] = QString::number(aspectDenominator);
671 props["force_aspect_ratio"].clear();
672 m_clipNeedsRefresh = true;
675 if (m_old_props.contains("force_aspect_num")) {
676 props["force_aspect_num"].clear();
677 m_clipNeedsRefresh = true;
679 if (m_old_props.contains("force_aspect_den")) {
680 props["force_aspect_den"].clear();
681 m_clipNeedsRefresh = true;
685 double fps = m_view.clip_framerate->value();
686 if (m_view.clip_force_framerate->isChecked()) {
687 if (fps != m_old_props.value("force_fps").toDouble()) {
688 props["force_fps"] = QString::number(fps);
689 m_clipNeedsRefresh = true;
691 } else if (m_old_props.contains("force_fps")) {
692 props["force_fps"].clear();
693 m_clipNeedsRefresh = true;
696 int progressive = m_view.clip_progressive->value();
697 if (m_view.clip_force_progressive->isChecked()) {
698 if (progressive != m_old_props.value("force_progressive").toInt()) {
699 props["force_progressive"] = QString::number(progressive);
701 } else if (m_old_props.contains("force_progressive")) {
702 props["force_progressive"].clear();
705 int fieldOrder = m_view.clip_fieldorder->currentIndex();
706 if (m_view.clip_force_fieldorder->isChecked()) {
707 if (fieldOrder != m_old_props.value("force_tff").toInt()) {
708 props["force_tff"] = QString::number(fieldOrder);
710 } else if (m_old_props.contains("force_tff")) {
711 props["force_tff"].clear();
714 int threads = m_view.clip_threads->value();
715 if (m_view.clip_force_threads->isChecked()) {
716 if (threads != m_old_props.value("threads").toInt()) {
717 props["threads"] = QString::number(threads);
719 } else if (m_old_props.contains("threads")) {
720 props["threads"].clear();
723 int vindex = m_view.clip_vindex->value();
724 if (m_view.clip_force_vindex->isChecked()) {
725 if (vindex != m_old_props.value("video_index").toInt()) {
726 props["video_index"] = QString::number(vindex);
728 } else if (m_old_props.contains("video_index")) {
729 props["video_index"].clear();
732 int aindex = m_view.clip_aindex->value();
733 if (m_view.clip_force_aindex->isChecked()) {
734 if (aindex != m_old_props.value("audio_index").toInt()) {
735 props["audio_index"] = QString::number(aindex);
737 } else if (m_old_props.contains("audio_index")) {
738 props["audio_index"].clear();
741 int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
742 if (m_view.clip_force_colorspace->isChecked()) {
743 if (colorspace != m_old_props.value("force_colorspace").toInt()) {
744 props["force_colorspace"] = QString::number(colorspace);
745 m_clipNeedsRefresh = true;
747 } else if (m_old_props.contains("force_colorspace")) {
748 props["force_colorspace"].clear();
749 m_clipNeedsRefresh = true;
752 if (m_view.clip_full_luma->isChecked()) {
753 props["full_luma"] = QString::number(1);
754 m_clipNeedsRefresh = true;
755 } else if (m_old_props.contains("full_luma")) {
756 props["full_luma"].clear();
757 m_clipNeedsRefresh = true;
760 // If we adjust several clips, return now
761 if (m_clip == NULL) {
762 if (m_view.clip_out->isEnabled()) {
763 int duration = m_tc.getFrameCount(m_view.clip_out->text());
764 if (duration != m_old_props.value("out").toInt()) {
765 props["out"] = QString::number(duration - 1);
771 if (m_old_props.value("description") != m_view.clip_description->text())
772 props["description"] = m_view.clip_description->text();
775 QString new_color = m_view.clip_color->color().name();
776 if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
777 m_clipNeedsRefresh = true;
778 props["colour"] = "0x" + new_color.right(6) + "ff";
780 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
781 if (duration != m_clip->duration().frames(m_fps)) {
782 props["out"] = QString::number(duration - 1);
784 } else if (t == IMAGE) {
785 if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
786 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
787 //m_clipNeedsRefresh = true;
789 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
790 if (duration != m_clip->duration().frames(m_fps)) {
791 props["out"] = QString::number(duration - 1);
793 } else if (t == SLIDESHOW) {
794 QString value = QString::number((int) m_view.slide_loop->isChecked());
795 if (m_old_props.value("loop") != value) props["loop"] = value;
796 value = QString::number((int) m_view.slide_crop->isChecked());
797 if (m_old_props.value("crop") != value) props["crop"] = value;
798 value = QString::number((int) m_view.slide_fade->isChecked());
799 if (m_old_props.value("fade") != value) props["fade"] = value;
800 value = QString::number((int) m_view.luma_softness->value());
801 if (m_old_props.value("softness") != value) props["softness"] = value;
803 bool isMime = !(m_view.clip_path->text().contains('%'));
805 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
806 QString new_path = m_view.clip_path->text() + extension;
807 if (new_path != m_old_props.value("resource")) {
808 m_clipNeedsReLoad = true;
809 props["resource"] = new_path;
810 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
814 if (m_view.slide_duration_format->currentIndex() == 1) {
815 // we are in frames mode
816 duration = m_view.slide_duration_frames->value();
817 } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
818 if (duration != m_old_props.value("ttl").toInt()) {
819 m_clipNeedsRefresh = true;
820 props["ttl"] = QString::number(duration);
821 props["length"] = QString::number(duration * m_count);
824 if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
825 m_clipNeedsRefresh = true;
826 props["out"] = QString::number(duration * m_count - 1);
828 if (m_view.slide_fade->isChecked()) {
830 if (m_view.slide_duration_format->currentIndex() == 1) {
831 // we are in frames mode
832 luma_duration = m_view.luma_duration_frames->value();
833 } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
834 if (luma_duration != m_old_props.value("luma_duration").toInt()) {
835 m_clipNeedsRefresh = true;
836 props["luma_duration"] = QString::number(luma_duration);
839 if (m_view.slide_luma->isChecked())
840 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
841 if (lumaFile != m_old_props.value("luma_file")) {
842 m_clipNeedsRefresh = true;
843 props["luma_file"] = lumaFile;
846 if (!m_old_props.value("luma_file").isEmpty()) {
847 props["luma_file"].clear();
851 QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
852 if (animation != m_old_props.value("animation")) {
853 if (animation.isEmpty()) {
854 props["animation"].clear();
856 props["animation"] = animation;
858 m_clipNeedsRefresh = true;
864 bool ClipProperties::needsTimelineRefresh() const
866 return m_clipNeedsRefresh;
869 bool ClipProperties::needsTimelineReload() const
871 return m_clipNeedsReLoad;
875 void ClipProperties::parseFolder()
877 QString path = m_view.clip_path->text();
878 bool isMime = !(path.contains('%'));
879 if (!isMime) path = KUrl(path).directory();
886 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
887 filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
888 extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
889 dir.setNameFilters(filters);
892 QStringList result = dir.entryList(QDir::Files);
896 QString filter = KUrl(m_view.clip_path->text()).fileName();
897 QString ext = filter.section('.', -1);
898 filter = filter.section('%', 0, -2);
899 QString regexp = "^" + filter + "\\d+\\." + ext + "$";
902 foreach(const QString & path, result) {
903 if (rx.exactMatch(path)) entries << path;
908 m_count = result.count();
909 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
911 // no images, do not accept that
912 m_view.slide_info->setText(i18n("No image found"));
913 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
916 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
917 m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
918 QDomElement xml = m_clip->toXML();
919 xml.setAttribute("resource", m_view.clip_path->text() + extension);
920 int width = 180.0 * KdenliveSettings::project_display_ratio();
921 if (width % 2 == 1) width++;
922 QString filePath = m_view.clip_path->text();
923 if (isMime) filePath.append(extension);
924 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
925 QMap <QString, QString> props = m_clip->properties();
926 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
927 m_view.clip_thumb->setPixmap(pix);
930 void ClipProperties::slotCheckMaxLength()
932 if (m_clip->maxDuration() == GenTime()) return;
933 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
934 if (duration > m_clip->maxDuration().frames(m_fps)) {
935 m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
939 void ClipProperties::slotUpdateDurationFormat(int ix)
941 bool framesFormat = ix == 1;
943 // switching to frames count, update widget
944 m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
945 m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
946 m_view.slide_duration->setHidden(true);
947 m_view.luma_duration->setHidden(true);
948 m_view.slide_duration_frames->setHidden(false);
949 m_view.luma_duration_frames->setHidden(false);
951 // switching to timecode format
952 m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
953 m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
954 m_view.slide_duration_frames->setHidden(true);
955 m_view.luma_duration_frames->setHidden(true);
956 m_view.slide_duration->setHidden(false);
957 m_view.luma_duration->setHidden(false);
961 #include "clipproperties.moc"