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"
26 #include <KStandardDirs>
32 static const int VIDEOTAB = 0;
33 static const int AUDIOTAB = 1;
34 static const int COLORTAB = 2;
35 static const int SLIDETAB = 3;
36 static const int IMAGETAB = 4;
37 static const int MARKERTAB = 5;
38 static const int METATAB = 6;
39 static const int ADVANCEDTAB = 7;
41 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
47 m_clipNeedsRefresh(false),
48 m_clipNeedsReLoad(false)
50 setFont(KGlobalSettings::toolBarFont());
52 KUrl url = m_clip->fileURL();
53 m_view.clip_path->setText(url.path());
54 m_view.clip_description->setText(m_clip->description());
55 QMap <QString, QString> props = m_clip->properties();
57 if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
58 m_view.clip_force_ar->setChecked(true);
59 m_view.clip_ar->setEnabled(true);
60 m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
63 if (props.contains("threads") && props.value("threads").toInt() != 1) {
64 m_view.clip_force_threads->setChecked(true);
65 m_view.clip_threads->setEnabled(true);
66 m_view.clip_threads->setValue(props.value("threads").toInt());
69 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
70 m_view.clip_force_vindex->setChecked(true);
71 m_view.clip_vindex->setEnabled(true);
72 m_view.clip_vindex->setValue(props.value("video_index").toInt());
75 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
76 m_view.clip_force_aindex->setChecked(true);
77 m_view.clip_aindex->setEnabled(true);
78 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
81 if (props.contains("audio_max")) {
82 m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
85 if (props.contains("video_max")) {
86 m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
90 QMap<QString, QString> meta = m_clip->metadata();
91 QMap<QString, QString>::const_iterator i = meta.constBegin();
92 while (i != meta.constEnd()) {
93 QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
94 metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
95 metaitem->setText(1, i.value());
99 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
100 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
101 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
102 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
104 if (props.contains("audiocodec"))
105 m_view.clip_acodec->setText(props.value("audiocodec"));
106 if (props.contains("frequency"))
107 m_view.clip_frequency->setText(props.value("frequency"));
108 if (props.contains("channels"))
109 m_view.clip_channels->setText(props.value("channels"));
111 CLIPTYPE t = m_clip->clipType();
112 if (t != AUDIO && t != AV) {
113 m_view.clip_force_aindex->setEnabled(false);
116 if (t != VIDEO && t != AV) {
117 m_view.clip_force_vindex->setEnabled(false);
121 m_view.tabWidget->removeTab(SLIDETAB);
122 m_view.tabWidget->removeTab(COLORTAB);
123 m_view.tabWidget->removeTab(AUDIOTAB);
124 m_view.tabWidget->removeTab(VIDEOTAB);
125 if (props.contains("frame_size"))
126 m_view.image_size->setText(props.value("frame_size"));
127 if (props.contains("transparency"))
128 m_view.image_transparency->setChecked(props.value("transparency").toInt());
129 int width = 180.0 * KdenliveSettings::project_display_ratio();
130 if (width % 2 == 1) width++;
131 m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
132 } else if (t == COLOR) {
133 m_view.clip_path->setEnabled(false);
134 m_view.tabWidget->removeTab(METATAB);
135 m_view.tabWidget->removeTab(IMAGETAB);
136 m_view.tabWidget->removeTab(SLIDETAB);
137 m_view.tabWidget->removeTab(AUDIOTAB);
138 m_view.tabWidget->removeTab(VIDEOTAB);
139 m_view.clip_thumb->setHidden(true);
140 m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
141 } else if (t == SLIDESHOW) {
142 m_view.clip_path->setText(url.directory());
143 m_view.tabWidget->removeTab(METATAB);
144 m_view.tabWidget->removeTab(IMAGETAB);
145 m_view.tabWidget->removeTab(COLORTAB);
146 m_view.tabWidget->removeTab(AUDIOTAB);
147 m_view.tabWidget->removeTab(VIDEOTAB);
149 //WARNING: Keep in sync with slideshowclip.cpp
150 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
151 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
152 m_view.image_type->addItem("PNG (*.png)", "png");
153 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
154 m_view.image_type->addItem("GIF (*.gif)", "gif");
155 m_view.image_type->addItem("TGA (*.tga)", "tga");
156 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
157 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
159 m_view.slide_loop->setChecked(props.value("loop").toInt());
160 m_view.slide_fade->setChecked(props.value("fade").toInt());
161 m_view.luma_softness->setValue(props.value("softness").toInt());
162 QString path = props.value("resource");
163 QString ext = path.section('.', -1);
164 for (int i = 0; i < m_view.image_type->count(); i++) {
165 if (m_view.image_type->itemData(i).toString() == ext) {
166 m_view.image_type->setCurrentIndex(i);
170 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
172 m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
173 m_view.slide_duration_format->addItem(i18n("Frames"));
174 connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
175 m_view.slide_duration_frames->setHidden(true);
176 m_view.luma_duration_frames->setHidden(true);
180 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
181 QString lumaFile = props.value("luma_file");
183 // Check for Kdenlive installed luma files
185 filters << "*.pgm" << "*.png";
187 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
188 foreach(const QString &folder, customLumas) {
189 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
190 foreach(const QString &fname, filesnames) {
191 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
192 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
196 // Check for MLT lumas
197 QString profilePath = KdenliveSettings::mltpath();
198 QString folder = profilePath.section('/', 0, -3);
199 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
200 QDir lumafolder(folder);
201 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
202 foreach(const QString &fname, filesnames) {
203 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
204 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
207 if (!lumaFile.isEmpty()) {
208 m_view.slide_luma->setChecked(true);
209 m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
210 } else m_view.luma_file->setEnabled(false);
211 slotEnableLuma(m_view.slide_fade->checkState());
212 slotEnableLumaFile(m_view.slide_luma->checkState());
213 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
214 connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
216 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
217 } else if (t != AUDIO) {
218 m_view.tabWidget->removeTab(IMAGETAB);
219 m_view.tabWidget->removeTab(SLIDETAB);
220 m_view.tabWidget->removeTab(COLORTAB);
221 if (props.contains("frame_size"))
222 m_view.clip_size->setText(props.value("frame_size"));
223 if (props.contains("videocodec"))
224 m_view.clip_vcodec->setText(props.value("videocodec"));
225 if (props.contains("fps"))
226 m_view.clip_fps->setText(props.value("fps"));
227 if (props.contains("aspect_ratio"))
228 m_view.clip_ratio->setText(props.value("aspect_ratio"));
229 int width = 180.0 * KdenliveSettings::project_display_ratio();
230 if (width % 2 == 1) width++;
231 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
232 m_view.clip_thumb->setPixmap(pix);
233 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
235 m_view.tabWidget->removeTab(IMAGETAB);
236 m_view.tabWidget->removeTab(SLIDETAB);
237 m_view.tabWidget->removeTab(COLORTAB);
238 m_view.tabWidget->removeTab(VIDEOTAB);
239 m_view.clip_thumb->setHidden(true);
242 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
243 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
244 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
245 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
246 else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
249 m_view.marker_new->setIcon(KIcon("document-new"));
250 m_view.marker_new->setToolTip(i18n("Add marker"));
251 m_view.marker_edit->setIcon(KIcon("document-properties"));
252 m_view.marker_edit->setToolTip(i18n("Edit marker"));
253 m_view.marker_delete->setIcon(KIcon("trash-empty"));
254 m_view.marker_delete->setToolTip(i18n("Delete marker"));
256 slotFillMarkersList();
257 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
258 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
259 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
260 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
265 void ClipProperties::slotEnableLuma(int state)
268 if (state == Qt::Checked) enable = true;
269 m_view.luma_duration->setEnabled(enable);
270 m_view.luma_duration_frames->setEnabled(enable);
271 m_view.slide_luma->setEnabled(enable);
273 m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
274 } else m_view.luma_file->setEnabled(false);
275 m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
276 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
279 void ClipProperties::slotEnableLumaFile(int state)
282 if (state == Qt::Checked) enable = true;
283 m_view.luma_file->setEnabled(enable);
284 m_view.luma_softness->setEnabled(enable);
285 m_view.label_softness->setEnabled(enable);
288 void ClipProperties::slotFillMarkersList()
290 m_view.markers_list->clear();
291 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
292 for (int count = 0; count < marks.count(); ++count) {
293 QString time = m_tc.getTimecode(marks[count].time());
294 QStringList itemtext;
295 itemtext << time << marks[count].comment();
296 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
300 void ClipProperties::slotAddMarker()
302 CommentedTime marker(GenTime(), i18n("Marker"));
303 MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
304 if (d.exec() == QDialog::Accepted) {
305 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
307 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
310 void ClipProperties::slotEditMarker()
312 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
313 int pos = m_view.markers_list->currentIndex().row();
314 if (pos < 0 || pos > marks.count() - 1) return;
315 MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
316 if (d.exec() == QDialog::Accepted) {
317 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
319 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
322 void ClipProperties::slotDeleteMarker()
324 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
325 int pos = m_view.markers_list->currentIndex().row();
326 if (pos < 0 || pos > marks.count() - 1) return;
327 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
329 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
332 const QString &ClipProperties::clipId() const
334 return m_clip->getId();
338 QMap <QString, QString> ClipProperties::properties()
340 QMap <QString, QString> props;
341 CLIPTYPE t = m_clip->clipType();
342 QMap <QString, QString> old_props = m_clip->properties();
344 if (old_props.value("description") != m_view.clip_description->text())
345 props["description"] = m_view.clip_description->text();
347 double aspect = m_view.clip_ar->value();
348 if (m_view.clip_force_ar->isChecked()) {
349 if (aspect != old_props.value("force_aspect_ratio").toDouble()) {
350 props["force_aspect_ratio"] = QString::number(aspect);
351 m_clipNeedsRefresh = true;
353 } else if (old_props.contains("force_aspect_ratio")) {
354 props["force_aspect_ratio"].clear();
355 m_clipNeedsRefresh = true;
358 int threads = m_view.clip_threads->value();
359 if (m_view.clip_force_threads->isChecked()) {
360 if (threads != old_props.value("threads").toInt()) {
361 props["threads"] = QString::number(threads);
363 } else if (old_props.contains("threads")) {
364 props["threads"].clear();
367 int vindex = m_view.clip_vindex->value();
368 if (m_view.clip_force_vindex->isChecked()) {
369 if (vindex != old_props.value("video_index").toInt()) {
370 props["video_index"] = QString::number(vindex);
372 } else if (old_props.contains("video_index")) {
373 props["video_index"].clear();
376 int aindex = m_view.clip_aindex->value();
377 if (m_view.clip_force_aindex->isChecked()) {
378 if (aindex != old_props.value("audio_index").toInt()) {
379 props["audio_index"] = QString::number(aindex);
381 } else if (old_props.contains("audio_index")) {
382 props["audio_index"].clear();
386 QString new_color = m_view.clip_color->color().name();
387 if (new_color != QString('#' + old_props.value("colour").right(8).left(6))) {
388 m_clipNeedsRefresh = true;
389 props["colour"] = "0x" + new_color.right(6) + "ff";
391 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
392 if (duration != m_clip->duration().frames(m_fps)) {
393 props["out"] = QString::number(duration);
395 } else if (t == IMAGE) {
396 if ((int) m_view.image_transparency->isChecked() != old_props.value("transparency").toInt()) {
397 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
398 //m_clipNeedsRefresh = true;
400 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
401 if (duration != m_clip->duration().frames(m_fps)) {
402 props["out"] = QString::number(duration);
404 } else if (t == SLIDESHOW) {
405 QString value = QString::number((int) m_view.slide_loop->isChecked());
406 if (old_props.value("loop") != value) props["loop"] = value;
407 value = QString::number((int) m_view.slide_fade->isChecked());
408 if (old_props.value("fade") != value) props["fade"] = value;
409 value = QString::number((int) m_view.luma_softness->value());
410 if (old_props.value("softness") != value) props["softness"] = value;
412 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
413 QString new_path = m_view.clip_path->text() + extension;
414 if (new_path != old_props.value("resource")) {
415 m_clipNeedsReLoad = true;
416 props["resource"] = new_path;
417 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
420 if (m_view.slide_duration_format->currentIndex() == 1) {
421 // we are in frames mode
422 duration = m_view.slide_duration_frames->value();
423 } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
424 if (duration != old_props.value("ttl").toInt()) {
425 m_clipNeedsRefresh = true;
426 props["ttl"] = QString::number(duration);
427 props["out"] = QString::number(duration * m_count);
429 if (duration * m_count != old_props.value("out").toInt()) {
430 m_clipNeedsRefresh = true;
431 props["out"] = QString::number(duration * m_count);
433 if (m_view.slide_fade->isChecked()) {
435 if (m_view.slide_duration_format->currentIndex() == 1) {
436 // we are in frames mode
437 luma_duration = m_view.luma_duration_frames->value();
438 } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
439 if (luma_duration != old_props.value("luma_duration").toInt()) {
440 m_clipNeedsRefresh = true;
441 props["luma_duration"] = QString::number(luma_duration);
444 if (m_view.slide_luma->isChecked())
445 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
446 if (lumaFile != old_props.value("luma_file")) {
447 m_clipNeedsRefresh = true;
448 props["luma_file"] = lumaFile;
451 if (!old_props.value("luma_file").isEmpty()) {
452 props["luma_file"].clear();
460 bool ClipProperties::needsTimelineRefresh() const
462 return m_clipNeedsRefresh;
465 bool ClipProperties::needsTimelineReload() const
467 return m_clipNeedsReLoad;
470 void ClipProperties::parseFolder()
473 QDir dir(m_view.clip_path->text());
475 filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
476 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
478 dir.setNameFilters(filters);
479 QStringList result = dir.entryList(QDir::Files);
480 m_count = result.count();
482 // no images, do not accept that
483 m_view.slide_info->setText(i18n("No image found"));
484 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
487 m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
488 m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
489 QDomElement xml = m_clip->toXML();
490 xml.setAttribute("resource", m_view.clip_path->text() + extension);
491 int width = 180.0 * KdenliveSettings::project_display_ratio();
492 if (width % 2 == 1) width++;
493 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, width, 180);
494 QMap <QString, QString> props = m_clip->properties();
495 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
496 m_view.clip_thumb->setPixmap(pix);
499 void ClipProperties::slotCheckMaxLength()
501 if (m_clip->maxDuration() == GenTime()) return;
502 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
503 if (duration > m_clip->maxDuration().frames(m_fps)) {
504 m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
508 void ClipProperties::slotUpdateDurationFormat(int ix)
510 bool framesFormat = ix == 1;
512 // switching to frames count, update widget
513 m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
514 m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
515 m_view.slide_duration->setHidden(true);
516 m_view.luma_duration->setHidden(true);
517 m_view.slide_duration_frames->setHidden(false);
518 m_view.luma_duration_frames->setHidden(false);
520 // switching to timecode format
521 m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
522 m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
523 m_view.slide_duration_frames->setHidden(true);
524 m_view.luma_duration_frames->setHidden(true);
525 m_view.slide_duration->setHidden(false);
526 m_view.luma_duration->setHidden(false);
530 #include "clipproperties.moc"