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();
51 // disable advanced properties until implemented
52 //m_view.tabWidget->widget(ADVANCEDTAB)->setEnabled(false);
53 if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
54 m_view.clip_force_ar->setChecked(true);
55 m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
58 if (props.contains("audiocodec"))
59 m_view.clip_acodec->setText(props.value("audiocodec"));
60 if (props.contains("frequency"))
61 m_view.clip_frequency->setText(props.value("frequency"));
62 if (props.contains("channels"))
63 m_view.clip_channels->setText(props.value("channels"));
65 CLIPTYPE t = m_clip->clipType();
67 m_view.tabWidget->removeTab(SLIDETAB);
68 m_view.tabWidget->removeTab(COLORTAB);
69 m_view.tabWidget->removeTab(AUDIOTAB);
70 m_view.tabWidget->removeTab(VIDEOTAB);
71 if (props.contains("frame_size"))
72 m_view.image_size->setText(props.value("frame_size"));
73 if (props.contains("transparency"))
74 m_view.image_transparency->setChecked(props.value("transparency").toInt());
75 } else if (t == COLOR) {
76 m_view.clip_path->setEnabled(false);
77 m_view.tabWidget->removeTab(IMAGETAB);
78 m_view.tabWidget->removeTab(SLIDETAB);
79 m_view.tabWidget->removeTab(AUDIOTAB);
80 m_view.tabWidget->removeTab(VIDEOTAB);
81 m_view.clip_thumb->setHidden(true);
82 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
83 } else if (t == SLIDESHOW) {
84 m_view.clip_path->setText(url.directory());
85 m_view.tabWidget->removeTab(IMAGETAB);
86 m_view.tabWidget->removeTab(COLORTAB);
87 m_view.tabWidget->removeTab(AUDIOTAB);
88 m_view.tabWidget->removeTab(VIDEOTAB);
90 types << "JPG" << "PNG" << "BMP" << "GIF";
91 m_view.image_type->addItems(types);
92 m_view.slide_loop->setChecked(props.value("loop").toInt());
93 m_view.slide_fade->setChecked(props.value("fade").toInt());
94 m_view.luma_softness->setValue(props.value("softness").toInt());
95 QString path = props.value("resource");
96 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
97 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
98 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
99 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
102 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
103 QString lumaFile = props.value("luma_file");
104 QString profilePath = KdenliveSettings::mltpath();
105 profilePath = profilePath.section('/', 0, -3);
106 profilePath += "/lumas/PAL/";
108 QDir dir(profilePath);
111 const QStringList result = dir.entryList(filter, QDir::Files);
112 QStringList imagefiles;
113 QStringList imagenamelist;
115 foreach(const QString file, result) {
116 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
117 if (!lumaFile.isEmpty() && lumaFile == QString(profilePath + file))
118 current = m_view.luma_file->count() - 1;
121 if (!lumaFile.isEmpty()) {
122 m_view.slide_luma->setChecked(true);
123 m_view.luma_file->setCurrentIndex(current);
126 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
127 } else if (t != AUDIO) {
128 m_view.tabWidget->removeTab(IMAGETAB);
129 m_view.tabWidget->removeTab(SLIDETAB);
130 m_view.tabWidget->removeTab(COLORTAB);
131 if (props.contains("frame_size"))
132 m_view.clip_size->setText(props.value("frame_size"));
133 if (props.contains("videocodec"))
134 m_view.clip_vcodec->setText(props.value("videocodec"));
135 if (props.contains("fps"))
136 m_view.clip_fps->setText(props.value("fps"));
137 if (props.contains("aspect_ratio"))
138 m_view.clip_ratio->setText(props.value("aspect_ratio"));
140 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), 240, 180);
141 m_view.clip_thumb->setPixmap(pix);
142 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
144 m_view.tabWidget->removeTab(IMAGETAB);
145 m_view.tabWidget->removeTab(SLIDETAB);
146 m_view.tabWidget->removeTab(COLORTAB);
147 m_view.tabWidget->removeTab(VIDEOTAB);
148 m_view.clip_thumb->setHidden(true);
150 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
152 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
153 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
154 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
157 m_view.marker_new->setIcon(KIcon("document-new"));
158 m_view.marker_new->setToolTip(i18n("Add marker"));
159 m_view.marker_edit->setIcon(KIcon("document-properties"));
160 m_view.marker_edit->setToolTip(i18n("Edit marker"));
161 m_view.marker_delete->setIcon(KIcon("trash-empty"));
162 m_view.marker_delete->setToolTip(i18n("Delete marker"));
164 slotFillMarkersList();
165 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
166 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
167 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
168 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
173 void ClipProperties::slotFillMarkersList() {
174 m_view.markers_list->clear();
175 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
176 for (uint count = 0; count < marks.count(); ++count) {
177 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
178 QStringList itemtext;
179 itemtext << time << marks[count].comment();
180 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
184 void ClipProperties::slotAddMarker() {
185 CommentedTime marker(GenTime(), i18n("Marker"));
186 MarkerDialog d(m_clip, marker, m_tc, this);
187 if (d.exec() == QDialog::Accepted) {
188 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
190 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
193 void ClipProperties::slotEditMarker() {
194 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
195 int pos = m_view.markers_list->currentIndex().row();
196 if (pos < 0 || pos > marks.count() - 1) return;
197 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
198 if (d.exec() == QDialog::Accepted) {
199 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
201 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
204 void ClipProperties::slotDeleteMarker() {
205 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
206 int pos = m_view.markers_list->currentIndex().row();
207 if (pos < 0 || pos > marks.count() - 1) return;
208 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
210 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
213 const QString &ClipProperties::clipId() const {
214 return m_clip->getId();
218 QMap <QString, QString> ClipProperties::properties() {
219 QMap <QString, QString> props;
220 props["description"] = m_view.clip_description->text();
221 CLIPTYPE t = m_clip->clipType();
222 QMap <QString, QString> old_props = m_clip->properties();
223 double aspect = m_view.clip_ar->value();
224 if (m_view.clip_force_ar->isChecked()) {
225 if (aspect != old_props.value("force_aspect_ratio").toDouble()) {
226 props["force_aspect_ratio"] = QString::number(aspect);
227 m_clipNeedsRefresh = true;
229 } else if (old_props.contains("force_aspect_ratio")) {
230 props["force_aspect_ratio"] = QString();
231 m_clipNeedsRefresh = true;
234 QString new_color = m_view.clip_color->color().name();
235 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
236 m_clipNeedsRefresh = true;
237 props["colour"] = "0x" + new_color.right(6) + "ff";
239 } else if (t == IMAGE) {
240 if ((int) m_view.image_transparency->isChecked() != old_props.value("transparency").toInt()) {
241 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
242 m_clipNeedsRefresh = true;
244 } else if (t == SLIDESHOW) {
245 QString value = QString::number((int) m_view.slide_loop->isChecked());
246 if (old_props.value("loop") != value) props["loop"] = value;
247 value = QString::number((int) m_view.slide_fade->isChecked());
248 if (old_props.value("fade") != value) props["fade"] = value;
249 value = QString::number((int) m_view.luma_softness->value());
250 if (old_props.value("softness") != value) props["softness"] = value;
253 switch (m_view.image_type->currentIndex()) {
255 extension = "/.all.png";
258 extension = "/.all.bmp";
261 extension = "/.all.gif";
264 extension = "/.all.jpg";
267 QString new_path = m_view.clip_path->text() + extension;
268 if (new_path != old_props.value("resource")) {
269 m_clipNeedsRefresh = true;
270 props["resource"] = new_path;
271 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
273 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
274 if (duration != old_props.value("ttl").toInt()) {
275 m_clipNeedsRefresh = true;
276 props["ttl"] = QString::number(duration);
277 props["out"] = QString::number(duration * m_count);
279 if (duration * m_count != old_props.value("out").toInt()) {
280 m_clipNeedsRefresh = true;
281 props["out"] = QString::number(duration * m_count);
283 if (m_view.slide_fade->isChecked()) {
284 int luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
285 if (luma_duration != old_props.value("luma_duration").toInt()) {
286 m_clipNeedsRefresh = true;
287 props["luma_duration"] = QString::number(luma_duration);
290 if (m_view.slide_luma->isChecked())
291 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
292 if (lumaFile != old_props.value("luma_file")) {
293 m_clipNeedsRefresh = true;
294 props["luma_file"] = lumaFile;
297 if (old_props.value("luma_file") != QString()) {
298 props["luma_file"] = QString();
306 bool ClipProperties::needsTimelineRefresh() const {
307 return m_clipNeedsRefresh;
310 void ClipProperties::parseFolder() {
312 QDir dir(m_view.clip_path->text());
315 switch (m_view.image_type->currentIndex()) {
318 extension = "/.all.png";
322 extension = "/.all.bmp";
326 extension = "/.all.gif";
330 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
332 extension = "/.all.jpg";
336 dir.setNameFilters(filters);
337 QStringList result = dir.entryList(QDir::Files);
338 m_count = result.count();
339 m_view.slide_info->setText(i18n("%1 images found", m_count));
340 QDomElement xml = m_clip->toXML();
341 xml.setAttribute("resource", m_view.clip_path->text() + extension);
342 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, 240, 180);
343 QMap <QString, QString> props = m_clip->properties();
344 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
345 m_view.clip_thumb->setPixmap(pix);
348 #include "clipproperties.moc"