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;
32 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
33 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
35 setSizeHint(0, QSize(65, 45));
36 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
38 m_clipId = clip->getId();
39 QString name = m_clip->getProperty("name");
40 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
41 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
42 if (m_clipType != UNKNOWN) slotSetToolTip();
44 setText(1, m_clip->description());
45 m_clip->askForAudioThumbs();
46 GenTime duration = m_clip->duration();
47 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
48 //setFlags(Qt::NoItemFlags);
49 //kDebug() << "Constructed with clipId: " << m_clipId;
52 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
53 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
55 setSizeHint(0, QSize(65, 45));
56 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
58 m_clipId = clip->getId();
59 QString name = m_clip->getProperty("name");
60 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
61 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
63 setText(1, m_clip->description());
64 m_clip->askForAudioThumbs();
65 GenTime duration = m_clip->duration();
66 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
67 //setFlags(Qt::NoItemFlags);
68 //kDebug() << "Constructed with clipId: " << m_clipId;
72 ProjectItem::~ProjectItem()
76 int ProjectItem::numReferences() const
78 if (!m_clip) return 0;
79 return m_clip->numReferences();
82 const QString &ProjectItem::clipId() const
87 CLIPTYPE ProjectItem::clipType() const
92 int ProjectItem::clipMaxDuration() const
94 return m_clip->getProperty("duration").toInt();
97 QStringList ProjectItem::names() const
100 result.append(text(0));
101 result.append(text(1));
102 result.append(text(2));
106 QDomElement ProjectItem::toXml() const
108 return m_clip->toXML();
111 const KUrl ProjectItem::clipUrl() const
113 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
114 return KUrl(m_clip->getProperty("resource"));
118 void ProjectItem::changeDuration(int frames)
120 setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
123 void ProjectItem::setProperties(QMap <QString, QString> props)
125 if (m_clip == NULL) return;
126 m_clip->setProperties(props);
129 QString ProjectItem::getClipHash() const
131 if (m_clip == NULL) return QString();
132 return m_clip->getClipHash();
135 void ProjectItem::setProperty(const QString &key, const QString &value)
137 if (m_clip == NULL) return;
138 m_clip->setProperty(key, value);
141 void ProjectItem::clearProperty(const QString &key)
143 if (m_clip == NULL) return;
144 m_clip->clearProperty(key);
147 DocClipBase *ProjectItem::referencedClip()
152 void ProjectItem::slotSetToolTip()
155 switch (m_clipType) {
157 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
160 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
163 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
166 tip.append(i18n("Color clip"));
169 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
172 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
173 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
176 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
179 tip.append(i18n("Virtual clip"));
182 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
185 tip.append(i18n("Unknown clip"));
193 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
195 if (m_clip == NULL) return;
196 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
197 if (attributes.contains("duration")) {
198 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
199 setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
200 m_clip->setDuration(duration);
202 // No duration known, use an arbitrary one until it is.
206 //extend attributes -reh
208 if (m_clipType == UNKNOWN) {
209 QString cliptype = attributes.value("type");
210 if (cliptype == "audio") m_clipType = AUDIO;
211 else if (cliptype == "video") m_clipType = VIDEO;
212 else if (cliptype == "av") m_clipType = AV;
213 else if (cliptype == "playlist") m_clipType = PLAYLIST;
214 else m_clipType = AV;
216 m_clip->setClipType(m_clipType);
219 m_clip->setProperties(attributes);
220 m_clip->setMetadata(metadata);
221 m_clip->askForAudioThumbs();
223 if (m_clip->description().isEmpty()) {
224 if (metadata.contains("description")) {
225 m_clip->setProperty("description", metadata.value("description"));
226 setText(1, m_clip->description());
227 } else if (metadata.contains("comment")) {
228 m_clip->setProperty("description", metadata.value("comment"));
229 setText(1, m_clip->description());