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