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;
41 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
42 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
43 m_element = xml.cloneNode().toElement();
44 setSizeHint(0, QSize(65, 45));
45 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46 if (!m_element.isNull()) {
47 m_element.setAttribute("id", clipId);
48 QString cType = m_element.attribute("type", QString::null);
49 if (!cType.isEmpty()) {
50 m_clipType = (CLIPTYPE) cType.toInt();
54 if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION);
55 else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) {
56 m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt());
61 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
62 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
63 m_element = xml.cloneNode().toElement();
64 setSizeHint(0, QSize(65, 45));
65 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
66 if (!m_element.isNull()) {
67 m_element.setAttribute("id", clipId);
68 QString cType = m_element.attribute("type", QString::null);
69 if (!cType.isEmpty()) {
70 m_clipType = (CLIPTYPE) cType.toInt();
76 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
77 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1)) {
78 setSizeHint(0, QSize(65, 45));
79 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
80 setIcon(0, KIcon("folder"));
83 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
84 : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) {
85 setSizeHint(0, QSize(65, 45));
86 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
88 m_element = clip->toXML();
89 m_clipId = clip->getId();
90 QString name = m_element.attribute("name");
91 if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
92 m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
93 m_groupName = m_element.attribute("group");
95 kDebug() << "PROJECT ITE;. ADDINGÂ LCIP: " << m_clipId;
99 ProjectItem::~ProjectItem() {
102 int ProjectItem::numReferences() const {
103 if (!m_clip) return 0;
104 return m_clip->numReferences();
107 int ProjectItem::clipId() const {
111 CLIPTYPE ProjectItem::clipType() const {
115 int ProjectItem::clipMaxDuration() const {
116 return m_element.attribute("duration").toInt();
119 bool ProjectItem::isGroup() const {
123 const QString ProjectItem::groupName() const {
127 QStringList ProjectItem::names() const {
129 result.append(text(0));
130 result.append(text(1));
131 result.append(text(2));
135 QDomElement ProjectItem::toXml() const {
139 const KUrl ProjectItem::clipUrl() const {
140 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
141 return KUrl(m_element.attribute("resource"));
146 void ProjectItem::slotSetToolTip() {
147 QString tip = "<qt><b>";
148 switch (m_clipType) {
150 tip.append(i18n("Audio clip"));
153 tip.append(i18n("Mute video clip"));
156 tip.append(i18n("Video clip"));
159 tip.append(i18n("Color clip"));
160 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
163 tip.append(i18n("Image clip"));
166 tip.append(i18n("Text clip"));
169 tip.append(i18n("Slideshow clip"));
172 tip.append(i18n("Virtual clip"));
175 tip.append(i18n("Playlist clip"));
178 tip.append(i18n("Unknown clip"));
185 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
186 if (attributes.contains("duration")) {
187 if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
188 m_duration = GenTime(attributes["duration"].toInt(), 25);
189 setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
190 m_durationKnown = true;
191 m_clip->setDuration(m_duration);
192 kDebug() << "//// LOADED CLIP, DURATIONÂ SET TO: " << m_duration.frames(25);
194 // No duration known, use an arbitrary one until it is.
195 m_duration = GenTime(0.0);
196 m_durationKnown = false;
200 //extend attributes -reh
202 if (m_clipType == UNKNOWN) {
203 if (attributes.contains("type")) {
204 if (attributes["type"] == "audio")
206 else if (attributes["type"] == "video")
208 else if (attributes["type"] == "av")
210 else if (attributes["type"] == "playlist")
211 m_clipType = PLAYLIST;
215 m_clip->setClipType(m_clipType);
218 if (m_element.isNull()) {
220 m_element = doc.createElement("producer");
222 if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
223 m_element.setAttribute("resource", attributes["filename"]);
224 m_element.setAttribute("type", (int) m_clipType);
226 if (KdenliveSettings::audiothumbnails()) m_clip->slotRequestAudioThumbs();
228 if (attributes.contains("height")) {
229 m_height = attributes["height"].toInt();
233 if (attributes.contains("width")) {
234 m_width = attributes["width"].toInt();
239 if (attributes.contains("name")) {
240 m_decompressor = attributes["name"];
242 m_decompressor = "n/a";
244 //video type ntsc/pal
245 if (attributes.contains("system")) {
246 m_system = attributes["system"];
250 if (attributes.contains("fps")) {
251 m_framesPerSecond = attributes["fps"].toInt();
253 // No frame rate known.
254 m_framesPerSecond = 0;
256 //audio attributes -reh
257 if (attributes.contains("channels")) {
258 m_channels = attributes["channels"].toInt();
262 if (attributes.contains("format")) {
263 m_format = attributes["format"];
267 if (attributes.contains("frequency")) {
268 m_frequency = attributes["frequency"].toInt();
272 if (attributes.contains("videocodec")) {
273 m_videoCodec = attributes["videocodec"];
275 if (attributes.contains("audiocodec")) {
276 m_audioCodec = attributes["audiocodec"];
279 m_metadata = metadata;
281 if (m_metadata.contains("description")) {
282 setDescription (m_metadata["description"]);
284 else if (m_metadata.contains("comment")) {
285 setDescription (m_metadata["comment"]);
291 #include "projectitem.moc"