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 if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
66 m_view.clip_force_ar->setChecked(true);
67 m_view.clip_ar->setEnabled(true);
68 m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
69 } else if (props.contains("aspect_ratio")) m_view.clip_ar->setValue(props.value("aspect_ratio").toDouble());
70 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
71 connect(m_view.clip_ar, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
73 if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
74 m_view.clip_force_framerate->setChecked(true);
75 m_view.clip_framerate->setEnabled(true);
76 m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
78 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
79 connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
81 if (props.contains("force_progressive")) {
82 m_view.clip_force_progressive->setChecked(true);
83 m_view.clip_progressive->setEnabled(true);
84 m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
86 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
87 connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
89 if (props.contains("threads") && props.value("threads").toInt() != 1) {
90 m_view.clip_force_threads->setChecked(true);
91 m_view.clip_threads->setEnabled(true);
92 m_view.clip_threads->setValue(props.value("threads").toInt());
94 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
95 connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
97 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
98 m_view.clip_force_vindex->setChecked(true);
99 m_view.clip_vindex->setEnabled(true);
100 m_view.clip_vindex->setValue(props.value("video_index").toInt());
102 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
103 connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
105 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
106 m_view.clip_force_aindex->setChecked(true);
107 m_view.clip_aindex->setEnabled(true);
108 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
110 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
111 connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
113 if (props.contains("audio_max")) {
114 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
117 if (props.contains("video_max")) {
118 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
121 // Check for Metadata
122 QMap<QString, QString> meta = m_clip->metadata();
123 QMap<QString, QString>::const_iterator i = meta.constBegin();
124 while (i != meta.constEnd()) {
125 QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
126 metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
127 metaitem->setText(1, i.value());
131 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
132 connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
133 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
134 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
135 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
136 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
138 if (props.contains("audiocodec"))
139 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
141 if (props.contains("channels"))
142 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
144 if (props.contains("frequency"))
145 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
147 CLIPTYPE t = m_clip->clipType();
148 if (t != AUDIO && t != AV) {
149 m_view.clip_force_aindex->setEnabled(false);
152 if (t != VIDEO && t != AV) {
153 m_view.clip_force_vindex->setEnabled(false);
157 m_view.tabWidget->removeTab(SLIDETAB);
158 m_view.tabWidget->removeTab(COLORTAB);
159 m_view.tabWidget->removeTab(AUDIOTAB);
160 m_view.tabWidget->removeTab(VIDEOTAB);
161 if (props.contains("frame_size"))
162 m_view.image_size->setText(props.value("frame_size"));
163 if (props.contains("transparency"))
164 m_view.image_transparency->setChecked(props.value("transparency").toInt());
165 connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
166 int width = 180.0 * KdenliveSettings::project_display_ratio();
167 if (width % 2 == 1) width++;
168 m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
169 } else if (t == COLOR) {
170 m_view.clip_path->setEnabled(false);
171 m_view.tabWidget->removeTab(METATAB);
172 m_view.tabWidget->removeTab(IMAGETAB);
173 m_view.tabWidget->removeTab(SLIDETAB);
174 m_view.tabWidget->removeTab(AUDIOTAB);
175 m_view.tabWidget->removeTab(VIDEOTAB);
176 m_view.clip_thumb->setHidden(true);
177 m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
178 connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
179 } else if (t == SLIDESHOW) {
181 if (url.fileName().startsWith(".all.")) {
182 // the image sequence is defined by mimetype
183 m_view.clip_path->setText(url.directory());
185 // the image sequence is defined by pattern
186 m_view.slide_type_label->setHidden(true);
187 m_view.image_type->setHidden(true);
188 m_view.clip_path->setText(url.path());
192 m_view.tabWidget->removeTab(METATAB);
193 m_view.tabWidget->removeTab(IMAGETAB);
194 m_view.tabWidget->removeTab(COLORTAB);
195 m_view.tabWidget->removeTab(AUDIOTAB);
196 m_view.tabWidget->removeTab(VIDEOTAB);
198 //WARNING: Keep in sync with slideshowclip.cpp
199 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
200 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
201 m_view.image_type->addItem("PNG (*.png)", "png");
202 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
203 m_view.image_type->addItem("GIF (*.gif)", "gif");
204 m_view.image_type->addItem("TGA (*.tga)", "tga");
205 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
206 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
207 m_view.animation->addItem(i18n("None"), QString());
208 m_view.animation->addItem(i18n("Pan"), "Pan");
209 m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
210 m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
211 m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
212 m_view.animation->addItem(i18n("Zoom"), "Zoom");
213 m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
215 m_view.slide_loop->setChecked(props.value("loop").toInt());
216 m_view.slide_crop->setChecked(props.value("crop").toInt());
217 m_view.slide_fade->setChecked(props.value("fade").toInt());
218 m_view.luma_softness->setValue(props.value("softness").toInt());
219 if (!props.value("animation").isEmpty())
220 m_view.animation->setCurrentItem(props.value("animation"));
222 m_view.animation->setCurrentIndex(0);
223 QString path = props.value("resource");
224 QString ext = path.section('.', -1);
225 for (int i = 0; i < m_view.image_type->count(); i++) {
226 if (m_view.image_type->itemData(i).toString() == ext) {
227 m_view.image_type->setCurrentIndex(i);
231 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
233 m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
234 m_view.slide_duration_format->addItem(i18n("Frames"));
235 connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
236 m_view.slide_duration_frames->setHidden(true);
237 m_view.luma_duration_frames->setHidden(true);
241 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
242 QString lumaFile = props.value("luma_file");
244 // Check for Kdenlive installed luma files
246 filters << "*.pgm" << "*.png";
248 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
249 foreach(const QString & folder, customLumas) {
250 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
251 foreach(const QString & fname, filesnames) {
252 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
253 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
257 // Check for MLT lumas
258 QString profilePath = KdenliveSettings::mltpath();
259 QString folder = profilePath.section('/', 0, -3);
260 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
261 QDir lumafolder(folder);
262 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
263 foreach(const QString & fname, filesnames) {
264 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
265 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
268 if (!lumaFile.isEmpty()) {
269 m_view.slide_luma->setChecked(true);
270 m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
271 } else m_view.luma_file->setEnabled(false);
272 slotEnableLuma(m_view.slide_fade->checkState());
273 slotEnableLumaFile(m_view.slide_luma->checkState());
275 connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
276 connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
277 connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
278 connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
279 connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
280 connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
281 connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
282 connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
283 connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
284 connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
287 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
288 connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
289 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
291 } else if (t != AUDIO) {
292 m_view.tabWidget->removeTab(IMAGETAB);
293 m_view.tabWidget->removeTab(SLIDETAB);
294 m_view.tabWidget->removeTab(COLORTAB);
298 m_propsDelegate = new PropertiesViewDelegate(this);
299 m_view.clip_vproperties->setItemDelegate(m_propsDelegate);
300 m_view.clip_aproperties->setItemDelegate(m_propsDelegate);
301 m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
302 m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
304 if (props.contains("videocodec"))
305 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
307 if (props.contains("frame_size"))
308 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
310 if (props.contains("fps")) {
311 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
312 if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
314 if (props.contains("aspect_ratio"))
315 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
317 if (props.contains("pix_fmt"))
318 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
320 if (props.contains("colorspace"))
321 new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
323 int width = 180.0 * KdenliveSettings::project_display_ratio();
324 if (width % 2 == 1) width++;
325 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
326 m_view.clip_thumb->setPixmap(pix);
327 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
329 m_view.tabWidget->removeTab(IMAGETAB);
330 m_view.tabWidget->removeTab(SLIDETAB);
331 m_view.tabWidget->removeTab(COLORTAB);
332 m_view.tabWidget->removeTab(VIDEOTAB);
333 m_view.clip_thumb->setHidden(true);
336 if (t != SLIDESHOW && t != COLOR) {
337 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
338 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
340 m_view.clip_filesize->setHidden(true);
341 m_view.label_size->setHidden(true);
343 m_view.clip_duration->setInputMask("");
344 m_view.clip_duration->setValidator(tc.validator());
345 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
346 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
347 else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
350 m_view.marker_new->setIcon(KIcon("document-new"));
351 m_view.marker_new->setToolTip(i18n("Add marker"));
352 m_view.marker_edit->setIcon(KIcon("document-properties"));
353 m_view.marker_edit->setToolTip(i18n("Edit marker"));
354 m_view.marker_delete->setIcon(KIcon("trash-empty"));
355 m_view.marker_delete->setToolTip(i18n("Delete marker"));
357 slotFillMarkersList();
358 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
359 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
360 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
361 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
363 connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
364 connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
365 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
370 // Used for multiple clips editing
371 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
377 m_clipNeedsRefresh(false),
378 m_clipNeedsReLoad(false)
380 setFont(KGlobalSettings::toolBarFont());
381 m_view.setupUi(this);
382 QMap <QString, QString> props = cliplist.at(0)->properties();
383 m_old_props = commonproperties;
385 if (commonproperties.contains("force_aspect_ratio") && !commonproperties.value("force_aspect_ratio").isEmpty() && commonproperties.value("force_aspect_ratio").toDouble() > 0) {
386 m_view.clip_force_ar->setChecked(true);
387 m_view.clip_ar->setEnabled(true);
388 m_view.clip_ar->setValue(commonproperties.value("force_aspect_ratio").toDouble());
391 if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
392 m_view.clip_force_framerate->setChecked(true);
393 m_view.clip_framerate->setEnabled(true);
394 m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
397 if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
398 m_view.clip_force_progressive->setChecked(true);
399 m_view.clip_progressive->setEnabled(true);
400 m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
403 if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
404 m_view.clip_force_threads->setChecked(true);
405 m_view.clip_threads->setEnabled(true);
406 m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
409 if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
410 m_view.clip_force_vindex->setChecked(true);
411 m_view.clip_vindex->setEnabled(true);
412 m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
415 if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
416 m_view.clip_force_aindex->setChecked(true);
417 m_view.clip_aindex->setEnabled(true);
418 m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
421 if (props.contains("audio_max")) {
422 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
425 if (props.contains("video_max")) {
426 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
429 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
430 connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
431 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
432 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
433 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
434 connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
436 m_view.tabWidget->removeTab(METATAB);
437 m_view.tabWidget->removeTab(MARKERTAB);
438 m_view.tabWidget->removeTab(IMAGETAB);
439 m_view.tabWidget->removeTab(SLIDETAB);
440 m_view.tabWidget->removeTab(COLORTAB);
441 m_view.tabWidget->removeTab(AUDIOTAB);
442 m_view.tabWidget->removeTab(VIDEOTAB);
444 m_view.clip_path->setHidden(true);
445 m_view.label_path->setHidden(true);
446 m_view.label_description->setHidden(true);
447 m_view.label_size->setHidden(true);
448 m_view.clip_filesize->setHidden(true);
449 m_view.clip_filesize->setHidden(true);
450 m_view.clip_path->setHidden(true);
451 m_view.clip_description->setHidden(true);
452 m_view.clip_thumb->setHidden(true);
453 m_view.label_duration->setHidden(true);
454 m_view.clip_duration->setHidden(true);
456 if (commonproperties.contains("out")) {
457 if (commonproperties.value("out").toInt() > 0) {
458 m_view.clip_force_out->setChecked(true);
459 m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
460 } else m_view.clip_out->setText(KdenliveSettings::image_duration());
462 m_view.clip_force_out->setHidden(true);
463 m_view.clip_out->setHidden(true);
467 ClipProperties::~ClipProperties()
469 if (m_propsDelegate) delete m_propsDelegate;
472 void ClipProperties::slotApplyProperties()
475 emit applyNewClipProperties(m_clip->getId(), m_clip->properties(), properties(), needsTimelineRefresh(), needsTimelineReload());
476 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
479 void ClipProperties::disableClipId(const QString &id)
481 if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
482 if (m_clip->getId() == id) {
483 // clip was removed from project, close this properties dialog
489 void ClipProperties::slotModified()
491 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
495 void ClipProperties::slotEnableLuma(int state)
498 if (state == Qt::Checked) enable = true;
499 m_view.luma_duration->setEnabled(enable);
500 m_view.luma_duration_frames->setEnabled(enable);
501 m_view.slide_luma->setEnabled(enable);
503 m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
504 } else m_view.luma_file->setEnabled(false);
505 m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
506 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
509 void ClipProperties::slotEnableLumaFile(int state)
512 if (state == Qt::Checked) enable = true;
513 m_view.luma_file->setEnabled(enable);
514 m_view.luma_softness->setEnabled(enable);
515 m_view.label_softness->setEnabled(enable);
518 void ClipProperties::slotFillMarkersList()
520 m_view.markers_list->clear();
521 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
522 for (int count = 0; count < marks.count(); ++count) {
523 QString time = m_tc.getTimecode(marks[count].time());
524 QStringList itemtext;
525 itemtext << time << marks[count].comment();
526 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
530 void ClipProperties::slotAddMarker()
532 CommentedTime marker(GenTime(), i18n("Marker"));
533 MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
534 if (d.exec() == QDialog::Accepted) {
535 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
537 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
540 void ClipProperties::slotEditMarker()
542 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
543 int pos = m_view.markers_list->currentIndex().row();
544 if (pos < 0 || pos > marks.count() - 1) return;
545 MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
546 if (d.exec() == QDialog::Accepted) {
547 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
549 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
552 void ClipProperties::slotDeleteMarker()
554 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
555 int pos = m_view.markers_list->currentIndex().row();
556 if (pos < 0 || pos > marks.count() - 1) return;
557 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
559 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
562 const QString &ClipProperties::clipId() const
564 return m_clip->getId();
568 QMap <QString, QString> ClipProperties::properties()
570 QMap <QString, QString> props;
571 CLIPTYPE t = UNKNOWN;
572 if (m_clip != NULL) {
573 t = m_clip->clipType();
574 m_old_props = m_clip->properties();
577 double aspect = m_view.clip_ar->value();
578 if (m_view.clip_force_ar->isChecked()) {
579 if (aspect != m_old_props.value("force_aspect_ratio").toDouble()) {
580 props["force_aspect_ratio"] = QString::number(aspect);
581 m_clipNeedsRefresh = true;
583 } else if (m_old_props.contains("force_aspect_ratio")) {
584 props["force_aspect_ratio"].clear();
585 m_clipNeedsRefresh = true;
588 double fps = m_view.clip_framerate->value();
589 if (m_view.clip_force_framerate->isChecked()) {
590 if (fps != m_old_props.value("force_fps").toDouble()) {
591 props["force_fps"] = QString::number(fps);
592 m_clipNeedsRefresh = true;
594 } else if (m_old_props.contains("force_fps")) {
595 props["force_fps"].clear();
596 m_clipNeedsRefresh = true;
599 int progressive = m_view.clip_progressive->value();
600 if (m_view.clip_force_progressive->isChecked()) {
601 if (progressive != m_old_props.value("force_progressive").toInt()) {
602 props["force_progressive"] = QString::number(progressive);
604 } else if (m_old_props.contains("force_progressive")) {
605 props["force_progressive"].clear();
608 int threads = m_view.clip_threads->value();
609 if (m_view.clip_force_threads->isChecked()) {
610 if (threads != m_old_props.value("threads").toInt()) {
611 props["threads"] = QString::number(threads);
613 } else if (m_old_props.contains("threads")) {
614 props["threads"].clear();
617 int vindex = m_view.clip_vindex->value();
618 if (m_view.clip_force_vindex->isChecked()) {
619 if (vindex != m_old_props.value("video_index").toInt()) {
620 props["video_index"] = QString::number(vindex);
622 } else if (m_old_props.contains("video_index")) {
623 props["video_index"].clear();
626 int aindex = m_view.clip_aindex->value();
627 if (m_view.clip_force_aindex->isChecked()) {
628 if (aindex != m_old_props.value("audio_index").toInt()) {
629 props["audio_index"] = QString::number(aindex);
631 } else if (m_old_props.contains("audio_index")) {
632 props["audio_index"].clear();
635 // If we adjust several clips, return now
636 if (m_clip == NULL) {
637 if (m_view.clip_out->isEnabled()) {
638 int duration = m_tc.getFrameCount(m_view.clip_out->text());
639 if (duration != m_old_props.value("out").toInt()) {
640 props["out"] = QString::number(duration - 1);
646 if (m_old_props.value("description") != m_view.clip_description->text())
647 props["description"] = m_view.clip_description->text();
650 QString new_color = m_view.clip_color->color().name();
651 if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
652 m_clipNeedsRefresh = true;
653 props["colour"] = "0x" + new_color.right(6) + "ff";
655 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
656 if (duration != m_clip->duration().frames(m_fps)) {
657 props["out"] = QString::number(duration - 1);
659 } else if (t == IMAGE) {
660 if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
661 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
662 //m_clipNeedsRefresh = true;
664 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
665 if (duration != m_clip->duration().frames(m_fps)) {
666 props["out"] = QString::number(duration - 1);
668 } else if (t == SLIDESHOW) {
669 QString value = QString::number((int) m_view.slide_loop->isChecked());
670 if (m_old_props.value("loop") != value) props["loop"] = value;
671 value = QString::number((int) m_view.slide_crop->isChecked());
672 if (m_old_props.value("crop") != value) props["crop"] = value;
673 value = QString::number((int) m_view.slide_fade->isChecked());
674 if (m_old_props.value("fade") != value) props["fade"] = value;
675 value = QString::number((int) m_view.luma_softness->value());
676 if (m_old_props.value("softness") != value) props["softness"] = value;
678 bool isMime = !(m_view.clip_path->text().contains('%'));
680 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
681 QString new_path = m_view.clip_path->text() + extension;
682 if (new_path != m_old_props.value("resource")) {
683 m_clipNeedsReLoad = true;
684 props["resource"] = new_path;
685 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
689 if (m_view.slide_duration_format->currentIndex() == 1) {
690 // we are in frames mode
691 duration = m_view.slide_duration_frames->value();
692 } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
693 if (duration != m_old_props.value("ttl").toInt()) {
694 m_clipNeedsRefresh = true;
695 props["ttl"] = QString::number(duration);
696 props["out"] = QString::number(duration * m_count - 1);
699 if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
700 m_clipNeedsRefresh = true;
701 props["out"] = QString::number(duration * m_count - 1);
703 if (m_view.slide_fade->isChecked()) {
705 if (m_view.slide_duration_format->currentIndex() == 1) {
706 // we are in frames mode
707 luma_duration = m_view.luma_duration_frames->value();
708 } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
709 if (luma_duration != m_old_props.value("luma_duration").toInt()) {
710 m_clipNeedsRefresh = true;
711 props["luma_duration"] = QString::number(luma_duration);
714 if (m_view.slide_luma->isChecked())
715 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
716 if (lumaFile != m_old_props.value("luma_file")) {
717 m_clipNeedsRefresh = true;
718 props["luma_file"] = lumaFile;
721 if (!m_old_props.value("luma_file").isEmpty()) {
722 props["luma_file"].clear();
726 QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
727 if (animation != m_old_props.value("animation")) {
728 if (animation.isEmpty()) {
729 props["animation"].clear();
731 props["animation"] = animation;
733 m_clipNeedsRefresh = true;
739 bool ClipProperties::needsTimelineRefresh() const
741 return m_clipNeedsRefresh;
744 bool ClipProperties::needsTimelineReload() const
746 return m_clipNeedsReLoad;
750 void ClipProperties::parseFolder()
752 QString path = m_view.clip_path->text();
753 bool isMime = !(path.contains('%'));
754 if (!isMime) path = KUrl(path).directory();
761 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
762 filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
763 extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
764 dir.setNameFilters(filters);
767 QStringList result = dir.entryList(QDir::Files);
771 QString filter = KUrl(m_view.clip_path->text()).fileName();
772 QString ext = filter.section('.', -1);
773 filter = filter.section('%', 0, -2);
774 QString regexp = "^" + filter + "\\d+\\." + ext + "$";
777 foreach(const QString & path, result) {
778 if (rx.exactMatch(path)) entries << path;
783 m_count = result.count();
784 m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
786 // no images, do not accept that
787 m_view.slide_info->setText(i18n("No image found"));
788 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
791 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
792 m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
793 QDomElement xml = m_clip->toXML();
794 xml.setAttribute("resource", m_view.clip_path->text() + extension);
795 int width = 180.0 * KdenliveSettings::project_display_ratio();
796 if (width % 2 == 1) width++;
797 QString filePath = m_view.clip_path->text();
798 if (isMime) filePath.append(extension);
799 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
800 QMap <QString, QString> props = m_clip->properties();
801 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
802 m_view.clip_thumb->setPixmap(pix);
805 void ClipProperties::slotCheckMaxLength()
807 if (m_clip->maxDuration() == GenTime()) return;
808 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
809 if (duration > m_clip->maxDuration().frames(m_fps)) {
810 m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
814 void ClipProperties::slotUpdateDurationFormat(int ix)
816 bool framesFormat = ix == 1;
818 // switching to frames count, update widget
819 m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
820 m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
821 m_view.slide_duration->setHidden(true);
822 m_view.luma_duration->setHidden(true);
823 m_view.slide_duration_frames->setHidden(false);
824 m_view.luma_duration_frames->setHidden(false);
826 // switching to timecode format
827 m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
828 m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
829 m_view.slide_duration_frames->setHidden(true);
830 m_view.luma_duration_frames->setHidden(true);
831 m_view.slide_duration->setHidden(false);
832 m_view.luma_duration->setHidden(false);
836 #include "clipproperties.moc"