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 m_clip->askForAudioThumbs();
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);
59 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
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 m_clip->askForAudioThumbs();
68 GenTime duration = m_clip->duration();
69 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
70 //setFlags(Qt::NoItemFlags);
71 //kDebug() << "Constructed with clipId: " << m_clipId;
75 ProjectItem::~ProjectItem()
80 int ProjectItem::itemDefaultHeight()
85 int ProjectItem::numReferences() const
87 if (!m_clip) return 0;
88 return m_clip->numReferences();
91 const QString &ProjectItem::clipId() const
96 CLIPTYPE ProjectItem::clipType() const
101 int ProjectItem::clipMaxDuration() const
103 return m_clip->getProperty("duration").toInt();
106 QStringList ProjectItem::names() const
109 result.append(text(0));
110 result.append(text(1));
111 result.append(text(2));
115 QDomElement ProjectItem::toXml() const
117 return m_clip->toXML();
120 const KUrl ProjectItem::clipUrl() const
122 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
123 return KUrl(m_clip->getProperty("resource"));
127 void ProjectItem::changeDuration(int frames)
129 setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
132 void ProjectItem::setProperties(QMap <QString, QString> props)
134 if (m_clip == NULL) return;
135 m_clip->setProperties(props);
138 QString ProjectItem::getClipHash() const
140 if (m_clip == NULL) return QString();
141 return m_clip->getClipHash();
144 void ProjectItem::setProperty(const QString &key, const QString &value)
146 if (m_clip == NULL) return;
147 m_clip->setProperty(key, value);
150 void ProjectItem::clearProperty(const QString &key)
152 if (m_clip == NULL) return;
153 m_clip->clearProperty(key);
156 DocClipBase *ProjectItem::referencedClip()
161 void ProjectItem::slotSetToolTip()
164 if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
165 switch (m_clipType) {
167 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
170 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
173 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
176 tip.append(i18n("Color clip"));
179 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
182 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
183 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
186 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
189 tip.append(i18n("Virtual clip"));
192 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
195 tip.append(i18n("Unknown clip"));
203 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
205 if (m_clip == NULL) return;
206 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
207 if (attributes.contains("duration")) {
208 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
209 setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
210 m_clip->setDuration(duration);
212 // No duration known, use an arbitrary one until it is.
216 //extend attributes -reh
218 if (m_clipType == UNKNOWN) {
219 QString cliptype = attributes.value("type");
220 if (cliptype == "audio") m_clipType = AUDIO;
221 else if (cliptype == "video") m_clipType = VIDEO;
222 else if (cliptype == "av") m_clipType = AV;
223 else if (cliptype == "playlist") m_clipType = PLAYLIST;
224 else m_clipType = AV;
226 m_clip->setClipType(m_clipType);
229 m_clip->setProperties(attributes);
230 m_clip->setMetadata(metadata);
231 m_clip->askForAudioThumbs();
233 if (m_clip->description().isEmpty()) {
234 if (metadata.contains("description")) {
235 m_clip->setProperty("description", metadata.value("description"));
236 setText(1, m_clip->description());
237 } else if (metadata.contains("comment")) {
238 m_clip->setProperty("description", metadata.value("comment"));
239 setText(1, m_clip->description());