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