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"
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("audiocodec"))
53 m_view.clip_acodec->setText(props.value("audiocodec"));
54 if (props.contains("frequency"))
55 m_view.clip_frequency->setText(props.value("frequency"));
56 if (props.contains("channels"))
57 m_view.clip_channels->setText(props.value("channels"));
59 CLIPTYPE t = m_clip->clipType();
61 m_view.tabWidget->removeTab(SLIDETAB);
62 m_view.tabWidget->removeTab(COLORTAB);
63 m_view.tabWidget->removeTab(AUDIOTAB);
64 m_view.tabWidget->removeTab(VIDEOTAB);
65 if (props.contains("frame_size"))
66 m_view.image_size->setText(props.value("frame_size"));
67 if (props.contains("transparency"))
68 m_view.image_transparency->setChecked(props.value("transparency").toInt());
69 } else if (t == COLOR) {
70 m_view.clip_path->setEnabled(false);
71 m_view.tabWidget->removeTab(IMAGETAB);
72 m_view.tabWidget->removeTab(SLIDETAB);
73 m_view.tabWidget->removeTab(AUDIOTAB);
74 m_view.tabWidget->removeTab(VIDEOTAB);
75 m_view.clip_thumb->setHidden(true);
76 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
77 } else if (t == SLIDESHOW) {
78 m_view.clip_path->setText(url.directory());
79 m_view.tabWidget->removeTab(IMAGETAB);
80 m_view.tabWidget->removeTab(COLORTAB);
81 m_view.tabWidget->removeTab(AUDIOTAB);
82 m_view.tabWidget->removeTab(VIDEOTAB);
84 types << "JPG" << "PNG" << "BMP" << "GIF";
85 m_view.image_type->addItems(types);
86 m_view.slide_loop->setChecked(props.value("loop").toInt());
87 m_view.slide_fade->setChecked(props.value("fade").toInt());
88 m_view.luma_softness->setValue(props.value("softness").toInt());
89 QString path = props.value("resource");
90 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
91 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
92 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
93 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
96 m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
97 QString lumaFile = props.value("luma_file");
98 QString profilePath = KdenliveSettings::mltpath();
99 profilePath = profilePath.section('/', 0, -3);
100 profilePath += "/lumas/PAL/";
102 QDir dir(profilePath);
105 const QStringList result = dir.entryList(filter, QDir::Files);
106 QStringList imagefiles;
107 QStringList imagenamelist;
109 foreach(const QString file, result) {
110 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
111 if (!lumaFile.isEmpty() && lumaFile == QString(profilePath + file))
112 current = m_view.luma_file->count() - 1;
115 if (!lumaFile.isEmpty()) {
116 m_view.slide_luma->setChecked(true);
117 m_view.luma_file->setCurrentIndex(current);
120 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
121 } else if (t != AUDIO) {
122 m_view.tabWidget->removeTab(IMAGETAB);
123 m_view.tabWidget->removeTab(SLIDETAB);
124 m_view.tabWidget->removeTab(COLORTAB);
125 if (props.contains("frame_size"))
126 m_view.clip_size->setText(props.value("frame_size"));
127 if (props.contains("videocodec"))
128 m_view.clip_vcodec->setText(props.value("videocodec"));
129 if (props.contains("fps"))
130 m_view.clip_fps->setText(props.value("fps"));
131 if (props.contains("aspect_ratio"))
132 m_view.clip_ratio->setText(props.value("aspect_ratio"));
134 QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), 240, 180);
135 m_view.clip_thumb->setPixmap(pix);
136 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
138 m_view.tabWidget->removeTab(IMAGETAB);
139 m_view.tabWidget->removeTab(SLIDETAB);
140 m_view.tabWidget->removeTab(COLORTAB);
141 m_view.tabWidget->removeTab(VIDEOTAB);
142 m_view.clip_thumb->setHidden(true);
144 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
146 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
147 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
148 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
151 m_view.marker_new->setIcon(KIcon("document-new"));
152 m_view.marker_new->setToolTip(i18n("Add marker"));
153 m_view.marker_edit->setIcon(KIcon("document-properties"));
154 m_view.marker_edit->setToolTip(i18n("Edit marker"));
155 m_view.marker_delete->setIcon(KIcon("trash-empty"));
156 m_view.marker_delete->setToolTip(i18n("Delete marker"));
158 slotFillMarkersList();
159 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
160 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
161 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
162 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
167 void ClipProperties::slotFillMarkersList() {
168 m_view.markers_list->clear();
169 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
170 for (uint count = 0; count < marks.count(); ++count) {
171 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
172 QStringList itemtext;
173 itemtext << time << marks[count].comment();
174 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
178 void ClipProperties::slotAddMarker() {
179 CommentedTime marker(GenTime(), i18n("Marker"));
180 MarkerDialog d(m_clip, marker, m_tc, this);
181 if (d.exec() == QDialog::Accepted) {
182 int id = m_clip->getId();
183 emit addMarker(id, d.newMarker().time(), d.newMarker().comment());
185 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
188 void ClipProperties::slotEditMarker() {
189 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
190 int pos = m_view.markers_list->currentIndex().row();
191 if (pos < 0 || pos > marks.count() - 1) return;
192 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
193 if (d.exec() == QDialog::Accepted) {
194 int id = m_clip->getId();
195 emit addMarker(id, 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 int id = m_clip->getId();
205 emit addMarker(id, marks.at(pos).time(), QString());
207 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
210 int ClipProperties::clipId() const {
211 return m_clip->getId();
215 QMap <QString, QString> ClipProperties::properties() {
216 QMap <QString, QString> props;
217 props["description"] = m_view.clip_description->text();
218 CLIPTYPE t = m_clip->clipType();
220 QMap <QString, QString> old_props = m_clip->properties();
221 QString new_color = m_view.clip_color->color().name();
222 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
223 m_clipNeedsRefresh = true;
224 props["colour"] = "0x" + new_color.right(6) + "ff";
226 } else if (t == IMAGE) {
227 QMap <QString, QString> old_props = m_clip->properties();
228 if ((int) m_view.image_transparency->isChecked() != old_props.value("transparency").toInt()) {
229 props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
230 m_clipNeedsRefresh = true;
232 } else if (t == SLIDESHOW) {
233 QMap <QString, QString> old_props = m_clip->properties();
234 QString value = QString::number((int) m_view.slide_loop->isChecked());
235 if (old_props.value("loop") != value) props["loop"] = value;
236 value = QString::number((int) m_view.slide_fade->isChecked());
237 if (old_props.value("fade") != value) props["fade"] = value;
238 value = QString::number((int) m_view.luma_softness->value());
239 if (old_props.value("softness") != value) props["softness"] = value;
242 switch (m_view.image_type->currentIndex()) {
244 extension = "/.all.png";
247 extension = "/.all.bmp";
250 extension = "/.all.gif";
253 extension = "/.all.jpg";
256 QString new_path = m_view.clip_path->text() + extension;
257 if (new_path != old_props.value("resource")) {
258 m_clipNeedsRefresh = true;
259 props["resource"] = new_path;
260 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
262 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
263 if (duration != old_props.value("ttl").toInt()) {
264 m_clipNeedsRefresh = true;
265 props["ttl"] = QString::number(duration);
266 props["out"] = QString::number(duration * m_count);
268 if (duration * m_count != old_props.value("out").toInt()) {
269 m_clipNeedsRefresh = true;
270 props["out"] = QString::number(duration * m_count);
272 if (m_view.slide_fade->isChecked()) {
273 int luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
274 if (luma_duration != old_props.value("luma_duration").toInt()) {
275 m_clipNeedsRefresh = true;
276 props["luma_duration"] = QString::number(luma_duration);
279 if (m_view.slide_luma->isChecked())
280 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
281 if (lumaFile != old_props.value("luma_file")) {
282 m_clipNeedsRefresh = true;
283 props["luma_file"] = lumaFile;
286 if (old_props.value("luma_file") != QString()) {
287 props["luma_file"] = QString();
295 bool ClipProperties::needsTimelineRefresh() const {
296 return m_clipNeedsRefresh;
299 void ClipProperties::parseFolder() {
301 QDir dir(m_view.clip_path->text());
304 switch (m_view.image_type->currentIndex()) {
307 extension = "/.all.png";
311 extension = "/.all.bmp";
315 extension = "/.all.gif";
318 filters << "*.jpg" << "*.jpeg";
319 extension = "/.all.jpg";
323 dir.setNameFilters(filters);
324 QStringList result = dir.entryList(QDir::Files);
325 m_count = result.count();
326 m_view.slide_info->setText(i18n("%1 images found", m_count));
327 QDomElement xml = m_clip->toXML();
328 xml.setAttribute("resource", m_view.clip_path->text() + extension);
329 QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, 240, 180);
330 QMap <QString, QString> props = m_clip->properties();
331 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
332 m_view.clip_thumb->setPixmap(pix);
335 #include "clipproperties.moc"