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"
42 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) {
43 setFont(KGlobalSettings::toolBarFont());
45 KUrl url = m_clip->fileURL();
46 m_view.clip_path->setText(url.path());
47 m_view.clip_description->setText(m_clip->description());
48 QMap <QString, QString> props = m_clip->properties();
50 if (props.contains("audiocodec"))
51 m_view.clip_acodec->setText(props.value("audiocodec"));
52 if (props.contains("frequency"))
53 m_view.clip_frequency->setText(props.value("frequency"));
54 if (props.contains("channels"))
55 m_view.clip_channels->setText(props.value("channels"));
57 CLIPTYPE t = m_clip->clipType();
59 m_view.clip_path->setEnabled(false);
60 m_view.tabWidget->removeTab(SLIDETAB);
61 m_view.tabWidget->removeTab(AUDIOTAB);
62 m_view.tabWidget->removeTab(VIDEOTAB);
63 m_view.clip_thumb->setHidden(true);
64 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
65 } else if (t == SLIDESHOW) {
66 m_view.clip_path->setText(url.directory());
67 m_view.tabWidget->removeTab(COLORTAB);
68 m_view.tabWidget->removeTab(AUDIOTAB);
69 m_view.tabWidget->removeTab(VIDEOTAB);
71 types << "JPG" << "PNG" << "BMP" << "GIF";
72 m_view.image_type->addItems(types);
73 m_view.slide_loop->setChecked(props.value("loop").toInt());
74 m_view.slide_fade->setChecked(props.value("fade").toInt());
75 QString path = props.value("resource");
76 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
77 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
78 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
79 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
82 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
83 QString lumaFile = props.value("luma_file");
84 QString profilePath = KdenliveSettings::mltpath();
85 profilePath = profilePath.section('/', 0, -3);
86 profilePath += "/lumas/PAL/";
88 QDir dir(profilePath);
89 QStringList result = dir.entryList(QDir::Files);
90 QStringList imagefiles;
91 QStringList imagenamelist;
93 foreach(QString file, result) {
94 if (file.endsWith(".pgm")) {
95 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
96 if (!lumaFile.isEmpty() && lumaFile == QString(profilePath + file))
97 current = m_view.luma_file->count() - 1;
101 if (!lumaFile.isEmpty()) {
102 m_view.slide_luma->setChecked(true);
103 m_view.luma_file->setCurrentIndex(current);
106 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
107 } else if (t != AUDIO) {
108 m_view.tabWidget->removeTab(SLIDETAB);
109 m_view.tabWidget->removeTab(COLORTAB);
110 if (props.contains("frame_size"))
111 m_view.clip_size->setText(props.value("frame_size"));
112 if (props.contains("videocodec"))
113 m_view.clip_vcodec->setText(props.value("videocodec"));
114 if (props.contains("fps"))
115 m_view.clip_fps->setText(props.value("fps"));
116 if (props.contains("aspect_ratio"))
117 m_view.clip_ratio->setText(props.value("aspect_ratio"));
119 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), 240, 180);
120 m_view.clip_thumb->setPixmap(pix);
121 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
123 m_view.tabWidget->removeTab(SLIDETAB);
124 m_view.tabWidget->removeTab(COLORTAB);
125 m_view.tabWidget->removeTab(VIDEOTAB);
126 m_view.clip_thumb->setHidden(true);
128 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
130 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
131 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
132 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
135 m_view.marker_new->setIcon(KIcon("document-new"));
136 m_view.marker_new->setToolTip(i18n("Add marker"));
137 m_view.marker_edit->setIcon(KIcon("document-properties"));
138 m_view.marker_edit->setToolTip(i18n("Edit marker"));
139 m_view.marker_delete->setIcon(KIcon("trash-empty"));
140 m_view.marker_delete->setToolTip(i18n("Delete marker"));
142 slotFillMarkersList();
143 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
144 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
145 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
146 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
151 void ClipProperties::slotFillMarkersList() {
152 m_view.markers_list->clear();
153 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
154 for (uint count = 0; count < marks.count(); ++count) {
155 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
156 QStringList itemtext;
157 itemtext << time << marks[count].comment();
158 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
162 void ClipProperties::slotAddMarker() {
163 CommentedTime marker(GenTime(), i18n("Marker"));
164 MarkerDialog d(m_clip, marker, m_tc, this);
165 if (d.exec() == QDialog::Accepted) {
166 int id = m_clip->getId();
167 emit addMarker(id, d.newMarker().time(), d.newMarker().comment());
169 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
172 void ClipProperties::slotEditMarker() {
173 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
174 int pos = m_view.markers_list->currentIndex().row();
175 if (pos < 0 || pos > marks.count() - 1) return;
176 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
177 if (d.exec() == QDialog::Accepted) {
178 int id = m_clip->getId();
179 emit addMarker(id, d.newMarker().time(), d.newMarker().comment());
181 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
184 void ClipProperties::slotDeleteMarker() {
185 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
186 int pos = m_view.markers_list->currentIndex().row();
187 if (pos < 0 || pos > marks.count() - 1) return;
188 int id = m_clip->getId();
189 emit addMarker(id, marks.at(pos).time(), QString());
191 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
194 int ClipProperties::clipId() const {
195 return m_clip->getId();
199 QMap <QString, QString> ClipProperties::properties() {
200 QMap <QString, QString> props;
201 props["description"] = m_view.clip_description->text();
202 CLIPTYPE t = m_clip->clipType();
204 QMap <QString, QString> old_props = m_clip->properties();
205 QString new_color = m_view.clip_color->color().name();
206 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
207 m_clipNeedsRefresh = true;
208 props["colour"] = "0x" + new_color.right(6) + "ff";
210 } else if (t == SLIDESHOW) {
211 QMap <QString, QString> old_props = m_clip->properties();
212 QString value = QString::number((int) m_view.slide_loop->isChecked());
213 if (old_props.value("loop") != value) props["loop"] = value;
214 value = QString::number((int) m_view.slide_fade->isChecked());
215 if (old_props.value("fade") != value) props["fade"] = value;
218 switch (m_view.image_type->currentIndex()) {
220 extension = "/.all.png";
223 extension = "/.all.bmp";
226 extension = "/.all.gif";
229 extension = "/.all.jpg";
232 QString new_path = m_view.clip_path->text() + extension;
233 if (new_path != old_props.value("resource")) {
234 m_clipNeedsRefresh = true;
235 props["resource"] = new_path;
236 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
238 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
239 if (duration != old_props.value("ttl").toInt()) {
240 m_clipNeedsRefresh = true;
241 props["ttl"] = QString::number(duration);
242 props["out"] = QString::number(duration * m_count);
244 if (duration * m_count != old_props.value("out").toInt()) {
245 m_clipNeedsRefresh = true;
246 props["out"] = QString::number(duration * m_count);
248 if (m_view.slide_fade->isChecked()) {
249 int luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
250 if (luma_duration != old_props.value("luma_duration").toInt()) {
251 m_clipNeedsRefresh = true;
252 props["luma_duration"] = QString::number(luma_duration);
255 if (m_view.slide_luma->isChecked())
256 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
257 if (lumaFile != old_props.value("luma_file")) {
258 m_clipNeedsRefresh = true;
259 props["luma_file"] = lumaFile;
262 if (old_props.value("luma_file") != QString()) {
263 props["luma_file"] = QString();
271 bool ClipProperties::needsTimelineRefresh() const {
272 return m_clipNeedsRefresh;
275 void ClipProperties::parseFolder() {
277 QDir dir(m_view.clip_path->text());
280 switch (m_view.image_type->currentIndex()) {
283 extension = "/.all.png";
287 extension = "/.all.bmp";
291 extension = "/.all.gif";
294 filters << "*.jpg" << "*.jpeg";
295 extension = "/.all.jpg";
299 dir.setNameFilters(filters);
300 QStringList result = dir.entryList(QDir::Files);
301 m_count = result.count();
302 m_view.slide_info->setText(i18n("%1 images found", m_count));
303 QDomElement xml = m_clip->toXML();
304 xml.setAttribute("resource", m_view.clip_path->text() + extension);
305 QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
306 QMap <QString, QString> props = m_clip->properties();
307 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
308 m_view.clip_thumb->setPixmap(pix);
311 #include "clipproperties.moc"