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