]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Reindent all source files
[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
35 const int NameRole = Qt::UserRole;
36 const int DurationRole = NameRole + 1;
37 const int UsageRole = NameRole + 2;
38
39
40 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
41         : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
42     m_element = xml.cloneNode().toElement();
43     setSizeHint(0, QSize(65, 45));
44     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
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 = (CLIPTYPE) cType.toInt();
50             slotSetToolTip();
51         }
52
53         if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION);
54         else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) {
55             m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt());
56         }
57     }
58 }
59
60 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
61         : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) {
62     m_element = xml.cloneNode().toElement();
63     setSizeHint(0, QSize(65, 45));
64     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
65     if (!m_element.isNull()) {
66         m_element.setAttribute("id", clipId);
67         QString cType = m_element.attribute("type", QString::null);
68         if (!cType.isEmpty()) {
69             m_clipType = (CLIPTYPE) cType.toInt();
70             slotSetToolTip();
71         }
72     }
73 }
74
75 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
76         : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1)) {
77     setSizeHint(0, QSize(65, 45));
78     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
79     setIcon(0, KIcon("folder"));
80 }
81
82 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
83         : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) {
84     setSizeHint(0, QSize(65, 45));
85     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
86     m_clip = clip;
87     m_element = clip->toXML();
88     m_clipId = clip->getId();
89     QString name = m_element.attribute("name");
90     if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
91     m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
92     m_groupName = m_element.attribute("group");
93     setText(1, name);
94     kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
95 }
96
97
98 ProjectItem::~ProjectItem() {
99 }
100
101 int ProjectItem::numReferences() const {
102     if (!m_clip) return 0;
103     return m_clip->numReferences();
104 }
105
106 int ProjectItem::clipId() const {
107     return m_clipId;
108 }
109
110 CLIPTYPE ProjectItem::clipType() const {
111     return m_clipType;
112 }
113
114 int ProjectItem::clipMaxDuration() const {
115     return m_element.attribute("duration").toInt();
116 }
117
118 bool ProjectItem::isGroup() const {
119     return m_isGroup;
120 }
121
122 const QString ProjectItem::groupName() const {
123     return m_groupName;
124 }
125
126 QStringList ProjectItem::names() const {
127     QStringList result;
128     result.append(text(0));
129     result.append(text(1));
130     result.append(text(2));
131     return result;
132 }
133
134 QDomElement ProjectItem::toXml() const {
135     return m_element;
136 }
137
138 const KUrl ProjectItem::clipUrl() const {
139     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
140         return KUrl(m_element.attribute("resource"));
141     else return KUrl();
142 }
143
144
145 void ProjectItem::slotSetToolTip() {
146     QString tip = "<qt><b>";
147     switch (m_clipType) {
148     case 1:
149         tip.append(i18n("Audio clip"));
150         break;
151     case 2:
152         tip.append(i18n("Mute video clip"));
153         break;
154     case 3:
155         tip.append(i18n("Video clip"));
156         break;
157     case 4:
158         tip.append(i18n("Color clip"));
159         setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
160         break;
161     case 5:
162         tip.append(i18n("Image clip"));
163         break;
164     case 6:
165         tip.append(i18n("Text clip"));
166         break;
167     case 7:
168         tip.append(i18n("Slideshow clip"));
169         break;
170     case 8:
171         tip.append(i18n("Virtual clip"));
172         break;
173     case 9:
174         tip.append(i18n("Playlist clip"));
175         break;
176     default:
177         tip.append(i18n("Unknown clip"));
178         break;
179     }
180
181     setToolTip(1, tip);
182 }
183
184 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
185     if (attributes.contains("duration")) {
186         if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
187         m_duration = GenTime(attributes["duration"].toInt(), 25);
188         setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
189         m_durationKnown = true;
190         m_clip->setDuration(m_duration);
191         kDebug() << "//// LOADED CLIP, DURATION SET TO: " << m_duration.frames(25);
192     } else {
193         // No duration known, use an arbitrary one until it is.
194         m_duration = GenTime(0.0);
195         m_durationKnown = false;
196     }
197
198
199     //extend attributes -reh
200
201     if (m_clipType == UNKNOWN) {
202         if (attributes.contains("type")) {
203             if (attributes["type"] == "audio")
204                 m_clipType = AUDIO;
205             else if (attributes["type"] == "video")
206                 m_clipType = VIDEO;
207             else if (attributes["type"] == "av")
208                 m_clipType = AV;
209             else if (attributes["type"] == "playlist")
210                 m_clipType = PLAYLIST;
211         } else {
212             m_clipType = AV;
213         }
214         m_clip->setClipType(m_clipType);
215     }
216     slotSetToolTip();
217     if (m_element.isNull()) {
218         QDomDocument doc;
219         m_element = doc.createElement("producer");
220     }
221     if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
222     m_element.setAttribute("resource", attributes["filename"]);
223     m_element.setAttribute("type", (int) m_clipType);
224
225     m_clip->slotRequestAudioThumbs();
226     /*
227      if (attributes.contains("height")) {
228          m_height = attributes["height"].toInt();
229      } else {
230          m_height = 0;
231      }
232      if (attributes.contains("width")) {
233          m_width = attributes["width"].toInt();
234      } else {
235          m_width = 0;
236      }
237      //decoder name
238      if (attributes.contains("name")) {
239          m_decompressor = attributes["name"];
240      } else {
241          m_decompressor = "n/a";
242      }
243      //video type ntsc/pal
244      if (attributes.contains("system")) {
245          m_system = attributes["system"];
246      } else {
247          m_system = "n/a";
248      }
249      if (attributes.contains("fps")) {
250          m_framesPerSecond = attributes["fps"].toInt();
251      } else {
252          // No frame rate known.
253          m_framesPerSecond = 0;
254      }
255      //audio attributes -reh
256      if (attributes.contains("channels")) {
257          m_channels = attributes["channels"].toInt();
258      } else {
259          m_channels = 0;
260      }
261      if (attributes.contains("format")) {
262          m_format = attributes["format"];
263      } else {
264          m_format = "n/a";
265      }
266      if (attributes.contains("frequency")) {
267          m_frequency = attributes["frequency"].toInt();
268      } else {
269          m_frequency = 0;
270      }
271      if (attributes.contains("videocodec")) {
272          m_videoCodec = attributes["videocodec"];
273      }
274      if (attributes.contains("audiocodec")) {
275          m_audioCodec = attributes["audiocodec"];
276      }
277
278      m_metadata = metadata;
279
280      if (m_metadata.contains("description")) {
281          setDescription (m_metadata["description"]);
282      }
283      else if (m_metadata.contains("comment")) {
284          setDescription (m_metadata["comment"]);
285      }
286     */
287
288 }
289
290 #include "projectitem.moc"