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