From: Till T. <ro...@tt...> - 2012-05-09 09:26:34
|
Git commit eb3b733dc84377145bb3f88dcd452b6592beae37 by Till Theato. Committed on 07/05/2012 at 14:34. Pushed by theato into branch 'refactoring'. Use the effectdescription to create new effects. M +0 -1 src/effects/CMakeLists.txt M +3 -1 src/effects/abstracteffectlist.h M +13 -5 src/effects/abstractparameter.cpp M +6 -5 src/effects/abstractparameter.h M +9 -2 src/effects/abstractparameterdescription.cpp M +7 -2 src/effects/abstractparameterdescription.h M +10 -8 src/effects/abstractparameterlist.cpp M +1 -1 src/effects/abstractparameterlist.h M +14 -24 src/effects/doubleparameter.cpp M +4 -8 src/effects/doubleparameter.h M +2 -2 src/effects/doubleparameterdescription.cpp M +5 -5 src/effects/effect.cpp M +3 -2 src/effects/effect.h M +5 -0 src/effects/effectdescription.cpp M +1 -0 src/effects/effectdescription.h M +1 -0 src/effects/effectdevice.cpp M +3 -3 src/effects/effectdevice.h http://commits.kde.org/kdenlive/eb3b733dc84377145bb3f88dcd452b6592beae37 diff --git a/src/effects/CMakeLists.txt b/src/effects/CMakeLists.txt index 1b103b8..94e494f 100644 --- a/src/effects/CMakeLists.txt +++ b/src/effects/CMakeLists.txt @@ -4,7 +4,6 @@ set(kdenlive_SRCS effects/abstracteffectrepositoryitem.cpp effects/abstracteffectstackitem.cpp effects/abstractparameter.cpp - effects/abstractparameterlist.cpp effects/abstractparameterdescription.cpp effects/abstractparameterlist.cpp effects/doubleparameter.cpp diff --git a/src/effects/abstracteffectlist.h b/src/effects/abstracteffectlist.h index 979e270..0cc3fba 100644 --- a/src/effects/abstracteffectlist.h +++ b/src/effects/abstracteffectlist.h @@ -16,7 +16,7 @@ the Free Software Foundation, either version 3 of the License, or #include <QList> class Effect; - +class EffectDescription; class AbstractEffectList : public QObject, protected QList<Effect *> { @@ -26,6 +26,8 @@ public: ~AbstractEffectList(); virtual void appendFilter(Mlt::Filter *filter) = 0; + virtual void appendEffect(QString id) = 0; + virtual void appendEffect(EffectDescription *description) = 0; MultiUiHandler *getUiHandler(); virtual Mlt::Service *getService() = 0; diff --git a/src/effects/abstractparameter.cpp b/src/effects/abstractparameter.cpp index 222d52f..84897ae 100644 --- a/src/effects/abstractparameter.cpp +++ b/src/effects/abstractparameter.cpp @@ -9,16 +9,16 @@ the Free Software Foundation, either version 3 of the License, or */ #include "abstractparameter.h" +#include "abstractparameterdescription.h" #include "abstractparameterlist.h" #include "multiuihandler.h" -#include <QDomElement> -AbstractParameter::AbstractParameter(QDomElement parameterDescription, AbstractParameterList* parent) : + +AbstractParameter::AbstractParameter(AbstractParameterDescription *parameterDescription, AbstractParameterList* parent) : + m_abstractDescription(static_cast<AbstractParameterDescription*>(parameterDescription)), m_parent(parent) { m_uiHandler = new MultiUiHandler(parent->getUiHandler()); - m_name = parameterDescription.attribute("name"); - connect(m_uiHandler, SIGNAL(createUi(EffectUiTypes, QObject*)), this, SLOT(createUi(EffectUiTypes, QObject*))); } @@ -27,9 +27,17 @@ AbstractParameter::~AbstractParameter() delete m_uiHandler; } -MultiUiHandler* AbstractParameter::getMultiUiHandler() +MultiUiHandler *AbstractParameter::getMultiUiHandler() { return m_uiHandler; } +QString AbstractParameter::getName() const +{ + return m_abstractDescription->getName(); +} +AbstractParameterDescription* AbstractParameter::getDescription() +{ + return m_abstractDescription; +} \ No newline at end of file diff --git a/src/effects/abstractparameter.h b/src/effects/abstractparameter.h index 3988cf8..6099485 100644 --- a/src/effects/abstractparameter.h +++ b/src/effects/abstractparameter.h @@ -11,12 +11,11 @@ the Free Software Foundation, either version 3 of the License, or #ifndef ABSTRACTPARAMETER_H #define ABSTRACTPARAMETER_H -#include "multiuihandler.h" -#include <mlt++/Mlt.h> #include <QObject> +#include "multiuihandler.h" +class AbstractParameterDescription; class AbstractParameterList; -class QDomElement; class AbstractParameter : public QObject @@ -24,11 +23,13 @@ class AbstractParameter : public QObject Q_OBJECT public: - AbstractParameter(QDomElement parameterDescription, AbstractParameterList *parent); + AbstractParameter(AbstractParameterDescription *parameterDescription, AbstractParameterList *parent); virtual ~AbstractParameter(); virtual void set(const char *data) = 0; virtual const char *get() const = 0; + QString getName() const; + AbstractParameterDescription *getDescription(); MultiUiHandler *getMultiUiHandler(); public slots: @@ -36,7 +37,7 @@ public slots: protected: AbstractParameterList *m_parent; - QString m_name; + AbstractParameterDescription *m_abstractDescription; private: MultiUiHandler *m_uiHandler; diff --git a/src/effects/abstractparameterdescription.cpp b/src/effects/abstractparameterdescription.cpp index 7cb0b61..78ab6e7 100644 --- a/src/effects/abstractparameterdescription.cpp +++ b/src/effects/abstractparameterdescription.cpp @@ -16,7 +16,8 @@ the Free Software Foundation, either version 3 of the License, or #include <KLocale> -AbstractParameterDescription::AbstractParameterDescription(QDomElement parameter, QLocale locale) : +AbstractParameterDescription::AbstractParameterDescription(ParameterType type, QDomElement parameter, QLocale locale) : + m_type(type), m_valid(true) { m_name = parameter.attribute("name"); @@ -36,7 +37,8 @@ AbstractParameterDescription::AbstractParameterDescription(QDomElement parameter m_comment = i18n(m_commentOrig.toUtf8()); } -AbstractParameterDescription::AbstractParameterDescription(Mlt::Properties& properties, QLocale locale) : +AbstractParameterDescription::AbstractParameterDescription(ParameterType type, Mlt::Properties& properties, QLocale locale) : + m_type(type), m_valid(true) { m_name = properties.get("identifier"); @@ -57,6 +59,11 @@ QString AbstractParameterDescription::getName() const return m_name; } +ParameterType AbstractParameterDescription::getType() const +{ + return m_type; +} + QString AbstractParameterDescription::getDisplayName() const { return m_displayName; diff --git a/src/effects/abstractparameterdescription.h b/src/effects/abstractparameterdescription.h index f1618b4..d6d9f7b 100644 --- a/src/effects/abstractparameterdescription.h +++ b/src/effects/abstractparameterdescription.h @@ -21,16 +21,20 @@ namespace Mlt class Properties; } +//proper location? +enum ParameterType { DoubleParameterType}; + // make template to be able to store default? class AbstractParameterDescription { public: - AbstractParameterDescription(QDomElement parameter, QLocale locale); - AbstractParameterDescription(Mlt::Properties &properties, QLocale locale); + AbstractParameterDescription(ParameterType type, QDomElement parameter, QLocale locale); + AbstractParameterDescription(ParameterType type, Mlt::Properties &properties, QLocale locale); virtual ~AbstractParameterDescription(); QString getName() const; + ParameterType getType() const; QString getDisplayName() const; QString getComment() const; bool isValid() const; @@ -39,6 +43,7 @@ protected: bool m_valid; private: + ParameterType m_type; QString m_name; QString m_displayName; QString m_displayNameOrig; diff --git a/src/effects/abstractparameterlist.cpp b/src/effects/abstractparameterlist.cpp index bb20636..7f6434f 100644 --- a/src/effects/abstractparameterlist.cpp +++ b/src/effects/abstractparameterlist.cpp @@ -9,7 +9,8 @@ the Free Software Foundation, either version 3 of the License, or */ #include "abstractparameterlist.h" -#include "parametertypes.h" +#include "abstractparameter.h" +#include "doubleparameter.h" #include "multiuihandler.h" @@ -24,16 +25,17 @@ AbstractParameterList::~AbstractParameterList() delete m_uiHandler; } -void AbstractParameterList::loadParameters(QDomNodeList parameters) +void AbstractParameterList::loadParameters(QList<AbstractParameterDescription *> parameters) { - for (int i = 0; i < parameters.count(); ++i) { - QDomElement parameterDescription = parameters.at(i).toElement(); - QString type = parameterDescription.attribute("type"); + foreach(AbstractParameterDescription *parameterDescription, parameters) { + ParameterType type = parameterDescription->getType(); AbstractParameter *parameter; - if (type == "double" || type == "constant") { - parameter = new DoubleParameter(parameterDescription, this); + if (type == DoubleParameterType) { + parameter = new DoubleParameter(static_cast<DoubleParameterDescription*>(parameterDescription), this); + } + if (parameter) { + append(parameter); } - append(parameter); } } diff --git a/src/effects/abstractparameterlist.h b/src/effects/abstractparameterlist.h index 68b257f..e0f033c 100644 --- a/src/effects/abstractparameterlist.h +++ b/src/effects/abstractparameterlist.h @@ -26,7 +26,7 @@ public: AbstractParameterList(QObject *parent = 0); virtual ~AbstractParameterList(); - void loadParameters(QDomNodeList parameters); + void loadParameters(QList<AbstractParameterDescription *> parameters); virtual void setParameter(QString name, QString value) = 0; virtual QString getParameter(QString name) const = 0; diff --git a/src/effects/doubleparameter.cpp b/src/effects/doubleparameter.cpp index a0aae5f..d3556d9 100644 --- a/src/effects/doubleparameter.cpp +++ b/src/effects/doubleparameter.cpp @@ -11,51 +11,41 @@ the Free Software Foundation, either version 3 of the License, or #include "doubleparameter.h" #include "abstractparameterlist.h" #include "doubleparametereffectstackitem.h" -#include <QDomElement> +#include <QLocale> -// WARNING: locale! -DoubleParameter::DoubleParameter(QDomElement parameterDescription, AbstractParameterList* parent) : - AbstractParameter(parameterDescription, parent) +DoubleParameter::DoubleParameter(DoubleParameterDescription *parameterDescription, AbstractParameterList* parent) : + AbstractParameter(parameterDescription, parent), + m_description(parameterDescription) { - m_default = parameterDescription.attribute("default").toDouble(); - m_min = parameterDescription.attribute("min").toInt(); - m_max = parameterDescription.attribute("max").toInt(); - m_factor = parameterDescription.attribute("factor").toInt(); - m_offset = parameterDescription.attribute("offset").toInt(); - m_decimals = 0; - - double value; - if (parameterDescription.hasAttribute("value")) - value = parameterDescription.attribute("value").toDouble(); - else - value = m_default; - set(value); + set(m_description->getDefault()); } void DoubleParameter::set(const char* data) { - double value = QString::fromUtf8(data).toDouble(); - value = m_offset + value * m_factor; + QLocale locale; + double value = locale.toDouble(QString(data)); + value = m_description->getOffset() + value * m_description->getFactor(); emit valueUpdated(value); } void DoubleParameter::set(double value, bool update) { + QLocale locale; if (update) emit valueUpdated(value); - value = (value + m_min - m_offset) / m_factor; - m_parent->setParameter(m_name, QString::number(value)); + value = (value + m_description->getMin() - m_description->getOffset()) / m_description->getFactor(); + m_parent->setParameter(getName(), locale.toString(value)); } const char* DoubleParameter::get() const { - return m_parent->getParameter(m_name).toUtf8().constData(); + return m_parent->getParameter(getName()).toUtf8().constData(); } double DoubleParameter::getValue() const { - return m_parent->getParameter(m_name).toDouble(); + return m_parent->getParameter(getName()).toDouble(); } void DoubleParameter::createUi(EffectUiTypes type, QObject* parent) @@ -64,7 +54,7 @@ void DoubleParameter::createUi(EffectUiTypes type, QObject* parent) switch (type) { case EffectStackEffectUi: - effectStackItem = new DoubleParameterEffectStackItem(m_name, getValue(), m_min, m_max, QString(), -1, QString(), 0, static_cast<AbstractEffectStackItem*>(parent)); + effectStackItem = new DoubleParameterEffectStackItem(m_description->getDisplayName(), getValue(), m_description->getMin(), m_description->getMax(), m_description->getComment(), -1, m_description->getSuffix(), m_description->getDecimals(), static_cast<AbstractEffectStackItem*>(parent)); connect(this, SIGNAL(valueUpdated(double)), effectStackItem, SLOT(setValue(double))); connect(effectStackItem, SIGNAL(valueChanged(double)), this, SLOT(set(double))); getMultiUiHandler()->addUi(type, static_cast<QObject *>(effectStackItem)); diff --git a/src/effects/doubleparameter.h b/src/effects/doubleparameter.h index 96a8007..36cdcdf 100644 --- a/src/effects/doubleparameter.h +++ b/src/effects/doubleparameter.h @@ -12,16 +12,17 @@ the Free Software Foundation, either version 3 of the License, or #define DOUBLEPARAMETER_H #include "abstractparameter.h" +#include "doubleparameterdescription.h" #include "parametertypes.h" -class AbstractParameterList; + class DoubleParameter : public AbstractParameter { Q_OBJECT public: - DoubleParameter(QDomElement parameterDescription, AbstractParameterList *parent); + DoubleParameter(DoubleParameterDescription *parameterDescription, AbstractParameterList *parent); // ~DoubleParameter(); void set(const char*data); @@ -34,12 +35,7 @@ public slots: void set(double value, bool update = false); private: - double m_default; - int m_min; - int m_max; - int m_factor; - int m_offset; - int m_decimals; + DoubleParameterDescription *m_description; signals: void valueUpdated(double value); diff --git a/src/effects/doubleparameterdescription.cpp b/src/effects/doubleparameterdescription.cpp index 5a0e61d..2a8c2c5 100644 --- a/src/effects/doubleparameterdescription.cpp +++ b/src/effects/doubleparameterdescription.cpp @@ -17,7 +17,7 @@ the Free Software Foundation, either version 3 of the License, or DoubleParameterDescription::DoubleParameterDescription(QDomElement parameter, QLocale locale) : - AbstractParameterDescription(parameter, locale) + AbstractParameterDescription(DoubleParameterType, parameter, locale) { m_default = locale.toDouble(parameter.attribute("default")); m_factor = locale.toDouble(parameter.attribute("factor", QString("1"))); @@ -31,7 +31,7 @@ DoubleParameterDescription::DoubleParameterDescription(QDomElement parameter, QL } DoubleParameterDescription::DoubleParameterDescription(Mlt::Properties& properties, QLocale locale) : - AbstractParameterDescription(properties, locale), + AbstractParameterDescription(DoubleParameterType, properties, locale), m_factor(1), m_offset(0), m_decimals(0), diff --git a/src/effects/effect.cpp b/src/effects/effect.cpp index bdbb515..07dbc20 100644 --- a/src/effects/effect.cpp +++ b/src/effects/effect.cpp @@ -11,15 +11,15 @@ the Free Software Foundation, either version 3 of the License, or #include "effect.h" #include "abstracteffectlist.h" +#include "effectdescription.h" -#include <QDomElement> - -Effect::Effect(QDomElement effectDescription, AbstractEffectList* parent) +Effect::Effect(EffectDescription *effectDescription, AbstractEffectList* parent) : + m_description(effectDescription) { - m_filter = new Mlt::Filter(*parent->getService()->profile(), effectDescription.attribute("tag").toUtf8().constData()); + m_filter = new Mlt::Filter(*parent->getService()->profile(), effectDescription->getTag().toUtf8().constData()); parent->appendFilter(m_filter); - loadParameters(effectDescription.elementsByTagName("parameter")); + loadParameters(effectDescription->getParameters()); m_uiHandler = new MultiUiHandler(parent->getUiHandler()); } diff --git a/src/effects/effect.h b/src/effects/effect.h index e3ddba1..63a6e00 100644 --- a/src/effects/effect.h +++ b/src/effects/effect.h @@ -14,7 +14,7 @@ the Free Software Foundation, either version 3 of the License, or #include "abstractparameterlist.h" #include <mlt++/Mlt.h> -class QDomElement; +class EffectDescription; class AbstractEffectList; @@ -23,7 +23,7 @@ class Effect : public AbstractParameterList Q_OBJECT public: - Effect(QDomElement effectDescription, AbstractEffectList* parent = 0); + Effect(EffectDescription *effectDescription, AbstractEffectList* parent = 0); ~Effect(); void setParameter(QString name, QString value); @@ -34,6 +34,7 @@ public: private: Mlt::Filter *m_filter; + EffectDescription *m_description; }; #endif diff --git a/src/effects/effectdescription.cpp b/src/effects/effectdescription.cpp index d8d723b..68beaa1 100644 --- a/src/effects/effectdescription.cpp +++ b/src/effects/effectdescription.cpp @@ -118,6 +118,11 @@ EffectDescription::~EffectDescription() qDeleteAll(begin(), end()); } +QList< AbstractParameterDescription* > EffectDescription::getParameters() +{ + return *this; +} + QString EffectDescription::getTag() const { return m_tag; diff --git a/src/effects/effectdescription.h b/src/effects/effectdescription.h index 115b074..19f81f2 100644 --- a/src/effects/effectdescription.h +++ b/src/effects/effectdescription.h @@ -25,6 +25,7 @@ public: EffectDescription(QDomElement description, double version); virtual ~EffectDescription(); + QList <AbstractParameterDescription *> getParameters(); QString getTag() const; QString getName() const; QString getDescription() const; diff --git a/src/effects/effectdevice.cpp b/src/effects/effectdevice.cpp index c75485e..471f2ce 100644 --- a/src/effects/effectdevice.cpp +++ b/src/effects/effectdevice.cpp @@ -9,6 +9,7 @@ the Free Software Foundation, either version 3 of the License, or */ #include "effectdevice.h" +#include "effectdescription.h" EffectDevice::EffectDevice(Mlt::Service* service) : AbstractEffectList(), diff --git a/src/effects/effectdevice.h b/src/effects/effectdevice.h index b8c40b4..553754b 100644 --- a/src/effects/effectdevice.h +++ b/src/effects/effectdevice.h @@ -22,11 +22,11 @@ class EffectDevice : public AbstractEffectList public: EffectDevice(Mlt::Service *service); ~EffectDevice(); - - void appendFilter(Mlt::Filter *filter); - Mlt::Service *getService(); + void appendFilter(Mlt::Filter *filter); void appendEffect(QString id); + void appendEffect(EffectDescription *description); + Mlt::Service *getService(); private: Mlt::Service *m_service; |