]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
project tree view: Add drag and drop support
[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, int clipId)
72     : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(DocClipBase::NONE), m_clipId(clipId), 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 ProjectItem *ProjectItem::clone() const
84 {
85   ProjectItem *item = (ProjectItem *) this->QTreeWidgetItem::clone();
86   /*if (isGroup())
87   {
88     item = new ProjectItem(new QTreeWidget(), names(), clipId());
89   }  
90   else {
91     if (parent())
92       item = new ProjectItem(new QTreeWidgetItem(), names(), toXml().cloneNode().toElement(), clipId());
93     else 
94       item = new ProjectItem(new QTreeWidget(), names(), toXml().cloneNode().toElement(), clipId());
95   }*/
96   return item;
97 }
98
99 int ProjectItem::clipId() const
100 {
101   return m_clipId;
102 }
103
104 bool ProjectItem::isGroup() const
105 {
106   return m_isGroup;
107 }
108
109 const QString &ProjectItem::groupName() const
110 {
111   if (isGroup()) return text(1);
112   else return QString::null;
113 }
114
115 QStringList ProjectItem::names() const
116 {
117   QStringList result;
118   result.append(text(0));
119   result.append(text(1));
120   result.append(text(2));
121   return result;
122 }
123
124 QDomElement ProjectItem::toXml() const
125 {
126     return m_element;
127 }
128
129 void ProjectItem::slotSetToolTip()
130 {
131   QString tip = "<qt><b>";
132   switch (m_clipType) {
133     case 1:
134       tip.append(i18n("Audio clip"));
135       break;
136     case 2:
137       tip.append(i18n("Mute video clip"));
138       break;
139     case 3:
140       tip.append(i18n("Video clip"));
141       break;
142     case 4:
143       tip.append(i18n("Color clip"));
144       setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
145       break;
146     case 5:
147       tip.append(i18n("Image clip"));
148       break;
149     case 6:
150       tip.append(i18n("Text clip"));
151       break;
152     case 7:
153       tip.append(i18n("Slideshow clip"));
154       break;
155     case 8:
156       tip.append(i18n("Virtual clip"));
157       break;
158     case 9:
159       tip.append(i18n("Playlist clip"));
160       break;
161     default:
162       tip.append(i18n("Unknown clip"));
163     break;
164   }
165
166   setToolTip(1, tip);
167 }
168
169 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
170 {
171         if (attributes.contains("duration")) {
172             m_duration = GenTime(attributes["duration"].toInt(), 25);
173             setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
174             m_durationKnown = true;
175         } else {
176             // No duration known, use an arbitrary one until it is.
177             m_duration = GenTime(0.0);
178             m_durationKnown = false;
179         }
180
181
182         //extend attributes -reh
183
184         if (m_clipType == DocClipBase::NONE) {
185           if (attributes.contains("type")) {
186             if (attributes["type"] == "audio")
187                 m_clipType = DocClipBase::AUDIO;
188             else if (attributes["type"] == "video")
189                 m_clipType = DocClipBase::VIDEO;
190             else if (attributes["type"] == "av")
191                 m_clipType = DocClipBase::AV;
192             else if (attributes["type"] == "playlist")
193                 m_clipType = DocClipBase::PLAYLIST;
194           } else {
195             m_clipType = DocClipBase::AV;
196           }
197         }
198         slotSetToolTip();
199
200         if (m_element.isNull()) {
201           QDomDocument doc;
202           m_element = doc.createElement("producer");
203         }
204         m_element.setAttribute("resource", attributes["filename"]);
205         m_element.setAttribute("type", (int) m_clipType);
206 /*
207         if (attributes.contains("height")) {
208             m_height = attributes["height"].toInt();
209         } else {
210             m_height = 0;
211         }
212         if (attributes.contains("width")) {
213             m_width = attributes["width"].toInt();
214         } else {
215             m_width = 0;
216         }
217         //decoder name
218         if (attributes.contains("name")) {
219             m_decompressor = attributes["name"];
220         } else {
221             m_decompressor = "n/a";
222         }
223         //video type ntsc/pal
224         if (attributes.contains("system")) {
225             m_system = attributes["system"];
226         } else {
227             m_system = "n/a";
228         }
229         if (attributes.contains("fps")) {
230             m_framesPerSecond = attributes["fps"].toInt();
231         } else {
232             // No frame rate known.
233             m_framesPerSecond = 0;
234         }
235         //audio attributes -reh
236         if (attributes.contains("channels")) {
237             m_channels = attributes["channels"].toInt();
238         } else {
239             m_channels = 0;
240         }
241         if (attributes.contains("format")) {
242             m_format = attributes["format"];
243         } else {
244             m_format = "n/a";
245         }
246         if (attributes.contains("frequency")) {
247             m_frequency = attributes["frequency"].toInt();
248         } else {
249             m_frequency = 0;
250         }
251         if (attributes.contains("videocodec")) {
252             m_videoCodec = attributes["videocodec"];
253         }
254         if (attributes.contains("audiocodec")) {
255             m_audioCodec = attributes["audiocodec"];
256         }
257
258         m_metadata = metadata;
259
260         if (m_metadata.contains("description")) {
261             setDescription (m_metadata["description"]);
262         }
263         else if (m_metadata.contains("comment")) {
264             setDescription (m_metadata["comment"]);
265         }
266 */
267
268 }
269
270 #include "projectitem.moc"