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 //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
64 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip)
65 : QTreeWidgetItem(parent) {
66 setSizeHint(0, QSize(65, 45));
67 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
69 m_clipId = clip->getId();
70 QString name = m_clip->getProperty("name");
71 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
72 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
74 setText(2, m_clip->description());
75 //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
79 ProjectItem::~ProjectItem() {
82 int ProjectItem::numReferences() const {
83 if (!m_clip) return 0;
84 return m_clip->numReferences();
87 const QString &ProjectItem::clipId() const {
91 CLIPTYPE ProjectItem::clipType() const {
95 int ProjectItem::clipMaxDuration() const {
96 return m_clip->getProperty("duration").toInt();
99 bool ProjectItem::isGroup() const {
100 return m_clipType == FOLDER;
103 QStringList ProjectItem::names() const {
105 result.append(text(0));
106 result.append(text(1));
107 result.append(text(2));
111 QDomElement ProjectItem::toXml() const {
112 return m_clip->toXML();
115 const KUrl ProjectItem::clipUrl() const {
116 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
117 return KUrl(m_clip->getProperty("resource"));
121 void ProjectItem::changeDuration(int frames) {
122 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
125 void ProjectItem::setProperties(QMap <QString, QString> props) {
126 if (m_clip == NULL) return;
127 m_clip->setProperties(props);
130 void ProjectItem::setProperty(const QString &key, const QString &value) {
131 if (m_clip == NULL) return;
132 m_clip->setProperty(key, value);
135 void ProjectItem::clearProperty(const QString &key) {
136 if (m_clip == NULL) return;
137 m_clip->clearProperty(key);
140 const QString ProjectItem::groupName() const {
144 void ProjectItem::setGroupName(const QString name) {
149 DocClipBase *ProjectItem::referencedClip() {
153 void ProjectItem::slotSetToolTip() {
154 QString tip = "<qt><b>";
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 tip.append(i18n("Text clip"));
175 tip.append(i18n("Slideshow clip"));
178 tip.append(i18n("Virtual clip"));
181 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
184 tip.append(i18n("Unknown clip"));
192 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
193 if (m_clip == NULL) return;
194 if (attributes.contains("duration")) {
195 //if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV)
196 //m_clip->setProperty("duration", attributes["duration"]);
197 GenTime duration = GenTime(attributes["duration"].toInt(), KdenliveSettings::project_fps());
198 setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
199 m_clip->setDuration(duration);
200 //kDebug() << "//// LOADED CLIP, DURATION SET TO: " << duration.frames(KdenliveSettings::project_fps());
202 // No duration known, use an arbitrary one until it is.
206 //extend attributes -reh
208 if (m_clipType == UNKNOWN) {
209 if (attributes.contains("type")) {
210 if (attributes["type"] == "audio")
212 else if (attributes["type"] == "video")
214 else if (attributes["type"] == "av")
216 else if (attributes["type"] == "playlist")
217 m_clipType = PLAYLIST;
221 m_clip->setClipType(m_clipType);
224 if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->slotRequestAudioThumbs();
226 m_clip->setProperties(attributes);
228 if (m_clip->description().isEmpty()) {
229 if (metadata.contains("description")) {
230 m_clip->setProperty("description", metadata["description"]);
231 setText(2, m_clip->description());
232 } else if (metadata.contains("comment")) {
233 m_clip->setProperty("description", metadata["comment"]);
234 setText(2, m_clip->description());