X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Feffectslist.cpp;h=d6777eb73503e0602e928c7e8aa05569db80dcb6;hb=cbf0c0c6e3ecf82381e9a7fd41154f600c2456f4;hp=9d33f8e1298302c8139d2de2fb382b58e1e33dbb;hpb=3eeba58b7d59810eba5154f186210b08b107bccc;p=kdenlive diff --git a/src/effectslist.cpp b/src/effectslist.cpp index 9d33f8e1..d6777eb7 100644 --- a/src/effectslist.cpp +++ b/src/effectslist.cpp @@ -54,6 +54,17 @@ QDomElement EffectsList::getEffectByName(const QString & name) const return QDomElement(); } + +void EffectsList::initEffect(QDomElement effect) const +{ + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (!e.hasAttribute("value")) + e.setAttribute("value", e.attribute("default")); + } +} + QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) const { QDomNodeList effects = m_baseElement.childNodes(); @@ -61,22 +72,20 @@ QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) QDomElement effect = effects.at(i).toElement(); if (!id.isEmpty()) { if (effect.attribute("id") == id) { - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - if (!e.hasAttribute("value")) - e.setAttribute("value", e.attribute("default")); - } + if (effect.tagName() == "effectgroup") { + // Effect group + QDomNodeList subeffects = effect.elementsByTagName("effect"); + for (int j = 0; j < subeffects.count(); j++) { + QDomElement sub = subeffects.at(j).toElement(); + initEffect(sub); + } + } + else initEffect(effect); return effect; } } else if (!tag.isEmpty()) { if (effect.attribute("tag") == tag) { - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - if (!e.hasAttribute("value")) - e.setAttribute("value", e.attribute("default")); - } + initEffect(effect); return effect; } } @@ -102,7 +111,7 @@ QStringList EffectsList::effectIdInfo(const int ix) const QDomElement effect = m_baseElement.childNodes().at(ix).toElement(); if (effect.tagName() == "effectgroup") { QString groupName = effect.attribute("name"); - info << groupName << groupName << groupName << QString::number(Kdenlive::groupEffect); + info << groupName << groupName << effect.attribute("id") << QString::number(Kdenlive::groupEffect); } else { QDomElement namenode = effect.firstChildElement("name"); @@ -203,13 +212,24 @@ void EffectsList::clearList() void EffectsList::setParameter(QDomElement effect, const QString &name, const QString &value) { QDomNodeList params = effect.elementsByTagName("parameter"); + bool found = false; for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); if (e.attribute("name") == name) { e.setAttribute("value", value); + found = true; break; } } + if (!found) { + // create property + QDomDocument doc = effect.ownerDocument(); + QDomElement e = doc.createElement("parameter"); + e.setAttribute("name", name); + QDomText val = doc.createTextNode(value); + e.appendChild(val); + effect.appendChild(e); + } } // static @@ -353,14 +373,15 @@ QDomElement EffectsList::insert(QDomElement effect) int ix = effect.attribute("kdenlive_ix").toInt(); QDomElement result; if (ix <= 0 || ix > effects.count()) { - ix = effects.count(); - result = m_baseElement.appendChild(importNode(effect, true)).toElement(); + ix = effects.count(); + result = m_baseElement.appendChild(importNode(effect, true)).toElement(); } else { QDomElement listeffect = effects.at(ix - 1).toElement(); - result = m_baseElement.insertBefore(importNode(effect, true), listeffect).toElement(); + result = m_baseElement.insertBefore(importNode(effect, true), listeffect).toElement(); } - if (m_useIndex) updateIndexes(effects, ix - 1); + if (m_useIndex && ix > 0) + updateIndexes(effects, ix - 1); return result; } @@ -368,7 +389,17 @@ void EffectsList::updateIndexes(QDomNodeList effects, int startIndex) { for (int i = startIndex; i < effects.count(); i++) { QDomElement listeffect = effects.at(i).toElement(); - listeffect.setAttribute("kdenlive_ix", i + 1); + listeffect.setAttribute("kdenlive_ix", i + 1); + } +} + +void EffectsList::enableEffects(QList indexes, bool disable) +{ + QDomNodeList effects = m_baseElement.childNodes(); + QDomElement effect; + for (int i = 0; i < indexes.count(); i++) { + effect = effectFromIndex(effects, indexes.at(i)); + effect.setAttribute("disable", (int) disable); } } @@ -384,8 +415,8 @@ void EffectsList::updateEffect(QDomElement effect) int ix = effect.attribute("kdenlive_ix").toInt(); QDomElement current = effectFromIndex(effects, ix); if (!current.isNull()) { - m_baseElement.insertBefore(importNode(effect, true), current); - m_baseElement.removeChild(current); + m_baseElement.insertBefore(importNode(effect, true), current); + m_baseElement.removeChild(current); } else m_baseElement.appendChild(importNode(effect, true)); }