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 FullPathRole = NameRole + 2;
38 const int ClipTypeRole = NameRole + 3;
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)
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)
64 m_element = xml.cloneNode().toElement();
65 setSizeHint(0, QSize(65, 45));
66 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
67 if (!m_element.isNull()) {
68 m_element.setAttribute("id", clipId);
69 QString cType = m_element.attribute("type", QString::null);
70 if (!cType.isEmpty()) {
71 m_clipType = (CLIPTYPE) cType.toInt();
77 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
78 : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1))
80 setSizeHint(0, QSize(65, 45));
81 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
82 setIcon(0, KIcon("folder"));
85 ProjectItem::~ProjectItem()
89 int ProjectItem::clipId() const
94 CLIPTYPE ProjectItem::clipType() const
99 int ProjectItem::clipMaxDuration() const
101 return m_element.attribute("duration").toInt();
104 bool ProjectItem::isGroup() const
109 const QString ProjectItem::groupName() const
114 QStringList ProjectItem::names() const
117 result.append(text(0));
118 result.append(text(1));
119 result.append(text(2));
123 QDomElement ProjectItem::toXml() const
128 const KUrl ProjectItem::clipUrl() const
130 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
131 return KUrl(m_element.attribute("resource"));
136 void ProjectItem::slotSetToolTip()
138 QString tip = "<qt><b>";
139 switch (m_clipType) {
141 tip.append(i18n("Audio clip"));
144 tip.append(i18n("Mute video clip"));
147 tip.append(i18n("Video clip"));
150 tip.append(i18n("Color clip"));
151 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
154 tip.append(i18n("Image clip"));
157 tip.append(i18n("Text clip"));
160 tip.append(i18n("Slideshow clip"));
163 tip.append(i18n("Virtual clip"));
166 tip.append(i18n("Playlist clip"));
169 tip.append(i18n("Unknown clip"));
176 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
178 if (attributes.contains("duration")) {
179 if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
180 m_duration = GenTime(attributes["duration"].toInt(), 25);
181 setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
182 m_durationKnown = true;
184 // No duration known, use an arbitrary one until it is.
185 m_duration = GenTime(0.0);
186 m_durationKnown = false;
190 //extend attributes -reh
192 if (m_clipType == UNKNOWN) {
193 if (attributes.contains("type")) {
194 if (attributes["type"] == "audio")
196 else if (attributes["type"] == "video")
198 else if (attributes["type"] == "av")
200 else if (attributes["type"] == "playlist")
201 m_clipType = PLAYLIST;
208 if (m_element.isNull()) {
210 m_element = doc.createElement("producer");
212 if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
213 m_element.setAttribute("resource", attributes["filename"]);
214 m_element.setAttribute("type", (int) m_clipType);
216 if (attributes.contains("height")) {
217 m_height = attributes["height"].toInt();
221 if (attributes.contains("width")) {
222 m_width = attributes["width"].toInt();
227 if (attributes.contains("name")) {
228 m_decompressor = attributes["name"];
230 m_decompressor = "n/a";
232 //video type ntsc/pal
233 if (attributes.contains("system")) {
234 m_system = attributes["system"];
238 if (attributes.contains("fps")) {
239 m_framesPerSecond = attributes["fps"].toInt();
241 // No frame rate known.
242 m_framesPerSecond = 0;
244 //audio attributes -reh
245 if (attributes.contains("channels")) {
246 m_channels = attributes["channels"].toInt();
250 if (attributes.contains("format")) {
251 m_format = attributes["format"];
255 if (attributes.contains("frequency")) {
256 m_frequency = attributes["frequency"].toInt();
260 if (attributes.contains("videocodec")) {
261 m_videoCodec = attributes["videocodec"];
263 if (attributes.contains("audiocodec")) {
264 m_audioCodec = attributes["audiocodec"];
267 m_metadata = metadata;
269 if (m_metadata.contains("description")) {
270 setDescription (m_metadata["description"]);
272 else if (m_metadata.contains("comment")) {
273 setDescription (m_metadata["comment"]);
279 #include "projectitem.moc"