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"));
48 //kDebug() << "Constructed as folder, with clipId: " << m_clipId << ", and groupname: " << m_groupname;
51 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
52 : QTreeWidgetItem(parent) {
53 setSizeHint(0, QSize(65, 45));
54 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
56 m_clipId = clip->getId();
57 QString name = m_clip->getProperty("name");
58 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
59 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
60 if (m_clipType != UNKNOWN) slotSetToolTip();
62 setText(2, m_clip->description());
63 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
64 //setFlags(Qt::NoItemFlags);
65 //kDebug() << "Constructed with clipId: " << m_clipId;
68 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip)
69 : QTreeWidgetItem(parent) {
70 setSizeHint(0, QSize(65, 45));
71 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
73 m_clipId = clip->getId();
74 QString name = m_clip->getProperty("name");
75 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
76 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
78 setText(2, m_clip->description());
79 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
80 //setFlags(Qt::NoItemFlags);
81 //kDebug() << "Constructed with clipId: " << m_clipId;
85 ProjectItem::~ProjectItem() {
88 int ProjectItem::numReferences() const {
89 if (!m_clip) return 0;
90 return m_clip->numReferences();
93 const QString &ProjectItem::clipId() const {
97 CLIPTYPE ProjectItem::clipType() const {
101 int ProjectItem::clipMaxDuration() const {
102 return m_clip->getProperty("duration").toInt();
105 bool ProjectItem::isGroup() const {
106 return m_clipType == FOLDER;
109 QStringList ProjectItem::names() const {
111 result.append(text(0));
112 result.append(text(1));
113 result.append(text(2));
117 QDomElement ProjectItem::toXml() const {
118 return m_clip->toXML();
121 const KUrl ProjectItem::clipUrl() const {
122 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
123 return KUrl(m_clip->getProperty("resource"));
127 void ProjectItem::changeDuration(int frames) {
128 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
131 void ProjectItem::setProperties(QMap <QString, QString> props) {
132 if (m_clip == NULL) return;
133 m_clip->setProperties(props);
136 QString ProjectItem::getClipHash() const {
137 if (m_clip == NULL) return QString();
138 return m_clip->getClipHash();
141 void ProjectItem::setProperty(const QString &key, const QString &value) {
142 if (m_clip == NULL) return;
143 m_clip->setProperty(key, value);
146 void ProjectItem::clearProperty(const QString &key) {
147 if (m_clip == NULL) return;
148 m_clip->clearProperty(key);
151 const QString ProjectItem::groupName() const {
155 void ProjectItem::setGroupName(const QString name) {
160 DocClipBase *ProjectItem::referencedClip() {
164 void ProjectItem::slotSetToolTip() {
165 QString tip = "<qt><b>";
166 switch (m_clipType) {
168 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
171 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
174 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
177 tip.append(i18n("Color clip"));
180 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
183 tip.append(i18n("Text clip"));
186 tip.append(i18n("Slideshow clip"));
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) {
204 if (m_clip == NULL) return;
205 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
206 if (attributes.contains("duration")) {
207 //if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV)
208 //m_clip->setProperty("duration", attributes["duration"]);
209 GenTime duration = GenTime(attributes["duration"].toInt(), KdenliveSettings::project_fps());
210 setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
211 m_clip->setDuration(duration);
212 //kDebug() << "//// LOADED CLIP, DURATIONĂ‚Â SET TO: " << duration.frames(KdenliveSettings::project_fps());
214 // No duration known, use an arbitrary one until it is.
218 //extend attributes -reh
220 if (m_clipType == UNKNOWN) {
221 if (attributes.contains("type")) {
222 if (attributes["type"] == "audio")
224 else if (attributes["type"] == "video")
226 else if (attributes["type"] == "av")
228 else if (attributes["type"] == "playlist")
229 m_clipType = PLAYLIST;
233 m_clip->setClipType(m_clipType);
236 m_clip->setProperties(attributes);
238 if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
240 if (m_clip->description().isEmpty()) {
241 if (metadata.contains("description")) {
242 m_clip->setProperty("description", metadata["description"]);
243 setText(2, m_clip->description());
244 } else if (metadata.contains("comment")) {
245 m_clip->setProperty("description", metadata["comment"]);
246 setText(2, m_clip->description());