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 itemHeight = 38;
33 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
34 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
36 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
37 if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
38 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
40 m_clipId = clip->getId();
41 QString name = m_clip->getProperty("name");
42 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
43 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
44 if (m_clipType != UNKNOWN) slotSetToolTip();
46 setText(1, m_clip->description());
47 GenTime duration = m_clip->duration();
48 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
49 //setFlags(Qt::NoItemFlags);
50 //kDebug() << "Constructed with clipId: " << m_clipId;
53 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
54 QTreeWidgetItem(parent, PROJECTCLIPTYPE)
56 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
57 if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
58 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
60 m_clipId = clip->getId();
61 QString name = m_clip->getProperty("name");
62 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
63 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
65 setText(1, m_clip->description());
66 GenTime duration = m_clip->duration();
67 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
68 //setFlags(Qt::NoItemFlags);
69 //kDebug() << "Constructed with clipId: " << m_clipId;
73 ProjectItem::~ProjectItem()
78 int ProjectItem::itemDefaultHeight()
83 int ProjectItem::numReferences() const
85 if (!m_clip) return 0;
86 return m_clip->numReferences();
89 const QString &ProjectItem::clipId() const
94 CLIPTYPE ProjectItem::clipType() const
99 int ProjectItem::clipMaxDuration() const
101 return m_clip->getProperty("duration").toInt();
104 QStringList ProjectItem::names() const
107 result.append(text(0));
108 result.append(text(1));
109 result.append(text(2));
113 QDomElement ProjectItem::toXml() const
115 return m_clip->toXML();
118 const KUrl ProjectItem::clipUrl() const
120 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
121 return KUrl(m_clip->getProperty("resource"));
125 void ProjectItem::changeDuration(int frames)
127 setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
130 void ProjectItem::setProperties(QMap <QString, QString> props)
132 if (m_clip == NULL) return;
133 m_clip->setProperties(props);
136 QString ProjectItem::getClipHash() const
138 if (m_clip == NULL) return QString();
139 return m_clip->getClipHash();
142 void ProjectItem::setProperty(const QString &key, const QString &value)
144 if (m_clip == NULL) return;
145 m_clip->setProperty(key, value);
148 void ProjectItem::clearProperty(const QString &key)
150 if (m_clip == NULL) return;
151 m_clip->clearProperty(key);
154 DocClipBase *ProjectItem::referencedClip()
159 void ProjectItem::slotSetToolTip()
162 if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
163 switch (m_clipType) {
165 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
168 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
171 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
174 tip.append(i18n("Color clip"));
177 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
180 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
181 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
184 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
187 tip.append(i18n("Virtual clip"));
190 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
193 tip.append(i18n("Unknown clip"));
201 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
203 if (m_clip == NULL) return;
204 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
205 if (attributes.contains("duration")) {
206 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
207 setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
208 m_clip->setDuration(duration);
210 // No duration known, use an arbitrary one until it is.
214 //extend attributes -reh
216 if (m_clipType == UNKNOWN) {
217 QString cliptype = attributes.value("type");
218 if (cliptype == "audio") m_clipType = AUDIO;
219 else if (cliptype == "video") m_clipType = VIDEO;
220 else if (cliptype == "av") m_clipType = AV;
221 else if (cliptype == "playlist") m_clipType = PLAYLIST;
222 else m_clipType = AV;
224 m_clip->setClipType(m_clipType);
227 m_clip->setProperties(attributes);
228 m_clip->setMetadata(metadata);
230 if (m_clip->description().isEmpty()) {
231 if (metadata.contains("description")) {
232 m_clip->setProperty("description", metadata.value("description"));
233 setText(1, m_clip->description());
234 } else if (metadata.contains("comment")) {
235 m_clip->setProperty("description", metadata.value("comment"));
236 setText(1, m_clip->description());