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"
35 const int NameRole = Qt::UserRole;
36 const int DurationRole = NameRole + 1;
37 const int UsageRole = NameRole + 2;
40 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
41 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
42 m_element = xml.cloneNode().toElement();
43 setSizeHint(0, QSize(65, 45));
44 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
45 if (!m_element.isNull()) {
46 m_element.setAttribute("id", clipId);
47 QString cType = m_element.attribute("type", QString::null);
48 if (!cType.isEmpty()) {
49 m_clipType = (CLIPTYPE) cType.toInt();
53 if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION);
54 else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) {
55 m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt());
60 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
61 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
62 m_element = xml.cloneNode().toElement();
63 setSizeHint(0, QSize(65, 45));
64 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
65 if (!m_element.isNull()) {
66 m_element.setAttribute("id", clipId);
67 QString cType = m_element.attribute("type", QString::null);
68 if (!cType.isEmpty()) {
69 m_clipType = (CLIPTYPE) cType.toInt();
75 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
76 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1)) {
77 setSizeHint(0, QSize(65, 45));
78 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
79 setIcon(0, KIcon("folder"));
82 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
83 : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) {
84 setSizeHint(0, QSize(65, 45));
85 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
87 m_element = clip->toXML();
88 m_clipId = clip->getId();
89 QString name = m_element.attribute("name");
90 if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
91 m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
92 m_groupName = m_element.attribute("group");
94 kDebug() << "PROJECT ITE;. ADDINGÂ LCIP: " << m_clipId;
98 ProjectItem::~ProjectItem() {
101 int ProjectItem::numReferences() const {
102 if (!m_clip) return 0;
103 return m_clip->numReferences();
106 int ProjectItem::clipId() const {
110 CLIPTYPE ProjectItem::clipType() const {
114 int ProjectItem::clipMaxDuration() const {
115 return m_element.attribute("duration").toInt();
118 bool ProjectItem::isGroup() const {
122 const QString ProjectItem::groupName() const {
126 QStringList ProjectItem::names() const {
128 result.append(text(0));
129 result.append(text(1));
130 result.append(text(2));
134 QDomElement ProjectItem::toXml() const {
138 const KUrl ProjectItem::clipUrl() const {
139 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
140 return KUrl(m_element.attribute("resource"));
145 void ProjectItem::slotSetToolTip() {
146 QString tip = "<qt><b>";
147 switch (m_clipType) {
149 tip.append(i18n("Audio clip"));
152 tip.append(i18n("Mute video clip"));
155 tip.append(i18n("Video clip"));
158 tip.append(i18n("Color clip"));
159 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
162 tip.append(i18n("Image clip"));
165 tip.append(i18n("Text clip"));
168 tip.append(i18n("Slideshow clip"));
171 tip.append(i18n("Virtual clip"));
174 tip.append(i18n("Playlist clip"));
177 tip.append(i18n("Unknown clip"));
184 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
185 if (attributes.contains("duration")) {
186 if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
187 m_duration = GenTime(attributes["duration"].toInt(), 25);
188 setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
189 m_durationKnown = true;
190 m_clip->setDuration(m_duration);
191 kDebug() << "//// LOADED CLIP, DURATIONÂ SET TO: " << m_duration.frames(25);
193 // No duration known, use an arbitrary one until it is.
194 m_duration = GenTime(0.0);
195 m_durationKnown = false;
199 //extend attributes -reh
201 if (m_clipType == UNKNOWN) {
202 if (attributes.contains("type")) {
203 if (attributes["type"] == "audio")
205 else if (attributes["type"] == "video")
207 else if (attributes["type"] == "av")
209 else if (attributes["type"] == "playlist")
210 m_clipType = PLAYLIST;
214 m_clip->setClipType(m_clipType);
217 if (m_element.isNull()) {
219 m_element = doc.createElement("producer");
221 if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
222 m_element.setAttribute("resource", attributes["filename"]);
223 m_element.setAttribute("type", (int) m_clipType);
225 m_clip->slotRequestAudioThumbs();
227 if (attributes.contains("height")) {
228 m_height = attributes["height"].toInt();
232 if (attributes.contains("width")) {
233 m_width = attributes["width"].toInt();
238 if (attributes.contains("name")) {
239 m_decompressor = attributes["name"];
241 m_decompressor = "n/a";
243 //video type ntsc/pal
244 if (attributes.contains("system")) {
245 m_system = attributes["system"];
249 if (attributes.contains("fps")) {
250 m_framesPerSecond = attributes["fps"].toInt();
252 // No frame rate known.
253 m_framesPerSecond = 0;
255 //audio attributes -reh
256 if (attributes.contains("channels")) {
257 m_channels = attributes["channels"].toInt();
261 if (attributes.contains("format")) {
262 m_format = attributes["format"];
266 if (attributes.contains("frequency")) {
267 m_frequency = attributes["frequency"].toInt();
271 if (attributes.contains("videocodec")) {
272 m_videoCodec = attributes["videocodec"];
274 if (attributes.contains("audiocodec")) {
275 m_audioCodec = attributes["audiocodec"];
278 m_metadata = metadata;
280 if (m_metadata.contains("description")) {
281 setDescription (m_metadata["description"]);
283 else if (m_metadata.contains("comment")) {
284 setDescription (m_metadata["comment"]);
290 #include "projectitem.moc"