]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Display clip usage
[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
35   const int NameRole = Qt::UserRole;
36   const int DurationRole = NameRole + 1;
37   const int UsageRole = NameRole + 2;
38
39
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 {
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();
51       slotSetToolTip();
52     }
53
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());
57     }
58   }
59 }
60
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 {
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();
72       slotSetToolTip();
73     }
74   }
75 }
76
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))
79 {
80   setSizeHint(0, QSize(65, 45));
81   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
82   setIcon(0, KIcon("folder"));
83 }
84
85 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
86     : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false)
87 {
88   setSizeHint(0, QSize(65, 45));
89   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
90   m_clip = clip;
91   m_element = clip->toXML();
92   m_clipId = clip->getId();
93   QString name = m_element.attribute("name");
94   if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
95   m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
96   m_groupName = m_element.attribute("group");
97   setText(1, name);
98   kDebug()<<"PROJECT ITE;. ADDING LCIP: "<< m_clipId;
99 }
100
101
102 ProjectItem::~ProjectItem()
103 {
104 }
105
106 int ProjectItem::numReferences() const
107 {
108   if (!m_clip) return 0;
109   return m_clip->numReferences();
110 }
111
112 int ProjectItem::clipId() const
113 {
114   return m_clipId;
115 }
116
117 CLIPTYPE ProjectItem::clipType() const
118 {
119  return m_clipType;
120 }
121
122 int ProjectItem::clipMaxDuration() const
123 {
124   return m_element.attribute("duration").toInt();
125 }
126
127 bool ProjectItem::isGroup() const
128 {
129   return m_isGroup;
130 }
131
132 const QString ProjectItem::groupName() const
133 {
134   return m_groupName;
135 }
136
137 QStringList ProjectItem::names() const
138 {
139   QStringList result;
140   result.append(text(0));
141   result.append(text(1));
142   result.append(text(2));
143   return result;
144 }
145
146 QDomElement ProjectItem::toXml() const
147 {
148     return m_element;
149 }
150
151 const KUrl ProjectItem::clipUrl() const
152 {
153     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
154       return KUrl(m_element.attribute("resource"));
155     else return KUrl();
156 }
157
158
159 void ProjectItem::slotSetToolTip()
160 {
161   QString tip = "<qt><b>";
162   switch (m_clipType) {
163     case 1:
164       tip.append(i18n("Audio clip"));
165       break;
166     case 2:
167       tip.append(i18n("Mute video clip"));
168       break;
169     case 3:
170       tip.append(i18n("Video clip"));
171       break;
172     case 4:
173       tip.append(i18n("Color clip"));
174       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
175       break;
176     case 5:
177       tip.append(i18n("Image clip"));
178       break;
179     case 6:
180       tip.append(i18n("Text clip"));
181       break;
182     case 7:
183       tip.append(i18n("Slideshow clip"));
184       break;
185     case 8:
186       tip.append(i18n("Virtual clip"));
187       break;
188     case 9:
189       tip.append(i18n("Playlist clip"));
190       break;
191     default:
192       tip.append(i18n("Unknown clip"));
193     break;
194   }
195
196   setToolTip(1, tip);
197 }
198
199 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
200 {
201   if (attributes.contains("duration")) {
202     if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
203     m_duration = GenTime(attributes["duration"].toInt(), 25);
204     setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
205     m_durationKnown = true;
206     m_clip->setDuration(m_duration);
207     kDebug()<<"//// LOADED CLIP, DURATION SET TO: "<<m_duration.frames(25);
208   } else {
209             // No duration known, use an arbitrary one until it is.
210             m_duration = GenTime(0.0);
211             m_durationKnown = false;
212         }
213
214
215         //extend attributes -reh
216
217   if (m_clipType == UNKNOWN) {
218           if (attributes.contains("type")) {
219             if (attributes["type"] == "audio")
220                 m_clipType = AUDIO;
221             else if (attributes["type"] == "video")
222                 m_clipType = VIDEO;
223             else if (attributes["type"] == "av")
224                 m_clipType = AV;
225             else if (attributes["type"] == "playlist")
226                 m_clipType = PLAYLIST;
227           } else {
228             m_clipType = AV;
229           }
230         m_clip->setClipType(m_clipType);
231         }
232         slotSetToolTip();
233
234         if (m_element.isNull()) {
235           QDomDocument doc;
236           m_element = doc.createElement("producer");
237         }
238         if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
239         m_element.setAttribute("resource", attributes["filename"]);
240         m_element.setAttribute("type", (int) m_clipType);
241 /*
242         if (attributes.contains("height")) {
243             m_height = attributes["height"].toInt();
244         } else {
245             m_height = 0;
246         }
247         if (attributes.contains("width")) {
248             m_width = attributes["width"].toInt();
249         } else {
250             m_width = 0;
251         }
252         //decoder name
253         if (attributes.contains("name")) {
254             m_decompressor = attributes["name"];
255         } else {
256             m_decompressor = "n/a";
257         }
258         //video type ntsc/pal
259         if (attributes.contains("system")) {
260             m_system = attributes["system"];
261         } else {
262             m_system = "n/a";
263         }
264         if (attributes.contains("fps")) {
265             m_framesPerSecond = attributes["fps"].toInt();
266         } else {
267             // No frame rate known.
268             m_framesPerSecond = 0;
269         }
270         //audio attributes -reh
271         if (attributes.contains("channels")) {
272             m_channels = attributes["channels"].toInt();
273         } else {
274             m_channels = 0;
275         }
276         if (attributes.contains("format")) {
277             m_format = attributes["format"];
278         } else {
279             m_format = "n/a";
280         }
281         if (attributes.contains("frequency")) {
282             m_frequency = attributes["frequency"].toInt();
283         } else {
284             m_frequency = 0;
285         }
286         if (attributes.contains("videocodec")) {
287             m_videoCodec = attributes["videocodec"];
288         }
289         if (attributes.contains("audiocodec")) {
290             m_audioCodec = attributes["audiocodec"];
291         }
292
293         m_metadata = metadata;
294
295         if (m_metadata.contains("description")) {
296             setDescription (m_metadata["description"]);
297         }
298         else if (m_metadata.contains("comment")) {
299             setDescription (m_metadata["comment"]);
300         }
301 */
302
303 }
304
305 #include "projectitem.moc"