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);
125 QDomNode namenode = effect.elementsByTagName("description").item(0);
126 if (!namenode.isNull())
127 info = i18n(namenode.toElement().text().toUtf8().data());
129 namenode = effect.elementsByTagName("author").item(0);
130 if (!namenode.isNull())
131 info.append("<br /><strong>" + i18n("Author:") + " </strong>" + i18n(namenode.toElement().text().toUtf8().data()));
136 QString EffectsList::getInfoFromIndex(const int ix) const
139 QDomElement effect = m_baseElement.childNodes().at(ix).toElement();
140 QDomNode namenode = effect.elementsByTagName("description").item(0);
141 if (!namenode.isNull()) info = i18n(namenode.toElement().text().toUtf8().data());
142 namenode = effect.elementsByTagName("author").item(0);
143 if (!namenode.isNull()) info.append("<br /><strong>" + i18n("Author:") + " </strong>" + i18n(namenode.toElement().text().toUtf8().data()));
148 bool EffectsList::hasKeyFrames(QDomElement effect)
150 QDomNodeList params = effect.elementsByTagName("parameter");
151 for (int i = 0; i < params.count(); i++) {
152 QDomElement e = params.item(i).toElement();
153 if (e.attribute("type") == "keyframe") return true;
159 bool EffectsList::hasSimpleKeyFrames(QDomElement effect)
161 QDomNodeList params = effect.elementsByTagName("parameter");
162 for (int i = 0; i < params.count(); i++) {
163 QDomElement e = params.item(i).toElement();
164 if (e.attribute("type") == "simplekeyframe") return true;
169 void EffectsList::clone(const EffectsList original)
171 setContent(original.toString());
172 m_baseElement = documentElement();
175 void EffectsList::clearList()
177 while (!m_baseElement.firstChild().isNull())
178 m_baseElement.removeChild(m_baseElement.firstChild());
182 void EffectsList::setParameter(QDomElement effect, const QString &name, const QString &value)
184 QDomNodeList params = effect.elementsByTagName("parameter");
185 for (int i = 0; i < params.count(); i++) {
186 QDomElement e = params.item(i).toElement();
187 if (e.attribute("name") == name) {
188 e.setAttribute("value", value);
195 QString EffectsList::parameter(QDomElement effect, const QString &name)
197 QDomNodeList params = effect.elementsByTagName("parameter");
198 for (int i = 0; i < params.count(); i++) {
199 QDomElement e = params.item(i).toElement();
200 if (e.attribute("name") == name) {
201 return e.attribute("value");
208 void EffectsList::setProperty(QDomElement effect, const QString &name, const QString &value)
210 QDomNodeList params = effect.elementsByTagName("property");
211 for (int i = 0; i < params.count(); i++) {
212 QDomElement e = params.item(i).toElement();
213 if (e.attribute("name") == name) {
214 e.firstChild().setNodeValue(value);
221 QString EffectsList::property(QDomElement effect, const QString &name)
223 QDomNodeList params = effect.elementsByTagName("property");
224 for (int i = 0; i < params.count(); i++) {
225 QDomElement e = params.item(i).toElement();
226 if (e.attribute("name") == name) {
227 return e.firstChild().nodeValue();
233 void EffectsList::append(QDomElement e)
235 m_baseElement.appendChild(importNode(e, true));
238 int EffectsList::count() const
240 return m_baseElement.childNodes().count();
243 bool EffectsList::isEmpty() const
245 return m_baseElement.childNodes().count() == 0;
248 const QDomElement EffectsList::at(int ix) const
250 QDomNodeList effects = m_baseElement.childNodes();
251 if (ix < 0 || ix >= effects.count()) return QDomElement();
252 return effects.at(ix).toElement();
255 void EffectsList::removeAt(int ix)
257 QDomNodeList effects = m_baseElement.childNodes();
258 if (ix < 0 || ix >= effects.count()) return;
259 m_baseElement.removeChild(effects.at(ix));
262 QDomElement EffectsList::item(int ix)
264 QDomNodeList effects = m_baseElement.childNodes();
265 if (ix < 0 || ix >= effects.count()) return QDomElement();
266 return effects.at(ix).toElement();
269 void EffectsList::insert(int ix, QDomElement effect)
271 QDomNodeList effects = m_baseElement.childNodes();
273 if (ix >= effects.count()) m_baseElement.appendChild(importNode(effect, true));
274 else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));
277 void EffectsList::replace(int ix, QDomElement effect)
279 QDomNodeList effects = m_baseElement.childNodes();
281 if (ix < effects.count()) m_baseElement.removeChild(effects.at(ix));
282 if (ix == effects.count()) m_baseElement.appendChild(importNode(effect, true));
283 else m_baseElement.insertBefore(importNode(effect, true), effects.at(ix));