diff --git a/src/effects/effectstack/model/abstracteffectitem.cpp b/src/effects/effectstack/model/abstracteffectitem.cpp
index 6045cb6ab..3884b0924 100644
--- a/src/effects/effectstack/model/abstracteffectitem.cpp
+++ b/src/effects/effectstack/model/abstracteffectitem.cpp
@@ -1,86 +1,86 @@
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#include "abstracteffectitem.hpp"
#include "core.h"
#include "effects/effectsrepository.hpp"
#include "effectstackmodel.hpp"
#include
#include
-AbstractEffectItem::AbstractEffectItem(EffectItemType type, const QList &data, const std::shared_ptr &stack, bool isRoot)
+AbstractEffectItem::AbstractEffectItem(EffectItemType type, const QList &data, const std::shared_ptr &stack, bool isRoot, bool isEnabled)
: TreeItem(data, stack, isRoot)
, m_effectItemType(type)
- , m_enabled(true)
+ , m_enabled(isEnabled)
, m_effectStackEnabled(true)
{
}
void AbstractEffectItem::markEnabled(const QString &name, bool enabled)
{
Fun undo = [this, enabled]() {
setEnabled(!enabled);
return true;
};
Fun redo = [this, enabled]() {
setEnabled(enabled);
return true;
};
redo();
pCore->pushUndo(undo, redo, enabled ? i18n("Enable %1", name) : i18n("Disable %1", name));
}
void AbstractEffectItem::setEnabled(bool enabled)
{
m_enabled = enabled;
updateEnable();
}
void AbstractEffectItem::setEffectStackEnabled(bool enabled)
{
if (m_effectStackEnabled == enabled) {
// nothing to do
return;
}
m_effectStackEnabled = enabled;
for (int i = 0; i < childCount(); ++i) {
std::static_pointer_cast(child(i))->setEffectStackEnabled(enabled);
}
updateEnable();
}
bool AbstractEffectItem::isEnabled() const
{
bool parentEnabled = true;
if (auto ptr = std::static_pointer_cast(m_parentItem.lock())) {
parentEnabled = ptr->isEnabled();
} else {
// Root item, always return true
return true;
}
return m_enabled && m_effectStackEnabled && parentEnabled;
}
EffectItemType AbstractEffectItem::effectItemType() const
{
return m_effectItemType;
}
diff --git a/src/effects/effectstack/model/abstracteffectitem.hpp b/src/effects/effectstack/model/abstracteffectitem.hpp
index 699e7a822..d45e5312c 100644
--- a/src/effects/effectstack/model/abstracteffectitem.hpp
+++ b/src/effects/effectstack/model/abstracteffectitem.hpp
@@ -1,72 +1,72 @@
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#ifndef ABSTRACTEFFECTITEM_H
#define ABSTRACTEFFECTITEM_H
#include "abstractmodel/treeitem.hpp"
#include
enum class EffectItemType { Effect, Group };
class EffectStackModel;
/* @brief This represents an effect of the effectstack
*/
class AbstractEffectItem : public TreeItem
{
public:
- AbstractEffectItem(EffectItemType type, const QList &data, const std::shared_ptr &stack, bool isRoot = false);
+ AbstractEffectItem(EffectItemType type, const QList &data, const std::shared_ptr &stack, bool isRoot = false, bool isEnabled = true);
/* @brief This function change the individual enabled state of the effect, creating an undo/redo entry*/
void markEnabled(const QString &name, bool enabled);
/* @brief This function directly change the individual enabled state of the effect */
void setEnabled(bool enabled);
/* @brief This function change the global (effectstack-wise) enabled state of the effect */
void setEffectStackEnabled(bool enabled);
/* @brief Returns whether the effect is enabled */
bool isEnabled() const;
friend class EffectGroupModel;
EffectItemType effectItemType() const;
/* @brief Return true if the effect or effect group applies only to audio */
virtual bool isAudio() const = 0;
/* @brief This function plants the effect into the given service in last position
*/
virtual void plant(const std::weak_ptr &service) = 0;
/* @brief This function unplants (removes) the effect from the given service
*/
virtual void unplant(const std::weak_ptr &service) = 0;
protected:
/* @brief Toogles the mlt effect according to the current activation state*/
virtual void updateEnable() = 0;
EffectItemType m_effectItemType;
bool m_enabled;
bool m_effectStackEnabled;
};
#endif
diff --git a/src/effects/effectstack/model/effectitemmodel.cpp b/src/effects/effectstack/model/effectitemmodel.cpp
index 582206e66..210895999 100644
--- a/src/effects/effectstack/model/effectitemmodel.cpp
+++ b/src/effects/effectstack/model/effectitemmodel.cpp
@@ -1,134 +1,132 @@
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#include "effectitemmodel.hpp"
#include "core.h"
#include "effects/effectsrepository.hpp"
#include "effectstackmodel.hpp"
#include
EffectItemModel::EffectItemModel(const QList &data, Mlt::Properties *effect, const QDomElement &xml, const QString &effectId,
- const std::shared_ptr &stack)
- : AbstractEffectItem(EffectItemType::Effect, data, stack)
+ const std::shared_ptr &stack, bool isEnabled)
+ : AbstractEffectItem(EffectItemType::Effect, data, stack, false, isEnabled)
, AssetParameterModel(effect, xml, effectId, std::static_pointer_cast(stack)->getOwnerId())
{
}
// static
std::shared_ptr EffectItemModel::construct(const QString &effectId, std::shared_ptr stack)
{
Q_ASSERT(EffectsRepository::get()->exists(effectId));
QDomElement xml = EffectsRepository::get()->getXml(effectId);
Mlt::Properties *effect = EffectsRepository::get()->getEffect(effectId);
effect->set("kdenlive_id", effectId.toUtf8().constData());
QList data;
data << EffectsRepository::get()->getName(effectId) << effectId;
- std::shared_ptr self(new EffectItemModel(data, effect, xml, effectId, std::move(stack)));
+ std::shared_ptr self(new EffectItemModel(data, effect, xml, effectId, std::move(stack), true));
baseFinishConstruct(self);
return self;
}
// static
std::shared_ptr EffectItemModel::construct(Mlt::Properties *effect, std::shared_ptr stack)
{
QString effectId = effect->get("kdenlive_id");
if (effectId.isEmpty()) {
effectId = effect->get("mlt_service");
}
Q_ASSERT(EffectsRepository::get()->exists(effectId));
QDomElement xml = EffectsRepository::get()->getXml(effectId);
QDomNodeList params = xml.elementsByTagName(QStringLiteral("parameter"));
for (int i = 0; i < params.count(); ++i) {
QDomElement currentParameter = params.item(i).toElement();
QString paramName = currentParameter.attribute(QStringLiteral("name"));
QString paramValue = effect->get(paramName.toUtf8().constData());
currentParameter.setAttribute(QStringLiteral("value"), paramValue);
}
QList data;
data << EffectsRepository::get()->getName(effectId) << effectId;
- std::shared_ptr self(new EffectItemModel(data, effect, xml, effectId, std::move(stack)));
-
+ std::shared_ptr self(new EffectItemModel(data, effect, xml, effectId, std::move(stack), effect->get_int("disable") == 0));
baseFinishConstruct(self);
-
return self;
}
void EffectItemModel::plant(const std::weak_ptr &service)
{
if (auto ptr = service.lock()) {
int ret = ptr->attach(filter());
Q_ASSERT(ret == 0);
} else {
qDebug() << "Error : Cannot plant effect because parent service is not available anymore";
Q_ASSERT(false);
}
}
void EffectItemModel::unplant(const std::weak_ptr &service)
{
if (auto ptr = service.lock()) {
int ret = ptr->detach(filter());
Q_ASSERT(ret == 0);
} else {
qDebug() << "Error : Cannot plant effect because parent service is not available anymore";
Q_ASSERT(false);
}
}
Mlt::Filter &EffectItemModel::filter() const
{
return *static_cast(m_asset.get());
}
void EffectItemModel::updateEnable()
{
filter().set("disable", isEnabled() ? 0 : 1);
pCore->refreshProjectItem(m_ownerId);
if (auto ptr = m_model.lock()) {
QModelIndex index = ptr->getIndexFromId(m_id);
emit dataChanged(index, index, QVector());
} else {
qDebug() << "Error, unable to send update to deleted model";
Q_ASSERT(false);
}
}
void EffectItemModel::setCollapsed(bool collapsed)
{
filter().set("kdenlive:collapsed", collapsed ? 1 : 0);
}
bool EffectItemModel::isCollapsed()
{
return filter().get_int("kdenlive:collapsed") == 1;
}
bool EffectItemModel::isAudio() const
{
return EffectsRepository::get()->getType(getAssetId()) == EffectType::Audio;
}
diff --git a/src/effects/effectstack/model/effectitemmodel.hpp b/src/effects/effectstack/model/effectitemmodel.hpp
index 74a79f39a..53f61f6f3 100644
--- a/src/effects/effectstack/model/effectitemmodel.hpp
+++ b/src/effects/effectstack/model/effectitemmodel.hpp
@@ -1,68 +1,68 @@
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#ifndef EFFECTITEMMODEL_H
#define EFFECTITEMMODEL_H
#include "abstracteffectitem.hpp"
#include "abstractmodel/treeitem.hpp"
#include "assets/model/assetparametermodel.hpp"
#include
class EffectStackModel;
/* @brief This represents an effect of the effectstack
*/
class EffectItemModel : public AbstractEffectItem, public AssetParameterModel
{
public:
/* This construct an effect of the given id
@param is a ptr to the model this item belongs to. This is required to send update signals
*/
static std::shared_ptr construct(const QString &effectId, std::shared_ptr stack);
/* This construct an effect with an already existing filter
Only used when loading an existing clip
*/
static std::shared_ptr construct(Mlt::Properties *effect, std::shared_ptr stack);
/* @brief This function plants the effect into the given service in last position
*/
void plant(const std::weak_ptr &service) override;
/* @brief This function unplants (removes) the effect from the given service
*/
void unplant(const std::weak_ptr &service) override;
Mlt::Filter &filter() const;
/* @brief Return true if the effect applies only to audio */
bool isAudio() const override;
void setCollapsed(bool collapsed);
bool isCollapsed();
protected:
EffectItemModel(const QList &data, Mlt::Properties *effect, const QDomElement &xml, const QString &effectId,
- const std::shared_ptr &stack);
+ const std::shared_ptr &stack, bool isEnabled = true);
void updateEnable() override;
};
#endif