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"
34 const int NameRole = Qt::UserRole;
35 const int DurationRole = NameRole + 1;
36 const int FullPathRole = NameRole + 2;
37 const int ClipTypeRole = NameRole + 3;
39 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
40 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), 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);
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 = (DocClipBase::CLIPTYPE) cType.toInt();
55 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
56 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null)
58 m_element = xml.cloneNode().toElement();
59 setSizeHint(0, QSize(65, 45));
60 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
61 if (!m_element.isNull()) {
62 m_element.setAttribute("id", clipId);
63 QString cType = m_element.attribute("type", QString::null);
64 if (!cType.isEmpty()) {
65 m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
71 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
72 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1))
74 setSizeHint(0, QSize(65, 45));
75 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
76 setIcon(0, KIcon("folder"));
79 ProjectItem::~ProjectItem()
83 int ProjectItem::clipId() const
88 int ProjectItem::clipMaxDuration() const
90 return m_element.attribute("duration").toInt();
93 bool ProjectItem::isGroup() const
98 const QString ProjectItem::groupName() const
103 QStringList ProjectItem::names() const
106 result.append(text(0));
107 result.append(text(1));
108 result.append(text(2));
112 QDomElement ProjectItem::toXml() const
117 const KUrl ProjectItem::clipUrl() const
119 if (m_clipType != DocClipBase::COLOR && m_clipType != DocClipBase::VIRTUAL && m_clipType != DocClipBase::NONE)
120 return KUrl(m_element.attribute("resouce"));
125 void ProjectItem::slotSetToolTip()
127 QString tip = "<qt><b>";
128 switch (m_clipType) {
130 tip.append(i18n("Audio clip"));
133 tip.append(i18n("Mute video clip"));
136 tip.append(i18n("Video clip"));
139 tip.append(i18n("Color clip"));
140 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
143 tip.append(i18n("Image clip"));
146 tip.append(i18n("Text clip"));
149 tip.append(i18n("Slideshow clip"));
152 tip.append(i18n("Virtual clip"));
155 tip.append(i18n("Playlist clip"));
158 tip.append(i18n("Unknown clip"));
165 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
167 if (attributes.contains("duration")) {
168 if (m_clipType == DocClipBase::AUDIO || m_clipType == DocClipBase::VIDEO || m_clipType == DocClipBase::AV) m_element.setAttribute("duration", attributes["duration"].toInt());
169 m_duration = GenTime(attributes["duration"].toInt(), 25);
170 setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
171 m_durationKnown = true;
173 // No duration known, use an arbitrary one until it is.
174 m_duration = GenTime(0.0);
175 m_durationKnown = false;
179 //extend attributes -reh
181 if (m_clipType == DocClipBase::NONE) {
182 if (attributes.contains("type")) {
183 if (attributes["type"] == "audio")
184 m_clipType = DocClipBase::AUDIO;
185 else if (attributes["type"] == "video")
186 m_clipType = DocClipBase::VIDEO;
187 else if (attributes["type"] == "av")
188 m_clipType = DocClipBase::AV;
189 else if (attributes["type"] == "playlist")
190 m_clipType = DocClipBase::PLAYLIST;
192 m_clipType = DocClipBase::AV;
197 if (m_element.isNull()) {
199 m_element = doc.createElement("producer");
200 m_element.setAttribute("duration", attributes["duration"].toInt());
202 m_element.setAttribute("resource", attributes["filename"]);
203 m_element.setAttribute("type", (int) m_clipType);
205 if (attributes.contains("height")) {
206 m_height = attributes["height"].toInt();
210 if (attributes.contains("width")) {
211 m_width = attributes["width"].toInt();
216 if (attributes.contains("name")) {
217 m_decompressor = attributes["name"];
219 m_decompressor = "n/a";
221 //video type ntsc/pal
222 if (attributes.contains("system")) {
223 m_system = attributes["system"];
227 if (attributes.contains("fps")) {
228 m_framesPerSecond = attributes["fps"].toInt();
230 // No frame rate known.
231 m_framesPerSecond = 0;
233 //audio attributes -reh
234 if (attributes.contains("channels")) {
235 m_channels = attributes["channels"].toInt();
239 if (attributes.contains("format")) {
240 m_format = attributes["format"];
244 if (attributes.contains("frequency")) {
245 m_frequency = attributes["frequency"].toInt();
249 if (attributes.contains("videocodec")) {
250 m_videoCodec = attributes["videocodec"];
252 if (attributes.contains("audiocodec")) {
253 m_audioCodec = attributes["audiocodec"];
256 m_metadata = metadata;
258 if (m_metadata.contains("description")) {
259 setDescription (m_metadata["description"]);
261 else if (m_metadata.contains("comment")) {
262 setDescription (m_metadata["comment"]);
268 #include "projectitem.moc"