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