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