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 QString path = props.value("resource");
75 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
76 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
77 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
78 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
80 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
81 } else if (t != AUDIO) {
82 m_view.tabWidget->removeTab(SLIDETAB);
83 m_view.tabWidget->removeTab(COLORTAB);
84 if (props.contains("frame_size"))
85 m_view.clip_size->setText(props.value("frame_size"));
86 if (props.contains("videocodec"))
87 m_view.clip_vcodec->setText(props.value("videocodec"));
88 if (props.contains("fps"))
89 m_view.clip_fps->setText(props.value("fps"));
90 if (props.contains("aspect_ratio"))
91 m_view.clip_ratio->setText(props.value("aspect_ratio"));
93 QPixmap pix = m_clip->thumbProducer()->getImage(url, 240, 180);
94 m_view.clip_thumb->setPixmap(pix);
95 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
97 m_view.tabWidget->removeTab(SLIDETAB);
98 m_view.tabWidget->removeTab(COLORTAB);
99 m_view.tabWidget->removeTab(VIDEOTAB);
100 m_view.clip_thumb->setHidden(true);
102 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
104 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
105 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
106 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
109 m_view.marker_new->setIcon(KIcon("document-new"));
110 m_view.marker_new->setToolTip(i18n("Add marker"));
111 m_view.marker_edit->setIcon(KIcon("document-properties"));
112 m_view.marker_edit->setToolTip(i18n("Edit marker"));
113 m_view.marker_delete->setIcon(KIcon("trash-empty"));
114 m_view.marker_delete->setToolTip(i18n("Delete marker"));
116 slotFillMarkersList();
117 connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
118 connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
119 connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
120 connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
125 void ClipProperties::slotFillMarkersList() {
126 m_view.markers_list->clear();
127 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
128 for (uint count = 0; count < marks.count(); ++count) {
129 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
130 QStringList itemtext;
131 itemtext << time << marks[count].comment();
132 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
136 void ClipProperties::slotAddMarker() {
137 CommentedTime marker(GenTime(), i18n("Marker"));
138 MarkerDialog d(m_clip, marker, m_tc, this);
139 if (d.exec() == QDialog::Accepted) {
140 int id = m_clip->getId();
141 emit addMarker(id, d.newMarker().time(), d.newMarker().comment());
143 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
146 void ClipProperties::slotEditMarker() {
147 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
148 int pos = m_view.markers_list->currentIndex().row();
149 if (pos < 0 || pos > marks.count() - 1) return;
150 MarkerDialog d(m_clip, marks.at(pos), m_tc, this);
151 if (d.exec() == QDialog::Accepted) {
152 int id = m_clip->getId();
153 emit addMarker(id, d.newMarker().time(), d.newMarker().comment());
155 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
158 void ClipProperties::slotDeleteMarker() {
159 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
160 int pos = m_view.markers_list->currentIndex().row();
161 if (pos < 0 || pos > marks.count() - 1) return;
162 int id = m_clip->getId();
163 emit addMarker(id, marks.at(pos).time(), QString());
165 QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
168 int ClipProperties::clipId() const {
169 return m_clip->getId();
173 QMap <QString, QString> ClipProperties::properties() {
174 QMap <QString, QString> props;
175 props["description"] = m_view.clip_description->text();
176 CLIPTYPE t = m_clip->clipType();
178 QMap <QString, QString> old_props = m_clip->properties();
179 QString new_color = m_view.clip_color->color().name();
180 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
181 m_clipNeedsRefresh = true;
182 props["colour"] = "0x" + new_color.right(6) + "ff";
184 } else if (t == SLIDESHOW) {
185 props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
186 QMap <QString, QString> old_props = m_clip->properties();
188 switch (m_view.image_type->currentIndex()) {
190 extension = "/.all.png";
193 extension = "/.all.bmp";
196 extension = "/.all.gif";
199 extension = "/.all.jpg";
202 QString new_path = m_view.clip_path->text() + extension;
203 if (new_path != old_props.value("resource")) {
204 m_clipNeedsRefresh = true;
205 props["resource"] = new_path;
206 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
208 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
209 if (duration != old_props.value("ttl").toInt()) {
210 m_clipNeedsRefresh = true;
211 props["ttl"] = QString::number(duration);
212 props["out"] = QString::number(duration * m_count);
214 if (duration * m_count != old_props.value("out").toInt()) {
215 m_clipNeedsRefresh = true;
216 props["out"] = QString::number(duration * m_count);
223 bool ClipProperties::needsTimelineRefresh() const {
224 return m_clipNeedsRefresh;
227 void ClipProperties::parseFolder() {
229 QDir dir(m_view.clip_path->text());
232 switch (m_view.image_type->currentIndex()) {
235 extension = "/.all.png";
239 extension = "/.all.bmp";
243 extension = "/.all.gif";
246 filters << "*.jpg" << "*.jpeg";
247 extension = "/.all.jpg";
251 dir.setNameFilters(filters);
252 QStringList result = dir.entryList(QDir::Files);
253 m_count = result.count();
254 m_view.slide_info->setText(i18n("%1 images found", m_count));
255 QDomElement xml = m_clip->toXML();
256 xml.setAttribute("resource", m_view.clip_path->text() + extension);
257 QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
258 QMap <QString, QString> props = m_clip->properties();
259 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
260 m_view.clip_thumb->setPixmap(pix);
263 #include "clipproperties.moc"