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