1 /***************************************************************************
2 effectslist.cpp - description
4 begin : Sat Aug 10 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
19 #include "effectslist.h"
25 EffectsList::EffectsList()
27 m_baseElement = createElement("list");
28 appendChild(m_baseElement);
31 EffectsList::~EffectsList()
35 QDomElement EffectsList::getEffectByName(const QString & name) const
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"));
57 QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) const
59 QDomNodeList effects = m_baseElement.childNodes();
60 for (int i = 0; i < effects.count(); i++) {
61 QDomElement effect = effects.at(i).toElement();
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"));
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"));
87 int EffectsList::hasEffect(const QString & tag, const QString & id) const
89 QDomNodeList effects = m_baseElement.childNodes();
90 for (int i = 0; i < effects.count(); i++) {
91 QDomElement effect = effects.at(i).toElement();
93 if (effect.attribute("id") == id) return i;
94 } else if (!tag.isEmpty() && effect.attribute("tag") == tag) return i;
99 QStringList EffectsList::effectIdInfo(const int ix) const
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");
108 QStringList EffectsList::effectNames()
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()));
120 QString EffectsList::getInfo(const QString & tag, const QString & id) const
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());
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()));
135 QString EffectsList::getInfoFromIndex(const int ix) const
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()));
147 bool EffectsList::hasKeyFrames(QDomElement effect)
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;
158 bool EffectsList::hasSimpleKeyFrames(QDomElement effect)
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;
169 bool EffectsList::hasGeometryKeyFrames(QDomElement effect)
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"))
180 void EffectsList::clone(const EffectsList original)
182 setContent(original.toString());
183 m_baseElement = documentElement();
186 void EffectsList::clearList()
188 while (!m_baseElement.firstChild().isNull())
189 m_baseElement.removeChild(m_baseElement.firstChild());
193 void EffectsList::setParameter(QDomElement effect, const QString &name, const QString &value)
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);
206 QString EffectsList::parameter(QDomElement effect, const QString &name)
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");
219 void EffectsList::setProperty(QDomElement effect, const QString &name, const QString &value)
221 QDomNodeList params = effect.elementsByTagName("property");
222 // Update property if it already exists
223 for (int i = 0; i < params.count(); i++) {
224 QDomElement e = params.item(i).toElement();
225 if (e.attribute("name") == name) {
226 e.firstChild().setNodeValue(value);
233 void EffectsList::renameProperty(QDomElement effect, const QString &oldName, const QString &newName)
235 QDomNodeList params = effect.elementsByTagName("property");
236 // Update property if it already exists
237 for (int i = 0; i < params.count(); i++) {
238 QDomElement e = params.item(i).toElement();
239 if (e.attribute("name") == oldName) {
240 e.setAttribute("name", newName);
247 QString EffectsList::property(QDomElement effect, const QString &name)
249 QDomNodeList params = effect.elementsByTagName("property");
250 for (int i = 0; i < params.count(); i++) {
251 QDomElement e = params.item(i).toElement();
252 if (e.attribute("name") == name) {
253 return e.firstChild().nodeValue();
260 void EffectsList::removeProperty(QDomElement effect, const QString &name)
262 QDomNodeList params = effect.elementsByTagName("property");
263 for (int i = 0; i < params.count(); i++) {
264 QDomElement e = params.item(i).toElement();
265 if (e.attribute("name") == name) {
266 effect.removeChild(params.item(i));
272 void EffectsList::append(QDomElement e)
274 m_baseElement.appendChild(importNode(e, true));
277 int EffectsList::count() const
279 return m_baseElement.childNodes().count();
282 bool EffectsList::isEmpty() const
284 return m_baseElement.childNodes().count() == 0;
287 const QDomElement EffectsList::at(int ix) const
289 QDomNodeList effects = m_baseElement.childNodes();
290 if (ix < 0 || ix >= effects.count()) return QDomElement();
291 return effects.at(ix).toElement();
294 void EffectsList::removeAt(int ix)
296 QDomNodeList effects = m_baseElement.childNodes();
297 if (ix < 0 || ix >= effects.count()) return;
298 m_baseElement.removeChild(effects.at(ix));
301 QDomElement EffectsList::item(int ix)
303 QDomNodeList effects = m_baseElement.childNodes();
304 if (ix < 0 || ix >= effects.count()) return QDomElement();
305 return effects.at(ix).toElement();
308 void EffectsList::insert(int ix, QDomElement effect)
310 QDomNodeList effects = m_baseElement.childNodes();
312 if (ix >= effects.count()) m_baseElement.appendChild(importNode(effect, true));
313 else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
316 void EffectsList::replace(int ix, QDomElement effect)
318 QDomNodeList effects = m_baseElement.childNodes();
320 if (ix < effects.count()) m_baseElement.removeChild(effects.at(ix));
321 if (ix == effects.count()) m_baseElement.appendChild(importNode(effect, true));
322 else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));