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 ***************************************************************************/
22 #include <KStandardDirs>
26 #include "kdenlivesettings.h"
27 #include "clipproperties.h"
29 #include "markerdialog.h"
31 static const int VIDEOTAB = 0;
32 static const int AUDIOTAB = 1;
33 static const int COLORTAB = 2;
34 static const int SLIDETAB = 3;
35 static const int IMAGETAB = 4;
36 static const int MARKERTAB = 5;
37 static const int ADVANCEDTAB = 6;
39 static const int TYPE_JPEG = 0;
40 static const int TYPE_PNG = 1;
41 static const int TYPE_BMP = 2;
42 static const int TYPE_GIF = 3;
44 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip), m_fps(fps), m_clipNeedsRefresh(false), m_count(0) {
45 setFont(KGlobalSettings::toolBarFont());
47 KUrl url = m_clip->fileURL();
48 m_view.clip_path->setText(url.path());
49 m_view.clip_description->setText(m_clip->description());
50 QMap <QString, QString> props = m_clip->properties();
52 if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
53 m_view.clip_force_ar->setChecked(true);
54 m_view.clip_ar->setEnabled(true);
55 m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
58 if (props.contains("threads") && props.value("threads").toInt() != 1) {
59 m_view.clip_force_threads->setChecked(true);
60 m_view.clip_threads->setEnabled(true);
61 m_view.clip_threads->setValue(props.value("threads").toInt());
64 if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
65 m_view.clip_force_vindex->setChecked(true);
66 m_view.clip_vindex->setEnabled(true);
67 m_view.clip_vindex->setValue(props.value("video_index").toInt());
70 if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
71 m_view.clip_force_aindex->setChecked(true);
72 m_view.clip_aindex->setEnabled(true);
73 m_view.clip_aindex->setValue(props.value("audio_index").toInt());
76 connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
77 connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
78 connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
79 connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
81 if (props.contains("audiocodec"))
82 m_view.clip_acodec->setText(props.value("audiocodec"));
83 if (props.contains("frequency"))
84 m_view.clip_frequency->setText(props.value("frequency"));
85 if (props.contains("channels"))
86 m_view.clip_channels->setText(props.value("channels"));
88 CLIPTYPE t = m_clip->clipType();
90 m_view.tabWidget->removeTab(SLIDETAB);
91 m_view.tabWidget->removeTab(COLORTAB);
92 m_view.tabWidget->removeTab(AUDIOTAB);
93 m_view.tabWidget->removeTab(VIDEOTAB);
94 if (props.contains("frame_size"))
95 m_view.image_size->setText(props.value("frame_size"));
96 if (props.contains("transparency"))
97 m_view.image_transparency->setChecked(props.value("transparency").toInt());
98 } else if (t == COLOR) {
99 m_view.clip_path->setEnabled(false);
100 m_view.tabWidget->removeTab(IMAGETAB);
101 m_view.tabWidget->removeTab(SLIDETAB);
102 m_view.tabWidget->removeTab(AUDIOTAB);
103 m_view.tabWidget->removeTab(VIDEOTAB);
104 m_view.clip_thumb->setHidden(true);
105 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
106 } else if (t == SLIDESHOW) {
107 m_view.clip_path->setText(url.directory());
108 m_view.tabWidget->removeTab(IMAGETAB);
109 m_view.tabWidget->removeTab(COLORTAB);
110 m_view.tabWidget->removeTab(AUDIOTAB);
111 m_view.tabWidget->removeTab(VIDEOTAB);
113 types << "JPG" << "PNG" << "BMP" << "GIF";
114 m_view.image_type->addItems(types);
115 m_view.slide_loop->setChecked(props.value("loop").toInt());
116 m_view.slide_fade->setChecked(props.value("fade").toInt());
117 m_view.luma_softness->setValue(props.value("softness").toInt());
118 QString path = props.value("resource");
119 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
120 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
121 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
122 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
125 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
126 QString lumaFile = props.value("luma_file");
127 QString profilePath = KdenliveSettings::mltpath();
128 profilePath = profilePath.section('/', 0, -3);
129 profilePath += "/lumas/PAL/";
131 QDir dir(profilePath);
134 const QStringList result = dir.entryList(filter, QDir::Files);
135 QStringList imagefiles;
136 QStringList imagenamelist;
138 foreach(const QString file, result) {
139 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
140 if (!lumaFile.isEmpty() && lumaFile == QString(profilePath + file))
141 current = m_view.luma_file->count() - 1;
144 if (!lumaFile.isEmpty()) {
145 m_view.slide_luma->setChecked(true);
146 m_view.luma_file->setCurrentIndex(current);
149 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
150 } else if (t != AUDIO) {
151 m_view.tabWidget->removeTab(IMAGETAB);
152 m_view.tabWidget->removeTab(SLIDETAB);
153 m_view.tabWidget->removeTab(COLORTAB);
154 if (props.contains("frame_size"))
155 m_view.clip_size->setText(props.value("frame_size"));
156 if (props.contains("videocodec"))
157 m_view.clip_vcodec->setText(props.value("videocodec"));
158 if (props.contains("fps"))
159 m_view.clip_fps->setText(props.value("fps"));
160 if (props.contains("aspect_ratio"))
161 m_view.clip_ratio->setText(props.value("aspect_ratio"));
163 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), 240, 180);
164 m_view.clip_thumb->setPixmap(pix);
165 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
167 m_view.tabWidget->removeTab(IMAGETAB);
168 m_view.tabWidget->removeTab(SLIDETAB);
169 m_view.tabWidget->removeTab(COLORTAB);
170 m_view.tabWidget->removeTab(VIDEOTAB);
171 m_view.clip_thumb->setHidden(true);
173 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
175 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
176 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
177 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
180 m_view.marker_new->setIcon(KIcon("document-new"));
181 m_view.marker_new->setToolTip(i18n("Add marker"));
182 m_view.marker_edit->setIcon(KIcon("document-properties"));
183 m_view.marker_edit->setToolTip(i18n("Edit marker"));
184 m_view.marker_delete->setIcon(KIcon("trash-empty"));
185 m_view.marker_delete->setToolTip(i18n("Delete marker"));
187 slotFillMarkersList();
188 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
189 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
190 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
191 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
196 void ClipProperties::slotFillMarkersList() {
197 m_view.markers_list->clear();
198 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
199 for (uint count = 0; count < marks.count(); ++count) {
200 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
201 QStringList itemtext;
202 itemtext << time << marks[count].comment();
203 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
207 void ClipProperties::slotAddMarker() {
208 CommentedTime marker(GenTime(), i18n("Marker"));
209 MarkerDialog d(m_clip, marker, m_tc, this);
210 if (d.exec() == QDialog::Accepted) {
211 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
213 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
216 void ClipProperties::slotEditMarker() {
217 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
218 int pos = m_view.markers_list->currentIndex().row();
219 if (pos < 0 || pos > marks.count() - 1) return;
220 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
221 if (d.exec() == QDialog::Accepted) {
222 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
224 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
227 void ClipProperties::slotDeleteMarker() {
228 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
229 int pos = m_view.markers_list->currentIndex().row();
230 if (pos < 0 || pos > marks.count() - 1) return;
231 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
233 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
236 const QString &ClipProperties::clipId() const {
237 return m_clip->getId();
241 QMap <QString, QString> ClipProperties::properties() {
242 QMap <QString, QString> props;
243 props["description"] = m_view.clip_description->text();
244 CLIPTYPE t = m_clip->clipType();
245 QMap <QString, QString> old_props = m_clip->properties();
246 double aspect = m_view.clip_ar->value();
247 if (m_view.clip_force_ar->isChecked()) {
248 if (aspect != old_props.value("force_aspect_ratio").toDouble()) {
249 props["force_aspect_ratio"] = QString::number(aspect);
250 m_clipNeedsRefresh = true;
252 } else if (old_props.contains("force_aspect_ratio")) {
253 props["force_aspect_ratio"] = QString();
254 m_clipNeedsRefresh = true;
257 int threads = m_view.clip_threads->value();
258 if (m_view.clip_force_threads->isChecked()) {
259 if (threads != old_props.value("threads").toInt()) {
260 props["threads"] = QString::number(threads);
262 } else if (old_props.contains("threads")) {
263 props["threads"] = QString();
266 int vindex = m_view.clip_vindex->value();
267 if (m_view.clip_force_vindex->isChecked()) {
268 if (vindex != old_props.value("video_index").toInt()) {
269 props["video_index"] = QString::number(vindex);
271 } else if (old_props.contains("video_index")) {
272 props["video_index"] = QString();
275 int aindex = m_view.clip_aindex->value();
276 if (m_view.clip_force_aindex->isChecked()) {
277 if (aindex != old_props.value("audio_index").toInt()) {
278 props["audio_index"] = QString::number(aindex);
280 } else if (old_props.contains("audio_index")) {
281 props["audio_index"] = QString();
285 QString new_color = m_view.clip_color->color().name();
286 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
287 m_clipNeedsRefresh = true;
288 props["colour"] = "0x" + new_color.right(6) + "ff";
290 } else if (t == IMAGE) {
291 if ((int) m_view.image_transparency->isChecked() != old_props.value("transparency").toInt()) {
292 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
293 m_clipNeedsRefresh = true;
295 } else if (t == SLIDESHOW) {
296 QString value = QString::number((int) m_view.slide_loop->isChecked());
297 if (old_props.value("loop") != value) props["loop"] = value;
298 value = QString::number((int) m_view.slide_fade->isChecked());
299 if (old_props.value("fade") != value) props["fade"] = value;
300 value = QString::number((int) m_view.luma_softness->value());
301 if (old_props.value("softness") != value) props["softness"] = value;
304 switch (m_view.image_type->currentIndex()) {
306 extension = "/.all.png";
309 extension = "/.all.bmp";
312 extension = "/.all.gif";
315 extension = "/.all.jpg";
318 QString new_path = m_view.clip_path->text() + extension;
319 if (new_path != old_props.value("resource")) {
320 m_clipNeedsRefresh = true;
321 props["resource"] = new_path;
322 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
324 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
325 if (duration != old_props.value("ttl").toInt()) {
326 m_clipNeedsRefresh = true;
327 props["ttl"] = QString::number(duration);
328 props["out"] = QString::number(duration * m_count);
330 if (duration * m_count != old_props.value("out").toInt()) {
331 m_clipNeedsRefresh = true;
332 props["out"] = QString::number(duration * m_count);
334 if (m_view.slide_fade->isChecked()) {
335 int luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
336 if (luma_duration != old_props.value("luma_duration").toInt()) {
337 m_clipNeedsRefresh = true;
338 props["luma_duration"] = QString::number(luma_duration);
341 if (m_view.slide_luma->isChecked())
342 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
343 if (lumaFile != old_props.value("luma_file")) {
344 m_clipNeedsRefresh = true;
345 props["luma_file"] = lumaFile;
348 if (old_props.value("luma_file") != QString()) {
349 props["luma_file"] = QString();
357 bool ClipProperties::needsTimelineRefresh() const {
358 return m_clipNeedsRefresh;
361 void ClipProperties::parseFolder() {
363 QDir dir(m_view.clip_path->text());
366 switch (m_view.image_type->currentIndex()) {
369 extension = "/.all.png";
373 extension = "/.all.bmp";
377 extension = "/.all.gif";
381 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
383 extension = "/.all.jpg";
387 dir.setNameFilters(filters);
388 QStringList result = dir.entryList(QDir::Files);
389 m_count = result.count();
390 m_view.slide_info->setText(i18n("%1 images found", m_count));
391 QDomElement xml = m_clip->toXML();
392 xml.setAttribute("resource", m_view.clip_path->text() + extension);
393 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, 240, 180);
394 QMap <QString, QString> props = m_clip->properties();
395 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
396 m_view.clip_thumb->setPixmap(pix);
399 #include "clipproperties.moc"