]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
add context menu
[kdenlive] / src / projectitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include <QMouseEvent>
22 #include <QStylePainter>
23 #include <QLabel>
24 #include <QLayout>
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30
31 #include "projectitem.h"
32 #include "timecode.h"
33
34   const int NameRole = Qt::UserRole;
35   const int DurationRole = NameRole + 1;
36   const int FullPathRole = NameRole + 2;
37   const int ClipTypeRole = NameRole + 3;
38
39 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
40     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false)
41 {
42   m_element = xml.cloneNode().toElement();
43   setSizeHint(0, QSize(65, 45));
44   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
45   if (!m_element.isNull()) {
46     m_element.setAttribute("id", clipId);
47     QString cType = m_element.attribute("type", QString::null);
48     if (!cType.isEmpty()) {
49       m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
50       slotSetToolTip();
51     }
52   }
53 }
54
55 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
56     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false)
57 {
58   m_element = xml.cloneNode().toElement();
59   setSizeHint(0, QSize(65, 45));
60   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
61   if (!m_element.isNull()) {
62     m_element.setAttribute("id", clipId);
63     QString cType = m_element.attribute("type", QString::null);
64     if (!cType.isEmpty()) {
65       m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
66       slotSetToolTip();
67     }
68   }
69 }
70
71 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings)
72     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(DocClipBase::NONE), m_clipId(-1), m_isGroup(true)
73 {
74   setSizeHint(0, QSize(65, 45));
75   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
76   setIcon(0, KIcon("folder"));
77 }
78
79 ProjectItem::~ProjectItem()
80 {
81 }
82
83 int ProjectItem::clipId()
84 {
85   return m_clipId;
86 }
87
88 bool ProjectItem::isGroup()
89 {
90   return m_isGroup;
91 }
92
93
94 QStringList ProjectItem::names()
95 {
96   QStringList result;
97   result.append(text(0));
98   result.append(text(1));
99   result.append(text(2));
100   return result;
101 }
102
103 QDomElement ProjectItem::toXml()
104 {
105     return m_element;
106 }
107
108 void ProjectItem::slotSetToolTip()
109 {
110   QString tip = "<qt><b>";
111   switch (m_clipType) {
112     case 1:
113       tip.append(i18n("Audio clip"));
114       break;
115     case 2:
116       tip.append(i18n("Mute video clip"));
117       break;
118     case 3:
119       tip.append(i18n("Video clip"));
120       break;
121     case 4:
122       tip.append(i18n("Color clip"));
123       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
124       break;
125     case 5:
126       tip.append(i18n("Image clip"));
127       break;
128     case 6:
129       tip.append(i18n("Text clip"));
130       break;
131     case 7:
132       tip.append(i18n("Slideshow clip"));
133       break;
134     case 8:
135       tip.append(i18n("Virtual clip"));
136       break;
137     case 9:
138       tip.append(i18n("Playlist clip"));
139       break;
140     default:
141       tip.append(i18n("Unknown clip"));
142     break;
143   }
144
145   setToolTip(1, tip);
146 }
147
148 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
149 {
150         if (attributes.contains("duration")) {
151             m_duration = GenTime(attributes["duration"].toInt(), 25);
152             setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
153             m_durationKnown = true;
154         } else {
155             // No duration known, use an arbitrary one until it is.
156             m_duration = GenTime(0.0);
157             m_durationKnown = false;
158         }
159
160
161         //extend attributes -reh
162
163         if (m_clipType == DocClipBase::NONE) {
164           if (attributes.contains("type")) {
165             if (attributes["type"] == "audio")
166                 m_clipType = DocClipBase::AUDIO;
167             else if (attributes["type"] == "video")
168                 m_clipType = DocClipBase::VIDEO;
169             else if (attributes["type"] == "av")
170                 m_clipType = DocClipBase::AV;
171             else if (attributes["type"] == "playlist")
172                 m_clipType = DocClipBase::PLAYLIST;
173           } else {
174             m_clipType = DocClipBase::AV;
175           }
176         }
177         slotSetToolTip();
178
179         if (m_element.isNull()) {
180           QDomDocument doc;
181           m_element = doc.createElement("producer");
182         }
183         m_element.setAttribute("resource", attributes["filename"]);
184         m_element.setAttribute("type", (int) m_clipType);
185 /*
186         if (attributes.contains("height")) {
187             m_height = attributes["height"].toInt();
188         } else {
189             m_height = 0;
190         }
191         if (attributes.contains("width")) {
192             m_width = attributes["width"].toInt();
193         } else {
194             m_width = 0;
195         }
196         //decoder name
197         if (attributes.contains("name")) {
198             m_decompressor = attributes["name"];
199         } else {
200             m_decompressor = "n/a";
201         }
202         //video type ntsc/pal
203         if (attributes.contains("system")) {
204             m_system = attributes["system"];
205         } else {
206             m_system = "n/a";
207         }
208         if (attributes.contains("fps")) {
209             m_framesPerSecond = attributes["fps"].toInt();
210         } else {
211             // No frame rate known.
212             m_framesPerSecond = 0;
213         }
214         //audio attributes -reh
215         if (attributes.contains("channels")) {
216             m_channels = attributes["channels"].toInt();
217         } else {
218             m_channels = 0;
219         }
220         if (attributes.contains("format")) {
221             m_format = attributes["format"];
222         } else {
223             m_format = "n/a";
224         }
225         if (attributes.contains("frequency")) {
226             m_frequency = attributes["frequency"].toInt();
227         } else {
228             m_frequency = 0;
229         }
230         if (attributes.contains("videocodec")) {
231             m_videoCodec = attributes["videocodec"];
232         }
233         if (attributes.contains("audiocodec")) {
234             m_audioCodec = attributes["audiocodec"];
235         }
236
237         m_metadata = metadata;
238
239         if (m_metadata.contains("description")) {
240             setDescription (m_metadata["description"]);
241         }
242         else if (m_metadata.contains("comment")) {
243             setDescription (m_metadata["comment"]);
244         }
245 */
246
247 }
248
249 #include "projectitem.moc"