]> git.sesse.net Git - kdenlive/blob - src/effectslist.cpp
Fix "Pan and Zoom" and position effects (fade, freeze) not obeying to undo/redo syste...
[kdenlive] / src / effectslist.cpp
1 /***************************************************************************
2                           effectslist.cpp  -  description
3                              -------------------
4     begin                : Sat Aug 10 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
19 #include "effectslist.h"
20
21 #include <KDebug>
22 #include <KLocale>
23
24
25 EffectsList::EffectsList()
26 {
27     m_baseElement = createElement("list");
28     appendChild(m_baseElement);
29 }
30
31 EffectsList::~EffectsList()
32 {
33 }
34
35 QDomElement EffectsList::getEffectByName(const QString & name) const
36 {
37     QString effectName;
38     QDomNodeList effects = m_baseElement.childNodes();
39     for (int i = 0; i < effects.count(); i++) {
40         QDomElement effect =  effects.at(i).toElement();
41         QDomNode namenode = effect.elementsByTagName("name").item(0);
42         if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
43         if (name == effectName) {
44             QDomNodeList params = effect.elementsByTagName("parameter");
45             for (int i = 0; i < params.count(); i++) {
46                 QDomElement e = params.item(i).toElement();
47                 if (!e.hasAttribute("value"))
48                     e.setAttribute("value", e.attribute("default"));
49             }
50             return effect;
51         }
52     }
53
54     return QDomElement();
55 }
56
57 QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) const
58 {
59     QDomNodeList effects = m_baseElement.childNodes();
60     for (int i = 0; i < effects.count(); i++) {
61         QDomElement effect =  effects.at(i).toElement();
62         if (!id.isEmpty()) {
63             if (effect.attribute("id") == id) {
64                 QDomNodeList params = effect.elementsByTagName("parameter");
65                 for (int i = 0; i < params.count(); i++) {
66                     QDomElement e = params.item(i).toElement();
67                     if (!e.hasAttribute("value"))
68                         e.setAttribute("value", e.attribute("default"));
69                 }
70                 return effect;
71             }
72         } else if (!tag.isEmpty()) {
73             if (effect.attribute("tag") == tag) {
74                 QDomNodeList params = effect.elementsByTagName("parameter");
75                 for (int i = 0; i < params.count(); i++) {
76                     QDomElement e = params.item(i).toElement();
77                     if (!e.hasAttribute("value"))
78                         e.setAttribute("value", e.attribute("default"));
79                 }
80                 return effect;
81             }
82         }
83     }
84     return QDomElement();
85 }
86
87 int EffectsList::hasEffect(const QString & tag, const QString & id) const
88 {
89     QDomNodeList effects = m_baseElement.childNodes();
90     for (int i = 0; i < effects.count(); i++) {
91         QDomElement effect =  effects.at(i).toElement();
92         if (!id.isEmpty()) {
93             if (effect.attribute("id") == id) return i;
94         } else if (!tag.isEmpty() && effect.attribute("tag") == tag) return i;
95     }
96     return -1;
97 }
98
99 QStringList EffectsList::effectIdInfo(const int ix) const
100 {
101     QStringList info;
102     QDomElement effect = m_baseElement.childNodes().at(ix).toElement();
103     QDomNode namenode = effect.elementsByTagName("name").item(0);
104     info << i18n(namenode.toElement().text().toUtf8().data()) << effect.attribute("tag") << effect.attribute("id");
105     return info;
106 }
107
108 QStringList EffectsList::effectNames()
109 {
110     QStringList list;
111     QDomNodeList effects = m_baseElement.childNodes();
112     for (int i = 0; i < effects.count(); i++) {
113         QDomElement effect =  effects.at(i).toElement();
114         QDomNode namenode = effect.elementsByTagName("name").item(0);
115         if (!namenode.isNull()) list.append(i18n(namenode.toElement().text().toUtf8().data()));
116     }
117     return list;
118 }
119
120 QString EffectsList::getInfo(const QString & tag, const QString & id) const
121 {
122     QString info;
123     QDomElement effect = getEffectByTag(tag, id);
124     QDomNode namenode = effect.elementsByTagName("description").item(0);
125     if (!namenode.isNull())
126         info = i18n(namenode.firstChild().nodeValue().simplified().toUtf8().data());
127
128     namenode = effect.elementsByTagName("author").item(0);
129     if (!namenode.isNull())
130         info.append("<br /><strong>" + i18n("Author:") + " </strong>" + i18n(namenode.toElement().text().toUtf8().data()));
131
132     return info;
133 }
134
135 QString EffectsList::getInfoFromIndex(const int ix) const
136 {
137     QString info;
138     QDomElement effect = m_baseElement.childNodes().at(ix).toElement();
139     QDomNode namenode = effect.elementsByTagName("description").item(0);
140     if (!namenode.isNull()) info = i18n(namenode.toElement().text().toUtf8().data());
141     namenode = effect.elementsByTagName("author").item(0);
142     if (!namenode.isNull()) info.append("<br /><strong>" + i18n("Author:") + " </strong>" + i18n(namenode.toElement().text().toUtf8().data()));
143     return info;
144 }
145
146 // static
147 bool EffectsList::hasKeyFrames(QDomElement effect)
148 {
149     QDomNodeList params = effect.elementsByTagName("parameter");
150     for (int i = 0; i < params.count(); i++) {
151         QDomElement e = params.item(i).toElement();
152         if (e.attribute("type") == "keyframe") return true;
153     }
154     return false;
155 }
156
157 // static
158 bool EffectsList::hasSimpleKeyFrames(QDomElement effect)
159 {
160     QDomNodeList params = effect.elementsByTagName("parameter");
161     for (int i = 0; i < params.count(); i++) {
162         QDomElement e = params.item(i).toElement();
163         if (e.attribute("type") == "simplekeyframe") return true;
164     }
165     return false;
166 }
167
168 // static
169 bool EffectsList::hasGeometryKeyFrames(QDomElement effect)
170 {
171     QDomNodeList params = effect.elementsByTagName("parameter");
172     for (int i = 0; i < params.count(); ++i) {
173         QDomElement param = params.item(i).toElement();
174         if (param.attribute("type") == "geometry" && !param.hasAttribute("fixed"))
175             return true;
176     }
177     return false;
178 }
179
180 void EffectsList::clone(const EffectsList original)
181 {
182     setContent(original.toString());
183     m_baseElement = documentElement();
184 }
185
186 void EffectsList::clearList()
187 {
188     while (!m_baseElement.firstChild().isNull())
189         m_baseElement.removeChild(m_baseElement.firstChild());
190 }
191
192 // static
193 void EffectsList::setParameter(QDomElement effect, const QString &name, const QString &value)
194 {
195     QDomNodeList params = effect.elementsByTagName("parameter");
196     for (int i = 0; i < params.count(); i++) {
197         QDomElement e = params.item(i).toElement();
198         if (e.attribute("name") == name) {
199             e.setAttribute("value", value);
200             break;
201         }
202     }
203 }
204
205 // static
206 QString EffectsList::parameter(QDomElement effect, const QString &name)
207 {
208     QDomNodeList params = effect.elementsByTagName("parameter");
209     for (int i = 0; i < params.count(); i++) {
210         QDomElement e = params.item(i).toElement();
211         if (e.attribute("name") == name) {
212             return e.attribute("value");
213         }
214     }
215     return QString();
216 }
217
218 // static
219 void EffectsList::setProperty(QDomElement effect, const QString &name, const QString &value)
220 {
221     QDomNodeList params = effect.elementsByTagName("property");
222     for (int i = 0; i < params.count(); i++) {
223         QDomElement e = params.item(i).toElement();
224         if (e.attribute("name") == name) {
225             e.firstChild().setNodeValue(value);
226             break;
227         }
228     }
229 }
230
231 // static
232 QString EffectsList::property(QDomElement effect, const QString &name)
233 {
234     QDomNodeList params = effect.elementsByTagName("property");
235     for (int i = 0; i < params.count(); i++) {
236         QDomElement e = params.item(i).toElement();
237         if (e.attribute("name") == name) {
238             return e.firstChild().nodeValue();
239         }
240     }
241     return QString();
242 }
243
244 void EffectsList::append(QDomElement e)
245 {
246     m_baseElement.appendChild(importNode(e, true));
247 }
248
249 int EffectsList::count() const
250 {
251     return m_baseElement.childNodes().count();
252 }
253
254 bool EffectsList::isEmpty() const
255 {
256     return m_baseElement.childNodes().count() == 0;
257 }
258
259 const QDomElement EffectsList::at(int ix) const
260 {
261     QDomNodeList effects = m_baseElement.childNodes();
262     if (ix < 0 || ix >= effects.count()) return QDomElement();
263     return effects.at(ix).toElement();
264 }
265
266 void EffectsList::removeAt(int ix)
267 {
268     QDomNodeList effects = m_baseElement.childNodes();
269     if (ix < 0 || ix >= effects.count()) return;
270     m_baseElement.removeChild(effects.at(ix));
271 }
272
273 QDomElement EffectsList::item(int ix)
274 {
275     QDomNodeList effects = m_baseElement.childNodes();
276     if (ix < 0 || ix >= effects.count()) return QDomElement();
277     return effects.at(ix).toElement();
278 }
279
280 void EffectsList::insert(int ix, QDomElement effect)
281 {
282     QDomNodeList effects = m_baseElement.childNodes();
283     if (ix < 0) ix = 0;
284     if (ix >= effects.count()) m_baseElement.appendChild(importNode(effect, true));
285     else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
286 }
287
288 void EffectsList::replace(int ix, QDomElement effect)
289 {
290     QDomNodeList effects = m_baseElement.childNodes();
291     if (ix < 0) ix = 0;
292     if (ix < effects.count()) m_baseElement.removeChild(effects.at(ix));
293     if (ix == effects.count()) m_baseElement.appendChild(importNode(effect, true));
294     else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
295 }