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));
109 int ClipProperties::clipId() const {
110 return m_clip->getId();
114 QMap <QString, QString> ClipProperties::properties() {
115 QMap <QString, QString> props;
116 props["description"] = m_view.clip_description->text();
117 CLIPTYPE t = m_clip->clipType();
119 QMap <QString, QString> old_props = m_clip->properties();
120 QString new_color = m_view.clip_color->color().name();
121 if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
122 m_clipNeedsRefresh = true;
123 props["colour"] = "0x" + new_color.right(6) + "ff";
125 } else if (t == SLIDESHOW) {
126 props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
127 QMap <QString, QString> old_props = m_clip->properties();
129 switch (m_view.image_type->currentIndex()) {
131 extension = "/.all.png";
134 extension = "/.all.bmp";
137 extension = "/.all.gif";
140 extension = "/.all.jpg";
143 QString new_path = m_view.clip_path->text() + extension;
144 if (new_path != old_props.value("resource")) {
145 m_clipNeedsRefresh = true;
146 props["resource"] = new_path;
147 kDebug() << "//// SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
149 int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
150 if (duration != old_props.value("ttl").toInt()) {
151 m_clipNeedsRefresh = true;
152 props["ttl"] = QString::number(duration);
153 props["out"] = QString::number(duration * m_count);
155 if (duration * m_count != old_props.value("out").toInt()) {
156 m_clipNeedsRefresh = true;
157 props["out"] = QString::number(duration * m_count);
164 bool ClipProperties::needsTimelineRefresh() const {
165 return m_clipNeedsRefresh;
168 void ClipProperties::parseFolder() {
170 QDir dir(m_view.clip_path->text());
173 switch (m_view.image_type->currentIndex()) {
176 extension = "/.all.png";
180 extension = "/.all.bmp";
184 extension = "/.all.gif";
187 filters << "*.jpg" << "*.jpeg";
188 extension = "/.all.jpg";
192 dir.setNameFilters(filters);
193 QStringList result = dir.entryList(QDir::Files);
194 m_count = result.count();
195 m_view.slide_info->setText(i18n("%1 images found", m_count));
196 QDomElement xml = m_clip->toXML();
197 xml.setAttribute("resource", m_view.clip_path->text() + extension);
198 QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
199 QMap <QString, QString> props = m_clip->properties();
200 m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
201 m_view.clip_thumb->setPixmap(pix);
204 #include "clipproperties.moc"