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);
54 if (props.contains("audiocodec"))
55 m_view.clip_acodec->setText(props.value("audiocodec"));
56 if (props.contains("frequency"))
57 m_view.clip_frequency->setText(props.value("frequency"));
58 if (props.contains("channels"))
59 m_view.clip_channels->setText(props.value("channels"));
61 CLIPTYPE t = m_clip->clipType();
63 m_view.tabWidget->removeTab(SLIDETAB);
64 m_view.tabWidget->removeTab(COLORTAB);
65 m_view.tabWidget->removeTab(AUDIOTAB);
66 m_view.tabWidget->removeTab(VIDEOTAB);
67 if (props.contains("frame_size"))
68 m_view.image_size->setText(props.value("frame_size"));
69 if (props.contains("transparency"))
70 m_view.image_transparency->setChecked(props.value("transparency").toInt());
71 } else if (t == COLOR) {
72 m_view.clip_path->setEnabled(false);
73 m_view.tabWidget->removeTab(IMAGETAB);
74 m_view.tabWidget->removeTab(SLIDETAB);
75 m_view.tabWidget->removeTab(AUDIOTAB);
76 m_view.tabWidget->removeTab(VIDEOTAB);
77 m_view.clip_thumb->setHidden(true);
78 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
79 } else if (t == SLIDESHOW) {
80 m_view.clip_path->setText(url.directory());
81 m_view.tabWidget->removeTab(IMAGETAB);
82 m_view.tabWidget->removeTab(COLORTAB);
83 m_view.tabWidget->removeTab(AUDIOTAB);
84 m_view.tabWidget->removeTab(VIDEOTAB);
86 types << "JPG" << "PNG" << "BMP" << "GIF";
87 m_view.image_type->addItems(types);
88 m_view.slide_loop->setChecked(props.value("loop").toInt());
89 m_view.slide_fade->setChecked(props.value("fade").toInt());
90 m_view.luma_softness->setValue(props.value("softness").toInt());
91 QString path = props.value("resource");
92 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
93 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
94 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
95 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
98 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
99 QString lumaFile = props.value("luma_file");
100 QString profilePath = KdenliveSettings::mltpath();
101 profilePath = profilePath.section('/', 0, -3);
102 profilePath += "/lumas/PAL/";
104 QDir dir(profilePath);
107 const QStringList result = dir.entryList(filter, QDir::Files);
108 QStringList imagefiles;
109 QStringList imagenamelist;
111 foreach(const QString file, result) {
112 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
113 if (!lumaFile.isEmpty() && lumaFile == QString(profilePath + file))
114 current = m_view.luma_file->count() - 1;
117 if (!lumaFile.isEmpty()) {
118 m_view.slide_luma->setChecked(true);
119 m_view.luma_file->setCurrentIndex(current);
122 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
123 } else if (t != AUDIO) {
124 m_view.tabWidget->removeTab(IMAGETAB);
125 m_view.tabWidget->removeTab(SLIDETAB);
126 m_view.tabWidget->removeTab(COLORTAB);
127 if (props.contains("frame_size"))
128 m_view.clip_size->setText(props.value("frame_size"));
129 if (props.contains("videocodec"))
130 m_view.clip_vcodec->setText(props.value("videocodec"));
131 if (props.contains("fps"))
132 m_view.clip_fps->setText(props.value("fps"));
133 if (props.contains("aspect_ratio"))
134 m_view.clip_ratio->setText(props.value("aspect_ratio"));
136 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), 240, 180);
137 m_view.clip_thumb->setPixmap(pix);
138 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
140 m_view.tabWidget->removeTab(IMAGETAB);
141 m_view.tabWidget->removeTab(SLIDETAB);
142 m_view.tabWidget->removeTab(COLORTAB);
143 m_view.tabWidget->removeTab(VIDEOTAB);
144 m_view.clip_thumb->setHidden(true);
146 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
148 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
149 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
150 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
153 m_view.marker_new->setIcon(KIcon("document-new"));
154 m_view.marker_new->setToolTip(i18n("Add marker"));
155 m_view.marker_edit->setIcon(KIcon("document-properties"));
156 m_view.marker_edit->setToolTip(i18n("Edit marker"));
157 m_view.marker_delete->setIcon(KIcon("trash-empty"));
158 m_view.marker_delete->setToolTip(i18n("Delete marker"));
160 slotFillMarkersList();
161 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
162 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
163 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
164 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
169 void ClipProperties::slotFillMarkersList() {
170 m_view.markers_list->clear();
171 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
172 for (uint count = 0; count < marks.count(); ++count) {
173 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
174 QStringList itemtext;
175 itemtext << time << marks[count].comment();
176 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
180 void ClipProperties::slotAddMarker() {
181 CommentedTime marker(GenTime(), i18n("Marker"));
182 MarkerDialog d(m_clip, marker, m_tc, this);
183 if (d.exec() == QDialog::Accepted) {
184 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
186 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
189 void ClipProperties::slotEditMarker() {
190 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
191 int pos = m_view.markers_list->currentIndex().row();
192 if (pos < 0 || pos > marks.count() - 1) return;
193 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
194 if (d.exec() == QDialog::Accepted) {
195 emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
197 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
200 void ClipProperties::slotDeleteMarker() {
201 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
202 int pos = m_view.markers_list->currentIndex().row();
203 if (pos < 0 || pos > marks.count() - 1) return;
204 emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
206 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
209 const QString &ClipProperties::clipId() const {
210 return m_clip->getId();
214 QMap <QString, QString> ClipProperties::properties() {
215 QMap <QString, QString> props;
216 props["description"] = m_view.clip_description->text();
217 CLIPTYPE t = m_clip->clipType();
219 QMap <QString, QString> old_props = m_clip->properties();
220 QString new_color = m_view.clip_color->color().name();
221 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
222 m_clipNeedsRefresh = true;
223 props["colour"] = "0x" + new_color.right(6) + "ff";
225 } else if (t == IMAGE) {
226 QMap <QString, QString> old_props = m_clip->properties();
227 if ((int) m_view.image_transparency->isChecked() != old_props.value("transparency").toInt()) {
228 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
229 m_clipNeedsRefresh = true;
231 } else if (t == SLIDESHOW) {
232 QMap <QString, QString> old_props = m_clip->properties();
233 QString value = QString::number((int) m_view.slide_loop->isChecked());
234 if (old_props.value("loop") != value) props["loop"] = value;
235 value = QString::number((int) m_view.slide_fade->isChecked());
236 if (old_props.value("fade") != value) props["fade"] = value;
237 value = QString::number((int) m_view.luma_softness->value());
238 if (old_props.value("softness") != value) props["softness"] = value;
241 switch (m_view.image_type->currentIndex()) {
243 extension = "/.all.png";
246 extension = "/.all.bmp";
249 extension = "/.all.gif";
252 extension = "/.all.jpg";
255 QString new_path = m_view.clip_path->text() + extension;
256 if (new_path != old_props.value("resource")) {
257 m_clipNeedsRefresh = true;
258 props["resource"] = new_path;
259 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
261 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
262 if (duration != old_props.value("ttl").toInt()) {
263 m_clipNeedsRefresh = true;
264 props["ttl"] = QString::number(duration);
265 props["out"] = QString::number(duration * m_count);
267 if (duration * m_count != old_props.value("out").toInt()) {
268 m_clipNeedsRefresh = true;
269 props["out"] = QString::number(duration * m_count);
271 if (m_view.slide_fade->isChecked()) {
272 int luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
273 if (luma_duration != old_props.value("luma_duration").toInt()) {
274 m_clipNeedsRefresh = true;
275 props["luma_duration"] = QString::number(luma_duration);
278 if (m_view.slide_luma->isChecked())
279 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
280 if (lumaFile != old_props.value("luma_file")) {
281 m_clipNeedsRefresh = true;
282 props["luma_file"] = lumaFile;
285 if (old_props.value("luma_file") != QString()) {
286 props["luma_file"] = QString();
294 bool ClipProperties::needsTimelineRefresh() const {
295 return m_clipNeedsRefresh;
298 void ClipProperties::parseFolder() {
300 QDir dir(m_view.clip_path->text());
303 switch (m_view.image_type->currentIndex()) {
306 extension = "/.all.png";
310 extension = "/.all.bmp";
314 extension = "/.all.gif";
318 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
320 extension = "/.all.jpg";
324 dir.setNameFilters(filters);
325 QStringList result = dir.entryList(QDir::Files);
326 m_count = result.count();
327 m_view.slide_info->setText(i18n("%1 images found", m_count));
328 QDomElement xml = m_clip->toXML();
329 xml.setAttribute("resource", m_view.clip_path->text() + extension);
330 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, 240, 180);
331 QMap <QString, QString> props = m_clip->properties();
332 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
333 m_view.clip_thumb->setPixmap(pix);
336 #include "clipproperties.moc"