]> git.sesse.net Git - kdenlive/blob - src/docclipbase.cpp
Starting KDE4 porting
[kdenlive] / src / docclipbase.cpp
1 /**************************1*************************************************
2                           DocClipBase.cpp  -  description
3                              -------------------
4     begin                : Fri Apr 12 2002
5     copyright            : (C) 2002 by Jason Wood
6     email                : jasonwood@blueyonder.co.uk
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include <KDebug>
19
20 #include "docclipbase.h"
21 /*#include "docclipavfile.h"
22 #include "doccliptextfile.h"
23 #include "docclipproject.h"
24 #include "doctrackbase.h"*/
25
26 DocClipBase::DocClipBase():
27 m_description(""), m_refcount(0), m_projectThumbFrame(0), audioThumbCreated(false)
28 {
29     //thumbCreator = 0;
30 }
31
32 DocClipBase::~DocClipBase()
33 {
34     //delete thumbCreator;
35 }
36
37 void DocClipBase::setName(const QString name)
38 {
39     m_name = name;
40 }
41
42 const QString & DocClipBase::name() const
43 {
44     return m_name;
45 }
46
47 uint DocClipBase::getId() const
48 {
49     return m_id;
50 }
51
52 void DocClipBase::setId( const uint &newId)
53 {
54     m_id = newId;
55 }
56
57 void DocClipBase::setProjectThumbFrame( const uint &ix)
58 {
59     m_projectThumbFrame = ix;
60 }
61
62 uint DocClipBase::getProjectThumbFrame() const
63 {
64     return m_projectThumbFrame;
65 }
66
67 void DocClipBase::setDescription(const QString & description)
68 {
69     m_description = description;
70 }
71
72 const QString & DocClipBase::description() const
73 {
74     return m_description;
75 }
76
77 // virtual
78 QDomDocument DocClipBase::toXML() const
79 {
80     QDomDocument doc;
81
82     QDomElement clip = doc.createElement("kdenliveclip");
83     QDomText text = doc.createTextNode(description());
84     clip.appendChild(text);
85     doc.appendChild(clip);
86
87     return doc;
88 }
89
90 DocClipBase *DocClipBase::
91 createClip(KdenliveDoc *doc, const QDomElement & element)
92 {
93     DocClipBase *clip = 0;
94     QString description;
95     QDomNode node = element;
96     node.normalize();
97     if (element.tagName() != "kdenliveclip") {
98         kWarning() <<
99             "DocClipBase::createClip() element has unknown tagName : " <<
100             element.tagName() << endl;
101         return 0;
102     }
103
104     QDomNode n = element.firstChild();
105
106     while (!n.isNull()) {
107         QDomElement e = n.toElement();
108         if (!e.isNull()) {
109             QString tagName = e.tagName();
110             if (e.tagName() == "avfile") {
111                 // clip = DocClipAVFile::createClip(e);
112             } else if (e.tagName() == "DocTrackBaseList") {
113                 // clip = DocClipProject::createClip(doc, e);
114             }
115         } else {
116             QDomText text = n.toText();
117             if (!text.isNull()) {
118                 description = text.nodeValue();
119             }
120         }
121
122         n = n.nextSibling();
123     }
124     if (clip == 0) {
125         kWarning() << "DocClipBase::createClip() unable to create clip" <<
126             endl;
127     } else {
128         // setup DocClipBase specifics of the clip.
129         clip->setDescription(description);
130         clip->setAudioThumbCreated(false);
131     }
132     return clip;
133 }
134
135 void DocClipBase::setAudioThumbCreated(bool isDone)
136 {
137     audioThumbCreated = isDone;
138 }
139
140
141 QDomDocument DocClipBase::generateSceneList(bool, bool) const
142 {
143 }
144
145 void DocClipBase::setThumbnail(const QPixmap & pixmap)
146 {
147     m_thumbnail = pixmap;
148 }
149
150 const QPixmap & DocClipBase::thumbnail() const
151 {
152     return m_thumbnail;
153 }
154
155 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
156 {
157     audioFrameChache = data;
158     audioThumbCreated = true;
159 }
160
161 QList < GenTime > DocClipBase::snapMarkers() const
162 {
163     QList < GenTime > markers;
164
165     for (uint count = 0; count < m_snapMarkers.count(); ++count) {
166         markers.append(m_snapMarkers[count].time());
167     }
168
169     return markers;
170 }
171
172 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
173 {
174     return m_snapMarkers;
175 }
176
177 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
178 {
179     m_snapMarkers = markers;
180 }
181
182 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
183 {
184     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
185     for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
186         if ((*it).time() >= time)
187             break;
188     }
189
190     if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
191         kError() <<
192             "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
193             << endl;
194     } else {
195         CommentedTime t(time, comment);
196         m_snapMarkers.insert(it, t);
197     }
198
199 }
200
201 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
202 {
203     QList < CommentedTime >::Iterator it;
204     for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
205         if ((*it).time() == time)
206             break;
207     }
208     if (it != m_snapMarkers.end()) {
209         (*it).setComment(comment);
210     } else {
211         kError() <<
212             "trying to edit Snap Marker that does not already exists"  << endl;
213     }
214 }
215
216 QString DocClipBase::deleteSnapMarker(const GenTime & time)
217 {
218     QString result = i18n("Marker");
219     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
220
221     while (itt != m_snapMarkers.end()) {
222         if ((*itt).time() == time)
223             break;
224         ++itt;
225     }
226
227     if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
228         result = (*itt).comment();
229         m_snapMarkers.erase(itt);
230     }
231     return result;
232 }
233
234
235 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
236 {
237     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
238
239     while (itt != m_snapMarkers.end()) {
240         if ((*itt).time() == time)
241             return time;
242         ++itt;
243     }
244
245     return GenTime(0.0);
246 }
247
248 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
249 {
250     int it;
251     for ( it = 0; it < m_snapMarkers.count(); it++ ) {
252         if (m_snapMarkers[it].time() >= currTime)
253             break;
254     }
255     if (it == 0) return GenTime();
256     else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
257         return m_snapMarkers[it].time();
258     else return m_snapMarkers[it-1].time();
259 }
260
261 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
262 {
263     int it;
264     for ( it = 0; it < m_snapMarkers.count(); it++ ) {
265         if (m_snapMarkers[it].time() > currTime)
266             break;
267     }
268     if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
269     return duration();
270 }
271
272 QString DocClipBase::markerComment(GenTime t)
273 {
274     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
275
276     while (itt != m_snapMarkers.end()) {
277         if ((*itt).time() == t)
278             return (*itt).comment();
279         ++itt;
280     }
281     return QString::null;
282 }
283
284 //static
285 QString DocClipBase::getTypeName(CLIPTYPE type)
286 {
287     QString result;
288     switch (type) {
289         case AV:
290             result = i18n("Video Clip");
291             break;
292         case COLOR:
293             result = i18n("Color Clip");
294             break;
295         case PLAYLIST:
296             result = i18n("Playlist Clip");
297             break;
298         case IMAGE:
299             result = i18n("Image Clip");
300             break;
301         case SLIDESHOW:
302             result = i18n("Slideshow Clip");
303             break;
304         case VIRTUAL:
305             result = i18n("Virtual Clip");
306             break;
307         case AUDIO:
308             result = i18n("Audio Clip");
309             break;
310         case VIDEO:
311             result = i18n("Mute Video Clip");
312             break;
313         case TEXT:
314             result = i18n("Text Clip");
315             break;
316         default:
317             result = i18n("None");
318             break;
319     }
320     return result;
321 }
322
323