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