]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
start implementing folders in project view
[kdenlive] / src / projectitem.cpp
1
2 #include <QMouseEvent>
3 #include <QStylePainter>
4 #include <QLabel>
5 #include <QLayout>
6
7 #include <KDebug>
8 #include <KLocale>
9 #include <KIcon>
10
11
12 #include "projectitem.h"
13 #include "timecode.h"
14
15   const int NameRole = Qt::UserRole;
16   const int DurationRole = NameRole + 1;
17   const int FullPathRole = NameRole + 2;
18   const int ClipTypeRole = NameRole + 3;
19
20 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
21     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false)
22 {
23   m_element = xml.cloneNode().toElement();
24   setSizeHint(0, QSize(65, 45));
25   setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
26   if (!m_element.isNull()) {
27     m_element.setAttribute("id", clipId);
28     QString cType = m_element.attribute("type", QString::null);
29     if (!cType.isEmpty()) {
30       m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
31       slotSetToolTip();
32     }
33   }
34 }
35
36 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
37     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false)
38 {
39   m_element = xml.cloneNode().toElement();
40   setSizeHint(0, QSize(65, 45));
41   setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
42   if (!m_element.isNull()) {
43     m_element.setAttribute("id", clipId);
44     QString cType = m_element.attribute("type", QString::null);
45     if (!cType.isEmpty()) {
46       m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
47       slotSetToolTip();
48     }
49   }
50 }
51
52 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings)
53     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(DocClipBase::NONE), m_clipId(-1), m_isGroup(true)
54 {
55   setSizeHint(0, QSize(65, 45));
56   setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
57   setIcon(0, KIcon("folder"));
58 }
59
60 ProjectItem::~ProjectItem()
61 {
62 }
63
64 int ProjectItem::clipId()
65 {
66   return m_clipId;
67 }
68
69 bool ProjectItem::isGroup()
70 {
71   return m_isGroup;
72 }
73
74
75 QStringList ProjectItem::names()
76 {
77   QStringList result;
78   result.append(text(0));
79   result.append(text(1));
80   result.append(text(2));
81   return result;
82 }
83
84 QDomElement ProjectItem::toXml()
85 {
86     return m_element;
87 }
88
89 void ProjectItem::slotSetToolTip()
90 {
91   QString tip = "<qt><b>";
92   switch (m_clipType) {
93     case 1:
94       tip.append(i18n("Audio clip"));
95       break;
96     case 2:
97       tip.append(i18n("Mute video clip"));
98       break;
99     case 3:
100       tip.append(i18n("Video clip"));
101       break;
102     case 4:
103       tip.append(i18n("Color clip"));
104       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
105       break;
106     case 5:
107       tip.append(i18n("Image clip"));
108       break;
109     case 6:
110       tip.append(i18n("Text clip"));
111       break;
112     case 7:
113       tip.append(i18n("Slideshow clip"));
114       break;
115     case 8:
116       tip.append(i18n("Virtual clip"));
117       break;
118     case 9:
119       tip.append(i18n("Playlist clip"));
120       break;
121     default:
122       tip.append(i18n("Unknown clip"));
123     break;
124   }
125
126   setToolTip(1, tip);
127 }
128
129 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
130 {
131         if (attributes.contains("duration")) {
132             m_duration = GenTime(attributes["duration"].toInt(), 25);
133             setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
134             m_durationKnown = true;
135         } else {
136             // No duration known, use an arbitrary one until it is.
137             m_duration = GenTime(0.0);
138             m_durationKnown = false;
139         }
140
141
142         //extend attributes -reh
143
144         if (m_clipType == DocClipBase::NONE) {
145           if (attributes.contains("type")) {
146             if (attributes["type"] == "audio")
147                 m_clipType = DocClipBase::AUDIO;
148             else if (attributes["type"] == "video")
149                 m_clipType = DocClipBase::VIDEO;
150             else if (attributes["type"] == "av")
151                 m_clipType = DocClipBase::AV;
152             else if (attributes["type"] == "playlist")
153                 m_clipType = DocClipBase::PLAYLIST;
154           } else {
155             m_clipType = DocClipBase::AV;
156           }
157         }
158         slotSetToolTip();
159
160         if (m_element.isNull()) {
161           QDomDocument doc;
162           m_element = doc.createElement("producer");
163         }
164         m_element.setAttribute("resource", attributes["filename"]);
165         m_element.setAttribute("type", (int) m_clipType);
166 /*
167         if (attributes.contains("height")) {
168             m_height = attributes["height"].toInt();
169         } else {
170             m_height = 0;
171         }
172         if (attributes.contains("width")) {
173             m_width = attributes["width"].toInt();
174         } else {
175             m_width = 0;
176         }
177         //decoder name
178         if (attributes.contains("name")) {
179             m_decompressor = attributes["name"];
180         } else {
181             m_decompressor = "n/a";
182         }
183         //video type ntsc/pal
184         if (attributes.contains("system")) {
185             m_system = attributes["system"];
186         } else {
187             m_system = "n/a";
188         }
189         if (attributes.contains("fps")) {
190             m_framesPerSecond = attributes["fps"].toInt();
191         } else {
192             // No frame rate known.
193             m_framesPerSecond = 0;
194         }
195         //audio attributes -reh
196         if (attributes.contains("channels")) {
197             m_channels = attributes["channels"].toInt();
198         } else {
199             m_channels = 0;
200         }
201         if (attributes.contains("format")) {
202             m_format = attributes["format"];
203         } else {
204             m_format = "n/a";
205         }
206         if (attributes.contains("frequency")) {
207             m_frequency = attributes["frequency"].toInt();
208         } else {
209             m_frequency = 0;
210         }
211         if (attributes.contains("videocodec")) {
212             m_videoCodec = attributes["videocodec"];
213         }
214         if (attributes.contains("audiocodec")) {
215             m_audioCodec = attributes["audiocodec"];
216         }
217
218         m_metadata = metadata;
219
220         if (m_metadata.contains("description")) {
221             setDescription (m_metadata["description"]);
222         }
223         else if (m_metadata.contains("comment")) {
224             setDescription (m_metadata["comment"]);
225         }
226 */
227
228 }
229
230 #include "projectitem.moc"