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