1 /***************************************************************************
2 * Copyright (C) 2007 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 ***************************************************************************/
21 #include "projectitem.h"
23 #include "kdenlivesettings.h"
24 #include "docclipbase.h"
30 const int DurationRole = Qt::UserRole + 1;
31 const int ProxyRole = Qt::UserRole + 5;
32 const int itemHeight = 38;
34 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
35 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
37 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
38 if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
39 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
41 m_clipId = clip->getId();
42 QString name = m_clip->getProperty("name");
43 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
44 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
45 if (m_clipType != UNKNOWN) slotSetToolTip();
47 setText(1, m_clip->description());
48 GenTime duration = m_clip->duration();
49 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
50 //setFlags(Qt::NoItemFlags);
51 //kDebug() << "Constructed with clipId: " << m_clipId;
54 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
55 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
57 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
58 if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
59 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
61 m_clipId = clip->getId();
62 QString name = m_clip->getProperty("name");
63 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
64 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
66 setText(1, m_clip->description());
67 GenTime duration = m_clip->duration();
68 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
69 //setFlags(Qt::NoItemFlags);
70 //kDebug() << "Constructed with clipId: " << m_clipId;
74 ProjectItem::~ProjectItem()
79 int ProjectItem::itemDefaultHeight()
84 int ProjectItem::numReferences() const
86 if (!m_clip) return 0;
87 return m_clip->numReferences();
90 const QString &ProjectItem::clipId() const
95 CLIPTYPE ProjectItem::clipType() const
100 int ProjectItem::clipMaxDuration() const
102 return m_clip->getProperty("duration").toInt();
105 QStringList ProjectItem::names() const
108 result.append(text(0));
109 result.append(text(1));
110 result.append(text(2));
114 QDomElement ProjectItem::toXml() const
116 return m_clip->toXML();
119 const KUrl ProjectItem::clipUrl() const
121 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
122 return KUrl(m_clip->getProperty("resource"));
126 void ProjectItem::changeDuration(int frames)
128 setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
131 void ProjectItem::setProperties(QMap <QString, QString> props)
133 if (m_clip == NULL) return;
134 m_clip->setProperties(props);
137 QString ProjectItem::getClipHash() const
139 if (m_clip == NULL) return QString();
140 return m_clip->getClipHash();
143 void ProjectItem::setProperty(const QString &key, const QString &value)
145 if (m_clip == NULL) return;
146 m_clip->setProperty(key, value);
149 void ProjectItem::clearProperty(const QString &key)
151 if (m_clip == NULL) return;
152 m_clip->clearProperty(key);
155 DocClipBase *ProjectItem::referencedClip()
160 void ProjectItem::slotSetToolTip()
163 if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
164 switch (m_clipType) {
166 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
169 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
172 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
175 tip.append(i18n("Color clip"));
178 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
181 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
182 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
185 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
188 tip.append(i18n("Virtual clip"));
191 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
194 tip.append(i18n("Unknown clip"));
202 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
204 if (m_clip == NULL) return;
205 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
206 if (attributes.contains("duration")) {
207 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
208 setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
209 m_clip->setDuration(duration);
211 // No duration known, use an arbitrary one until it is.
215 //extend attributes -reh
217 if (m_clipType == UNKNOWN) {
218 QString cliptype = attributes.value("type");
219 if (cliptype == "audio") m_clipType = AUDIO;
220 else if (cliptype == "video") m_clipType = VIDEO;
221 else if (cliptype == "av") m_clipType = AV;
222 else if (cliptype == "playlist") m_clipType = PLAYLIST;
223 else m_clipType = AV;
225 m_clip->setClipType(m_clipType);
228 m_clip->setProperties(attributes);
229 m_clip->setMetadata(metadata);
231 if (m_clip->description().isEmpty()) {
232 if (metadata.contains("description")) {
233 m_clip->setProperty("description", metadata.value("description"));
234 setText(1, m_clip->description());
235 } else if (metadata.contains("comment")) {
236 m_clip->setProperty("description", metadata.value("comment"));
237 setText(1, m_clip->description());
242 void ProjectItem::setProxyStatus(int status)
244 if (status == data(0, ProxyRole).toInt()) return;
245 setData(0, ProxyRole, status);
246 if (m_clip && status == 0) m_clip->abortProxy();
249 bool ProjectItem::hasProxy() const
251 if (m_clip == NULL) return false;
252 return !m_clip->getProperty("proxy").isEmpty();
255 bool ProjectItem::isProxyRunning() const
257 return (data(0, ProxyRole).toInt() == 1);