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"
41 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) {
42 setFont(KGlobalSettings::toolBarFont());
44 KUrl url = m_clip->fileURL();
45 m_view.clip_path->setText(url.path());
46 m_view.clip_description->setText(m_clip->description());
47 QMap <QString, QString> props = m_clip->properties();
49 if (props.contains("audiocodec"))
50 m_view.clip_acodec->setText(props.value("audiocodec"));
51 if (props.contains("frequency"))
52 m_view.clip_frequency->setText(props.value("frequency"));
53 if (props.contains("channels"))
54 m_view.clip_channels->setText(props.value("channels"));
56 CLIPTYPE t = m_clip->clipType();
58 m_view.clip_path->setEnabled(false);
59 m_view.tabWidget->removeTab(SLIDETAB);
60 m_view.tabWidget->removeTab(AUDIOTAB);
61 m_view.tabWidget->removeTab(VIDEOTAB);
62 m_view.clip_thumb->setHidden(true);
63 m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
64 } else if (t == SLIDESHOW) {
65 m_view.clip_path->setText(url.directory());
66 m_view.tabWidget->removeTab(COLORTAB);
67 m_view.tabWidget->removeTab(AUDIOTAB);
68 m_view.tabWidget->removeTab(VIDEOTAB);
70 types << "JPG" << "PNG" << "BMP" << "GIF";
71 m_view.image_type->addItems(types);
72 m_view.slide_loop->setChecked(props.value("loop").toInt());
73 QString path = props.value("resource");
74 if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
75 else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
76 else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
77 m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
79 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
80 } else if (t != AUDIO) {
81 m_view.tabWidget->removeTab(SLIDETAB);
82 m_view.tabWidget->removeTab(COLORTAB);
83 if (props.contains("frame_size"))
84 m_view.clip_size->setText(props.value("frame_size"));
85 if (props.contains("videocodec"))
86 m_view.clip_vcodec->setText(props.value("videocodec"));
87 if (props.contains("fps"))
88 m_view.clip_fps->setText(props.value("fps"));
89 if (props.contains("aspect_ratio"))
90 m_view.clip_ratio->setText(props.value("aspect_ratio"));
92 QPixmap pix = m_clip->thumbProducer()->getImage(url, 240, 180);
93 m_view.clip_thumb->setPixmap(pix);
94 if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
96 m_view.tabWidget->removeTab(SLIDETAB);
97 m_view.tabWidget->removeTab(COLORTAB);
98 m_view.tabWidget->removeTab(VIDEOTAB);
99 m_view.clip_thumb->setHidden(true);
101 if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
103 KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
104 m_view.clip_filesize->setText(KIO::convertSize(f.size()));
105 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
107 QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
109 for (uint count = 0; count < marks.count(); ++count) {
110 QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
111 QStringList itemtext;
112 itemtext << time << marks[count].comment();
113 (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
120 int ClipProperties::clipId() const {
121 return m_clip->getId();
125 QMap <QString, QString> ClipProperties::properties() {
126 QMap <QString, QString> props;
127 props["description"] = m_view.clip_description->text();
128 CLIPTYPE t = m_clip->clipType();
130 QMap <QString, QString> old_props = m_clip->properties();
131 QString new_color = m_view.clip_color->color().name();
132 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
133 m_clipNeedsRefresh = true;
134 props["colour"] = "0x" + new_color.right(6) + "ff";
136 } else if (t == SLIDESHOW) {
137 props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
138 QMap <QString, QString> old_props = m_clip->properties();
140 switch (m_view.image_type->currentIndex()) {
142 extension = "/.all.png";
145 extension = "/.all.bmp";
148 extension = "/.all.gif";
151 extension = "/.all.jpg";
154 QString new_path = m_view.clip_path->text() + extension;
155 if (new_path != old_props.value("resource")) {
156 m_clipNeedsRefresh = true;
157 props["resource"] = new_path;
158 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
160 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
161 if (duration != old_props.value("ttl").toInt()) {
162 m_clipNeedsRefresh = true;
163 props["ttl"] = QString::number(duration);
164 props["out"] = QString::number(duration * m_count);
166 if (duration * m_count != old_props.value("out").toInt()) {
167 m_clipNeedsRefresh = true;
168 props["out"] = QString::number(duration * m_count);
175 bool ClipProperties::needsTimelineRefresh() const {
176 return m_clipNeedsRefresh;
179 void ClipProperties::parseFolder() {
181 QDir dir(m_view.clip_path->text());
184 switch (m_view.image_type->currentIndex()) {
187 extension = "/.all.png";
191 extension = "/.all.bmp";
195 extension = "/.all.gif";
198 filters << "*.jpg" << "*.jpeg";
199 extension = "/.all.jpg";
203 dir.setNameFilters(filters);
204 QStringList result = dir.entryList(QDir::Files);
205 m_count = result.count();
206 m_view.slide_info->setText(i18n("%1 images found", m_count));
207 QDomElement xml = m_clip->toXML();
208 xml.setAttribute("resource", m_view.clip_path->text() + extension);
209 QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
210 QMap <QString, QString> props = m_clip->properties();
211 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
212 m_view.clip_thumb->setPixmap(pix);
215 #include "clipproperties.moc"