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 <QMouseEvent>
22 #include <QStylePainter>
31 #include "projectitem.h"
33 #include "kdenlivesettings.h"
34 #include "docclipbase.h"
36 const int NameRole = Qt::UserRole;
37 const int DurationRole = NameRole + 1;
38 const int UsageRole = NameRole + 2;
42 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, const QString &clipId)
43 : QTreeWidgetItem(parent, strings), m_clipType(FOLDER), m_clipId(clipId), m_clip(NULL), m_groupname(strings.at(1)) {
44 setSizeHint(0, QSize(65, 45));
45 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46 setIcon(0, KIcon("folder"));
47 setToolTip(1, "<qt><b>" + i18n("Folder"));
50 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
51 : QTreeWidgetItem(parent) {
52 setSizeHint(0, QSize(65, 45));
53 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
55 m_clipId = clip->getId();
56 QString name = m_clip->getProperty("name");
57 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
58 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
60 setText(2, m_clip->description());
61 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
62 //setFlags(Qt::NoItemFlags);
63 //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
66 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip)
67 : QTreeWidgetItem(parent) {
68 setSizeHint(0, QSize(65, 45));
69 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
71 m_clipId = clip->getId();
72 QString name = m_clip->getProperty("name");
73 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
74 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
76 setText(2, m_clip->description());
77 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
78 //setFlags(Qt::NoItemFlags);
79 //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
83 ProjectItem::~ProjectItem() {
86 int ProjectItem::numReferences() const {
87 if (!m_clip) return 0;
88 return m_clip->numReferences();
91 const QString &ProjectItem::clipId() const {
95 CLIPTYPE ProjectItem::clipType() const {
99 int ProjectItem::clipMaxDuration() const {
100 return m_clip->getProperty("duration").toInt();
103 bool ProjectItem::isGroup() const {
104 return m_clipType == FOLDER;
107 QStringList ProjectItem::names() const {
109 result.append(text(0));
110 result.append(text(1));
111 result.append(text(2));
115 QDomElement ProjectItem::toXml() const {
116 return m_clip->toXML();
119 const KUrl ProjectItem::clipUrl() const {
120 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
121 return KUrl(m_clip->getProperty("resource"));
125 void ProjectItem::changeDuration(int frames) {
126 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
129 void ProjectItem::setProperties(QMap <QString, QString> props) {
130 if (m_clip == NULL) return;
131 m_clip->setProperties(props);
134 void ProjectItem::setProperty(const QString &key, const QString &value) {
135 if (m_clip == NULL) return;
136 m_clip->setProperty(key, value);
139 void ProjectItem::clearProperty(const QString &key) {
140 if (m_clip == NULL) return;
141 m_clip->clearProperty(key);
144 const QString ProjectItem::groupName() const {
148 void ProjectItem::setGroupName(const QString name) {
153 DocClipBase *ProjectItem::referencedClip() {
157 void ProjectItem::slotSetToolTip() {
158 QString tip = "<qt><b>";
159 switch (m_clipType) {
161 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
164 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
167 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
170 tip.append(i18n("Color clip"));
173 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
176 tip.append(i18n("Text clip"));
179 tip.append(i18n("Slideshow clip"));
182 tip.append(i18n("Virtual clip"));
185 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
188 tip.append(i18n("Unknown clip"));
196 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
197 if (m_clip == NULL) return;
198 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
199 if (attributes.contains("duration")) {
200 //if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV)
201 //m_clip->setProperty("duration", attributes["duration"]);
202 GenTime duration = GenTime(attributes["duration"].toInt(), KdenliveSettings::project_fps());
203 setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
204 m_clip->setDuration(duration);
205 //kDebug() << "//// LOADED CLIP, DURATION SET TO: " << duration.frames(KdenliveSettings::project_fps());
207 // No duration known, use an arbitrary one until it is.
211 //extend attributes -reh
213 if (m_clipType == UNKNOWN) {
214 if (attributes.contains("type")) {
215 if (attributes["type"] == "audio")
217 else if (attributes["type"] == "video")
219 else if (attributes["type"] == "av")
221 else if (attributes["type"] == "playlist")
222 m_clipType = PLAYLIST;
226 m_clip->setClipType(m_clipType);
229 m_clip->setProperties(attributes);
231 if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
233 if (m_clip->description().isEmpty()) {
234 if (metadata.contains("description")) {
235 m_clip->setProperty("description", metadata["description"]);
236 setText(2, m_clip->description());
237 } else if (metadata.contains("comment")) {
238 m_clip->setProperty("description", metadata["comment"]);
239 setText(2, m_clip->description());