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