]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Reformat initializer lists in all constructors.
[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 "projectitem.h"
22 #include "timecode.h"
23 #include "kdenlivesettings.h"
24 #include "docclipbase.h"
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30
31 const int NameRole = Qt::UserRole;
32 const int DurationRole = NameRole + 1;
33 const int UsageRole = NameRole + 2;
34
35
36 // folder
37 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, const QString &clipId) :
38         QTreeWidgetItem(parent, strings),
39         m_clipType(FOLDER),
40         m_clipId(clipId),
41         m_clip(NULL),
42         m_groupname(strings.at(1))
43 {
44     setSizeHint(0, QSize(65, 45));
45     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46     setIcon(0, KIcon("folder"));
47     setToolTip(1, "<b>" + i18n("Folder"));
48     //kDebug() << "Constructed as folder, with clipId: " << m_clipId << ", and groupname: " << m_groupname;
49 }
50
51 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
52         QTreeWidgetItem(parent)
53 {
54     setSizeHint(0, QSize(65, 45));
55     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
56     m_clip = clip;
57     m_clipId = clip->getId();
58     QString name = m_clip->getProperty("name");
59     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
60     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
61     if (m_clipType != UNKNOWN) slotSetToolTip();
62     setText(1, name);
63     setText(2, m_clip->description());
64     if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
65     GenTime duration = m_clip->duration();
66     if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
67     //setFlags(Qt::NoItemFlags);
68     //kDebug() << "Constructed with clipId: " << m_clipId;
69 }
70
71 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
72         QTreeWidgetItem(parent)
73 {
74     setSizeHint(0, QSize(65, 45));
75     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
76     m_clip = clip;
77     m_clipId = clip->getId();
78     QString name = m_clip->getProperty("name");
79     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
80     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
81     setText(1, name);
82     setText(2, m_clip->description());
83     if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
84     GenTime duration = m_clip->duration();
85     if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
86     //setFlags(Qt::NoItemFlags);
87     //kDebug() << "Constructed with clipId: " << m_clipId;
88 }
89
90
91 ProjectItem::~ProjectItem()
92 {
93 }
94
95 int ProjectItem::numReferences() const
96 {
97     if (!m_clip) return 0;
98     return m_clip->numReferences();
99 }
100
101 const QString &ProjectItem::clipId() const
102 {
103     return m_clipId;
104 }
105
106 CLIPTYPE ProjectItem::clipType() const
107 {
108     return m_clipType;
109 }
110
111 int ProjectItem::clipMaxDuration() const
112 {
113     return m_clip->getProperty("duration").toInt();
114 }
115
116 bool ProjectItem::isGroup() const
117 {
118     return m_clipType == FOLDER;
119 }
120
121 QStringList ProjectItem::names() const
122 {
123     QStringList result;
124     result.append(text(0));
125     result.append(text(1));
126     result.append(text(2));
127     return result;
128 }
129
130 QDomElement ProjectItem::toXml() const
131 {
132     return m_clip->toXML();
133 }
134
135 const KUrl ProjectItem::clipUrl() const
136 {
137     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
138         return KUrl(m_clip->getProperty("resource"));
139     else return KUrl();
140 }
141
142 void ProjectItem::changeDuration(int frames)
143 {
144     setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
145 }
146
147 void ProjectItem::setProperties(QMap <QString, QString> props)
148 {
149     if (m_clip == NULL) return;
150     m_clip->setProperties(props);
151 }
152
153 QString ProjectItem::getClipHash() const
154 {
155     if (m_clip == NULL) return QString();
156     return m_clip->getClipHash();
157 }
158
159 void ProjectItem::setProperty(const QString &key, const QString &value)
160 {
161     if (m_clip == NULL) return;
162     m_clip->setProperty(key, value);
163 }
164
165 void ProjectItem::clearProperty(const QString &key)
166 {
167     if (m_clip == NULL) return;
168     m_clip->clearProperty(key);
169 }
170
171 const QString ProjectItem::groupName() const
172 {
173     return m_groupname;
174 }
175
176 void ProjectItem::setGroupName(const QString name)
177 {
178     m_groupname = name;
179     setText(1, name);
180 }
181
182 DocClipBase *ProjectItem::referencedClip()
183 {
184     return m_clip;
185 }
186
187 void ProjectItem::slotSetToolTip()
188 {
189     QString tip = "<b>";
190     switch (m_clipType) {
191     case AUDIO:
192         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
193         break;
194     case VIDEO:
195         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
196         break;
197     case AV:
198         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
199         break;
200     case COLOR:
201         tip.append(i18n("Color clip"));
202         break;
203     case IMAGE:
204         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
205         break;
206     case TEXT:
207         tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
208         break;
209     case SLIDESHOW:
210         tip.append(i18n("Slideshow clip"));
211         break;
212     case VIRTUAL:
213         tip.append(i18n("Virtual clip"));
214         break;
215     case PLAYLIST:
216         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
217         break;
218     default:
219         tip.append(i18n("Unknown clip"));
220         break;
221     }
222
223     setToolTip(1, tip);
224 }
225
226
227 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
228 {
229     if (m_clip == NULL) return;
230     //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
231     if (attributes.contains("duration")) {
232         GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
233         setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
234         m_clip->setDuration(duration);
235         //kDebug() << "//// LOADED CLIP, DURATION SET TO: " << duration.frames(KdenliveSettings::project_fps());
236     } else  {
237         // No duration known, use an arbitrary one until it is.
238     }
239
240
241     //extend attributes -reh
242
243     if (m_clipType == UNKNOWN) {
244         QString cliptype = attributes.value("type");
245         if (cliptype == "audio") m_clipType = AUDIO;
246         else if (cliptype == "video") m_clipType = VIDEO;
247         else if (cliptype == "av") m_clipType = AV;
248         else if (cliptype == "playlist") m_clipType = PLAYLIST;
249         else m_clipType = AV;
250
251         m_clip->setClipType(m_clipType);
252         slotSetToolTip();
253     }
254     m_clip->setProperties(attributes);
255     m_clip->setMetadata(metadata);
256     if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
257
258     if (m_clip->description().isEmpty()) {
259         if (metadata.contains("description")) {
260             m_clip->setProperty("description", metadata.value("description"));
261             setText(2, m_clip->description());
262         } else if (metadata.contains("comment")) {
263             m_clip->setProperty("description", metadata.value("comment"));
264             setText(2, m_clip->description());
265         }
266     }
267 }
268