]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Start of image clips
[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 FullPathRole = NameRole + 2;
38   const int ClipTypeRole = NameRole + 3;
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);
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);
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);
82   setIcon(0, KIcon("folder"));
83 }
84
85 ProjectItem::~ProjectItem()
86 {
87 }
88
89 int ProjectItem::clipId() const
90 {
91   return m_clipId;
92 }
93
94 int ProjectItem::clipMaxDuration() const
95 {
96   return m_element.attribute("duration").toInt();
97 }
98
99 bool ProjectItem::isGroup() const
100 {
101   return m_isGroup;
102 }
103
104 const QString ProjectItem::groupName() const
105 {
106   return m_groupName;
107 }
108
109 QStringList ProjectItem::names() const
110 {
111   QStringList result;
112   result.append(text(0));
113   result.append(text(1));
114   result.append(text(2));
115   return result;
116 }
117
118 QDomElement ProjectItem::toXml() const
119 {
120     return m_element;
121 }
122
123 const KUrl ProjectItem::clipUrl() const
124 {
125     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
126       return KUrl(m_element.attribute("resouce"));
127     else return KUrl();
128 }
129
130
131 void ProjectItem::slotSetToolTip()
132 {
133   QString tip = "<qt><b>";
134   switch (m_clipType) {
135     case 1:
136       tip.append(i18n("Audio clip"));
137       break;
138     case 2:
139       tip.append(i18n("Mute video clip"));
140       break;
141     case 3:
142       tip.append(i18n("Video clip"));
143       break;
144     case 4:
145       tip.append(i18n("Color clip"));
146       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
147       break;
148     case 5:
149       tip.append(i18n("Image clip"));
150       break;
151     case 6:
152       tip.append(i18n("Text clip"));
153       break;
154     case 7:
155       tip.append(i18n("Slideshow clip"));
156       break;
157     case 8:
158       tip.append(i18n("Virtual clip"));
159       break;
160     case 9:
161       tip.append(i18n("Playlist clip"));
162       break;
163     default:
164       tip.append(i18n("Unknown clip"));
165     break;
166   }
167
168   setToolTip(1, tip);
169 }
170
171 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
172 {
173         if (attributes.contains("duration")) {
174             if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
175             m_duration = GenTime(attributes["duration"].toInt(), 25);
176             setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
177             m_durationKnown = true;
178         } else {
179             // No duration known, use an arbitrary one until it is.
180             m_duration = GenTime(0.0);
181             m_durationKnown = false;
182         }
183
184
185         //extend attributes -reh
186
187         if (m_clipType == UNKNOWN) {
188           if (attributes.contains("type")) {
189             if (attributes["type"] == "audio")
190                 m_clipType = AUDIO;
191             else if (attributes["type"] == "video")
192                 m_clipType = VIDEO;
193             else if (attributes["type"] == "av")
194                 m_clipType = AV;
195             else if (attributes["type"] == "playlist")
196                 m_clipType = PLAYLIST;
197           } else {
198             m_clipType = AV;
199           }
200         }
201         slotSetToolTip();
202
203         if (m_element.isNull()) {
204           QDomDocument doc;
205           m_element = doc.createElement("producer");
206         }
207         if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
208         m_element.setAttribute("resource", attributes["filename"]);
209         m_element.setAttribute("type", (int) m_clipType);
210 /*
211         if (attributes.contains("height")) {
212             m_height = attributes["height"].toInt();
213         } else {
214             m_height = 0;
215         }
216         if (attributes.contains("width")) {
217             m_width = attributes["width"].toInt();
218         } else {
219             m_width = 0;
220         }
221         //decoder name
222         if (attributes.contains("name")) {
223             m_decompressor = attributes["name"];
224         } else {
225             m_decompressor = "n/a";
226         }
227         //video type ntsc/pal
228         if (attributes.contains("system")) {
229             m_system = attributes["system"];
230         } else {
231             m_system = "n/a";
232         }
233         if (attributes.contains("fps")) {
234             m_framesPerSecond = attributes["fps"].toInt();
235         } else {
236             // No frame rate known.
237             m_framesPerSecond = 0;
238         }
239         //audio attributes -reh
240         if (attributes.contains("channels")) {
241             m_channels = attributes["channels"].toInt();
242         } else {
243             m_channels = 0;
244         }
245         if (attributes.contains("format")) {
246             m_format = attributes["format"];
247         } else {
248             m_format = "n/a";
249         }
250         if (attributes.contains("frequency")) {
251             m_frequency = attributes["frequency"].toInt();
252         } else {
253             m_frequency = 0;
254         }
255         if (attributes.contains("videocodec")) {
256             m_videoCodec = attributes["videocodec"];
257         }
258         if (attributes.contains("audiocodec")) {
259             m_audioCodec = attributes["audiocodec"];
260         }
261
262         m_metadata = metadata;
263
264         if (m_metadata.contains("description")) {
265             setDescription (m_metadata["description"]);
266         }
267         else if (m_metadata.contains("comment")) {
268             setDescription (m_metadata["comment"]);
269         }
270 */
271
272 }
273
274 #include "projectitem.moc"