]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
clips now respect maximum length
[kdenlive] / src / projectitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include <QMouseEvent>
22 #include <QStylePainter>
23 #include <QLabel>
24 #include <QLayout>
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30
31 #include "projectitem.h"
32 #include "timecode.h"
33
34   const int NameRole = Qt::UserRole;
35   const int DurationRole = NameRole + 1;
36   const int FullPathRole = NameRole + 2;
37   const int ClipTypeRole = NameRole + 3;
38
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)
41 {
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();
50       slotSetToolTip();
51     }
52   }
53 }
54
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)
57 {
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();
66       slotSetToolTip();
67     }
68   }
69 }
70
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))
73 {
74   setSizeHint(0, QSize(65, 45));
75   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
76   setIcon(0, KIcon("folder"));
77 }
78
79 ProjectItem::~ProjectItem()
80 {
81 }
82
83 int ProjectItem::clipId() const
84 {
85   return m_clipId;
86 }
87
88 int ProjectItem::clipMaxDuration() const
89 {
90   return m_element.attribute("duration").toInt();
91 }
92
93 bool ProjectItem::isGroup() const
94 {
95   return m_isGroup;
96 }
97
98 const QString ProjectItem::groupName() const
99 {
100   return m_groupName;
101 }
102
103 QStringList ProjectItem::names() const
104 {
105   QStringList result;
106   result.append(text(0));
107   result.append(text(1));
108   result.append(text(2));
109   return result;
110 }
111
112 QDomElement ProjectItem::toXml() const
113 {
114     return m_element;
115 }
116
117 const KUrl ProjectItem::clipUrl() const
118 {
119     if (m_clipType != DocClipBase::COLOR && m_clipType != DocClipBase::VIRTUAL && m_clipType != DocClipBase::NONE)
120       return KUrl(m_element.attribute("resouce"));
121     else return KUrl();
122 }
123
124
125 void ProjectItem::slotSetToolTip()
126 {
127   QString tip = "<qt><b>";
128   switch (m_clipType) {
129     case 1:
130       tip.append(i18n("Audio clip"));
131       break;
132     case 2:
133       tip.append(i18n("Mute video clip"));
134       break;
135     case 3:
136       tip.append(i18n("Video clip"));
137       break;
138     case 4:
139       tip.append(i18n("Color clip"));
140       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
141       break;
142     case 5:
143       tip.append(i18n("Image clip"));
144       break;
145     case 6:
146       tip.append(i18n("Text clip"));
147       break;
148     case 7:
149       tip.append(i18n("Slideshow clip"));
150       break;
151     case 8:
152       tip.append(i18n("Virtual clip"));
153       break;
154     case 9:
155       tip.append(i18n("Playlist clip"));
156       break;
157     default:
158       tip.append(i18n("Unknown clip"));
159     break;
160   }
161
162   setToolTip(1, tip);
163 }
164
165 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
166 {
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;
172         } else {
173             // No duration known, use an arbitrary one until it is.
174             m_duration = GenTime(0.0);
175             m_durationKnown = false;
176         }
177
178
179         //extend attributes -reh
180
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;
191           } else {
192             m_clipType = DocClipBase::AV;
193           }
194         }
195         slotSetToolTip();
196
197         if (m_element.isNull()) {
198           QDomDocument doc;
199           m_element = doc.createElement("producer");
200           m_element.setAttribute("duration", attributes["duration"].toInt());
201         }
202         m_element.setAttribute("resource", attributes["filename"]);
203         m_element.setAttribute("type", (int) m_clipType);
204 /*
205         if (attributes.contains("height")) {
206             m_height = attributes["height"].toInt();
207         } else {
208             m_height = 0;
209         }
210         if (attributes.contains("width")) {
211             m_width = attributes["width"].toInt();
212         } else {
213             m_width = 0;
214         }
215         //decoder name
216         if (attributes.contains("name")) {
217             m_decompressor = attributes["name"];
218         } else {
219             m_decompressor = "n/a";
220         }
221         //video type ntsc/pal
222         if (attributes.contains("system")) {
223             m_system = attributes["system"];
224         } else {
225             m_system = "n/a";
226         }
227         if (attributes.contains("fps")) {
228             m_framesPerSecond = attributes["fps"].toInt();
229         } else {
230             // No frame rate known.
231             m_framesPerSecond = 0;
232         }
233         //audio attributes -reh
234         if (attributes.contains("channels")) {
235             m_channels = attributes["channels"].toInt();
236         } else {
237             m_channels = 0;
238         }
239         if (attributes.contains("format")) {
240             m_format = attributes["format"];
241         } else {
242             m_format = "n/a";
243         }
244         if (attributes.contains("frequency")) {
245             m_frequency = attributes["frequency"].toInt();
246         } else {
247             m_frequency = 0;
248         }
249         if (attributes.contains("videocodec")) {
250             m_videoCodec = attributes["videocodec"];
251         }
252         if (attributes.contains("audiocodec")) {
253             m_audioCodec = attributes["audiocodec"];
254         }
255
256         m_metadata = metadata;
257
258         if (m_metadata.contains("description")) {
259             setDescription (m_metadata["description"]);
260         }
261         else if (m_metadata.contains("comment")) {
262             setDescription (m_metadata["comment"]);
263         }
264 */
265
266 }
267
268 #include "projectitem.moc"