Commit 01c26990 authored by Julius Künzel's avatar Julius Künzel
Browse files

Add infrastruture for template effects

Template effects are basically pre-installed custom effects
parent 87785e11
......@@ -51,8 +51,8 @@ QImage AssetIconProvider::makeIcon(const QString &effectName, const QSize &size)
bool isGroup = false;
AssetListType::AssetType type = AssetListType::AssetType(effectName.section(QLatin1Char('/'), -1).toInt());
if (m_effect) {
isAudio = type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio;
isCustom = type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::Custom;
isAudio = type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::TemplateAudio;
isCustom = type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::Custom || type == AssetListType::AssetType::Template || type == AssetListType::AssetType::TemplateAudio;
if (isCustom) {
//isGroup = EffectsRepository::get()->isGroup(effectId);
}
......
......@@ -87,7 +87,7 @@ enum EditMode { NormalEdit = 0, OverwriteEdit = 1, InsertEdit = 2 };
namespace AssetListType {
Q_NAMESPACE
enum AssetType { Preferred, Video, Audio, Custom, CustomAudio, Favorites, AudioComposition, VideoShortComposition, VideoComposition, AudioTransition, VideoTransition, Hidden = -1 };
enum AssetType { Preferred, Video, Audio, Custom, CustomAudio, Template, TemplateAudio, Favorites, AudioComposition, VideoShortComposition, VideoComposition, AudioTransition, VideoTransition, Hidden = -1 };
Q_ENUM_NS(AssetType)
}
......
......@@ -44,7 +44,7 @@ bool EffectFilter::filterType(const std::shared_ptr<TreeItem> &item) const
return item->dataColumn(AssetTreeModel::preferredCol).toBool();
}
if (m_type_value == AssetListType::AssetType::Custom) {
return itemType == m_type_value || itemType == AssetListType::AssetType::CustomAudio;
return itemType == m_type_value || itemType == AssetListType::AssetType::CustomAudio || itemType == AssetListType::Template || itemType == AssetListType::TemplateAudio;
}
return itemType == m_type_value;
}
......
......@@ -21,6 +21,7 @@
EffectTreeModel::EffectTreeModel(QObject *parent)
: AssetTreeModel(parent)
, m_customCategory(nullptr)
, m_templateCategory(nullptr)
{
}
......@@ -62,11 +63,13 @@ std::shared_ptr<EffectTreeModel> EffectTreeModel::construct(const QString &categ
miscCategory = self->rootItem->appendChild(QList<QVariant>{i18n("Misc"), QStringLiteral("root")});
audioCategory = self->rootItem->appendChild(QList<QVariant>{i18n("Audio"), QStringLiteral("root")});
self->m_customCategory = self->rootItem->appendChild(QList<QVariant>{i18n("Custom"), QStringLiteral("root")});
self->m_templateCategory = self->rootItem->appendChild(QList<QVariant>{i18n("Templates"), QStringLiteral("root")});
} else {
// Flat view
miscCategory = self->rootItem;
audioCategory = self->rootItem;
self->m_customCategory = self->rootItem;
self->m_templateCategory = self->rootItem;
}
// We parse effects
......@@ -84,6 +87,9 @@ std::shared_ptr<EffectTreeModel> EffectTreeModel::construct(const QString &categ
if (type == AssetListType::AssetType::Custom || type == AssetListType::AssetType::CustomAudio) {
targetCategory = self->m_customCategory;
}
if (type == AssetListType::AssetType::Template || type == AssetListType::AssetType::TemplateAudio) {
targetCategory = self->m_templateCategory;
}
// we create the data list corresponding to this profile
bool isFav = KdenliveSettings::favorite_effects().contains(effect.first);
......
......@@ -30,6 +30,7 @@ public:
protected:
std::shared_ptr<TreeItem> m_customCategory;
std::shared_ptr<TreeItem> m_templateCategory;
};
#endif
......@@ -81,9 +81,17 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
}
QString type = base.attribute(QStringLiteral("type"), QString());
if (type == QLatin1String("customAudio")) {
result.type = AssetListType::AssetType::CustomAudio;
if (file_name.contains(QStringLiteral("effect-templates"))) {
result.type = AssetListType::AssetType::TemplateAudio;
} else {
result.type = AssetListType::AssetType::CustomAudio;
}
} else {
result.type = AssetListType::AssetType::Custom;
if (file_name.contains(QStringLiteral("effect-templates"))) {
result.type = AssetListType::AssetType::Template;
} else {
result.type = AssetListType::AssetType::Custom;
}
}
result.id = base.attribute(QStringLiteral("id"), QString());
if (result.id.isEmpty()) {
......@@ -165,7 +173,9 @@ std::unique_ptr<EffectsRepository> &EffectsRepository::get()
QStringList EffectsRepository::assetDirs() const
{
return QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("effects"), QStandardPaths::LocateDirectory);
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("effect-templates"), QStandardPaths::LocateDirectory);
dirs.append(QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("effects"), QStandardPaths::LocateDirectory));
return dirs;
}
void EffectsRepository::parseType(QScopedPointer<Mlt::Properties> &metadata, Info &res)
......@@ -394,7 +404,7 @@ bool EffectsRepository::isAudioEffect(const QString &assetId) const
{
if (m_assets.count(assetId) > 0) {
AssetListType::AssetType type = m_assets.at(assetId).type;
return type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio;
return type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::TemplateAudio ;
}
return false;
}
......@@ -222,8 +222,7 @@ bool EffectItemModel::hasForcedInOut() const
bool EffectItemModel::isAudio() const
{
AssetListType::AssetType type = EffectsRepository::get()->getType(m_assetId);
return type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio;
return EffectsRepository::get()->isAudioEffect(m_assetId);
}
bool EffectItemModel::isUnique() const
......
......@@ -309,8 +309,7 @@ bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &re
for (int i = 0; i < nodeList.count(); ++i) {
QDomElement node = nodeList.item(i).toElement();
const QString effectId = node.attribute(QStringLiteral("id"));
AssetListType::AssetType type = EffectsRepository::get()->getType(effectId);
bool isAudioEffect = type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio;
bool isAudioEffect = EffectsRepository::get()->isAudioEffect(effectId);
if (isAudioEffect) {
if (state != PlaylistState::AudioOnly) {
continue;
......
......@@ -719,8 +719,7 @@ void ClipModel::setTimelineEffectsEnabled(bool enabled)
bool ClipModel::addEffect(const QString &effectId)
{
QWriteLocker locker(&m_lock);
AssetListType::AssetType type = EffectsRepository::get()->getType(effectId);
if (type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio) {
if (EffectsRepository::get()->isAudioEffect(effectId)) {
if (m_currentState == PlaylistState::VideoOnly) {
return false;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment