diff --git a/src/assets/assetlist/model/assettreemodel.cpp b/src/assets/assetlist/model/assettreemodel.cpp index cc6e61d4b..3ec52cde2 100644 --- a/src/assets/assetlist/model/assettreemodel.cpp +++ b/src/assets/assetlist/model/assettreemodel.cpp @@ -1,124 +1,128 @@ /*************************************************************************** * 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 "assettreemodel.hpp" #include "abstractmodel/treeitem.hpp" #include "effects/effectsrepository.hpp" #include "transitions/transitionsrepository.hpp" int AssetTreeModel::nameCol = 0; int AssetTreeModel::idCol = 1; int AssetTreeModel::typeCol = 2; int AssetTreeModel::favCol = 3; AssetTreeModel::AssetTreeModel(QObject *parent) : AbstractTreeModel(parent) { } QHash AssetTreeModel::roleNames() const { QHash roles; roles[IdRole] = "identifier"; roles[NameRole] = "name"; roles[FavoriteRole] = "favorite"; return roles; } QString AssetTreeModel::getName(const QModelIndex &index) const { if (!index.isValid()) { return QString(); } std::shared_ptr item = getItemById((int)index.internalId()); if (item->depth() == 1) { return item->dataColumn(0).toString(); } return item->dataColumn(AssetTreeModel::nameCol).toString(); } bool AssetTreeModel::isFavorite(const QModelIndex &index) const { if (!index.isValid()) { return false; } std::shared_ptr item = getItemById((int)index.internalId()); if (item->depth() == 1) { return false; } return item->dataColumn(AssetTreeModel::favCol).toBool(); } -void AssetTreeModel::setFavorite(const QModelIndex &index, bool favorite) +void AssetTreeModel::setFavorite(const QModelIndex &index, bool favorite, bool isEffect) { if (!index.isValid()) { return; } std::shared_ptr item = getItemById((int)index.internalId()); - if (item->depth() == 1) { + if (isEffect && item->depth() == 1) { return; } item->setData(AssetTreeModel::favCol, favorite); auto id = item->dataColumn(AssetTreeModel::idCol).toString(); - if (EffectsRepository::get()->exists(id)) { - EffectsRepository::get()->setFavorite(id, favorite); - } else if (TransitionsRepository::get()->exists(id)) { - TransitionsRepository::get()->setFavorite(id, favorite); + if (isEffect) { + if (EffectsRepository::get()->exists(id)) { + EffectsRepository::get()->setFavorite(id, favorite); + } + } else { + if (TransitionsRepository::get()->exists(id)) { + TransitionsRepository::get()->setFavorite(id, favorite); + } } } QString AssetTreeModel::getDescription(const QModelIndex &index) const { if (!index.isValid()) { return QString(); } std::shared_ptr item = getItemById((int)index.internalId()); if (item->depth() == 1) { return QString(); } auto id = item->dataColumn(AssetTreeModel::idCol).toString(); if (EffectsRepository::get()->exists(id)) { return EffectsRepository::get()->getDescription(id); } if (TransitionsRepository::get()->exists(id)) { return TransitionsRepository::get()->getDescription(id); } return QString(); } QVariant AssetTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } std::shared_ptr item = getItemById((int)index.internalId()); switch(role) { case IdRole: return item->dataColumn(AssetTreeModel::idCol); case FavoriteRole: return item->dataColumn(AssetTreeModel::favCol); case NameRole: return item->dataColumn(index.column()); default: return QVariant(); } } diff --git a/src/assets/assetlist/model/assettreemodel.hpp b/src/assets/assetlist/model/assettreemodel.hpp index b61d31aca..db6af30ca 100644 --- a/src/assets/assetlist/model/assettreemodel.hpp +++ b/src/assets/assetlist/model/assettreemodel.hpp @@ -1,58 +1,58 @@ /*************************************************************************** * 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 ASSETTREEMODEL_H #define ASSETTREEMODEL_H #include "abstractmodel/abstracttreemodel.hpp" /* @brief This class represents an effect hierarchy to be displayed as a tree */ class TreeItem; class QMenu; class KActionCategory; class AssetTreeModel : public AbstractTreeModel { public: explicit AssetTreeModel(QObject *parent = 0); enum { IdRole = Qt::UserRole + 1, NameRole, FavoriteRole }; // Helper function to retrieve name QString getName(const QModelIndex &index) const; // Helper function to retrieve description QString getDescription(const QModelIndex &index) const; // Helper function to retrieve if an effect is categorized as favorite bool isFavorite(const QModelIndex &index) const; - void setFavorite(const QModelIndex &index, bool favorite); + void setFavorite(const QModelIndex &index, bool favorite, bool isEffect); QHash roleNames() const override; QVariant data(const QModelIndex &index, int role) const override; virtual void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) = 0; // for convenience, we store the column of each data field static int nameCol, idCol, favCol, typeCol; protected: }; #endif diff --git a/src/assets/assetlist/view/assetlistwidget.cpp b/src/assets/assetlist/view/assetlistwidget.cpp index 138895a3d..9f7d5e572 100644 --- a/src/assets/assetlist/view/assetlistwidget.cpp +++ b/src/assets/assetlist/view/assetlistwidget.cpp @@ -1,107 +1,107 @@ /*************************************************************************** * 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 "assetlistwidget.hpp" #include "assets/assetlist/view/qmltypes/asseticonprovider.hpp" #include #include #include #include #include AssetListWidget::AssetListWidget(QWidget *parent) : QQuickWidget(parent) , m_assetIconProvider(nullptr) { KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); #if KDECLARATIVE_VERSION >= QT_VERSION_CHECK(5, 45, 0) kdeclarative.setupEngine(engine()); kdeclarative.setupContext(); #else kdeclarative.setupBindings(); #endif } AssetListWidget::~AssetListWidget() { // clear source setSource(QUrl()); } void AssetListWidget::setup() { setResizeMode(QQuickWidget::SizeRootObjectToView); engine()->addImageProvider(QStringLiteral("asseticon"), m_assetIconProvider); setSource(QUrl(QStringLiteral("qrc:/qml/assetList.qml"))); setFocusPolicy(Qt::StrongFocus); } void AssetListWidget::reset() { setSource(QUrl(QStringLiteral("qrc:/qml/assetList.qml"))); } QString AssetListWidget::getName(const QModelIndex &index) const { return m_model->getName(m_proxyModel->mapToSource(index)); } bool AssetListWidget::isFavorite(const QModelIndex &index) const { return m_model->isFavorite(m_proxyModel->mapToSource(index)); } -void AssetListWidget::setFavorite(const QModelIndex &index, bool favorite) +void AssetListWidget::setFavorite(const QModelIndex &index, bool favorite, bool isEffect) { - m_model->setFavorite(m_proxyModel->mapToSource(index), favorite); + m_model->setFavorite(m_proxyModel->mapToSource(index), favorite, isEffect); } QString AssetListWidget::getDescription(const QModelIndex &index) const { return m_model->getDescription(m_proxyModel->mapToSource(index)); } void AssetListWidget::setFilterName(const QString &pattern) { m_proxyModel->setFilterName(!pattern.isEmpty(), pattern); if (!pattern.isEmpty()) { QVariantList mapped = m_proxyModel->getCategories(); QMetaObject::invokeMethod(rootObject(), "expandNodes", Qt::DirectConnection, Q_ARG(QVariant, mapped)); } } QVariantMap AssetListWidget::getMimeData(const QString &assetId) const { QVariantMap mimeData; mimeData.insert(getMimeType(assetId), assetId); return mimeData; } void AssetListWidget::activate(const QModelIndex &ix) { if (!ix.isValid()) { return; } const QString assetId = m_model->data(m_proxyModel->mapToSource(ix), AssetTreeModel::IdRole).toString(); emit activateAsset(getMimeData(assetId)); } diff --git a/src/assets/assetlist/view/assetlistwidget.hpp b/src/assets/assetlist/view/assetlistwidget.hpp index 4e6e0c672..74919b06a 100644 --- a/src/assets/assetlist/view/assetlistwidget.hpp +++ b/src/assets/assetlist/view/assetlistwidget.hpp @@ -1,82 +1,82 @@ /*************************************************************************** * 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 ASSETLISTWIDGET_H #define ASSETLISTWIDGET_H #include "../model/assetfilter.hpp" #include "../model/assettreemodel.hpp" #include "assets/assetlist/view/qmltypes/asseticonprovider.hpp" #include "effects/effectsrepository.hpp" #include #include /* @brief This class is a generic widget that display the list of available assets */ class AssetListWidget : public QQuickWidget { Q_OBJECT /* @brief Should the descriptive info box be displayed */ public: AssetListWidget(QWidget *parent = Q_NULLPTR); virtual ~AssetListWidget(); /* @brief Returns the name of the asset given its model index */ QString getName(const QModelIndex &index) const; /* @brief Returns true if this effect belongs to favorites */ bool isFavorite(const QModelIndex &index) const; /* @brief Returns true if this effect belongs to favorites */ - void setFavorite(const QModelIndex &index, bool favorite = true); + void setFavorite(const QModelIndex &index, bool favorite = true, bool isEffect = true); /* @brief Returns the description of the asset given its model index */ QString getDescription(const QModelIndex &index) const; /* @brief Sets the pattern against which the assets' names are filtered */ void setFilterName(const QString &pattern); /*@brief Return mime type used for drag and drop. It can be kdenlive/effect, kdenlive/composition or kdenlive/transition*/ virtual QString getMimeType(const QString &assetId) const = 0; QVariantMap getMimeData(const QString &assetId) const; void activate(const QModelIndex &ix); /* @brief Rebuild the view by resetting the source. Is there a better way? */ void reset(); protected: void setup(); std::shared_ptr m_model; std::unique_ptr m_proxyModel; // the QmlEngine takes ownership of the image provider AssetIconProvider *m_assetIconProvider; signals: void activateAsset(const QVariantMap data); }; #endif diff --git a/src/effects/effectlist/view/effectlistwidget.hpp b/src/effects/effectlist/view/effectlistwidget.hpp index 5c7c897cb..f7e123b8d 100644 --- a/src/effects/effectlist/view/effectlistwidget.hpp +++ b/src/effects/effectlist/view/effectlistwidget.hpp @@ -1,97 +1,97 @@ /*************************************************************************** * 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 EFFECTLISTWIDGET_H #define EFFECTLISTWIDGET_H #include "assets/assetlist/view/assetlistwidget.hpp" #include "kdenlivesettings.h" /* @brief This class is a widget that display the list of available effects */ class EffectFilter; class EffectTreeModel; class EffectListWidgetProxy; class KActionCategory; class QMenu; class EffectListWidget : public AssetListWidget { Q_OBJECT public: EffectListWidget(QWidget *parent = Q_NULLPTR); ~EffectListWidget(); void setFilterType(const QString &type); /*@brief Return mime type used for drag and drop. It will be kdenlive/effect*/ QString getMimeType(const QString &assetId) const override; void updateFavorite(const QModelIndex &index); void reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions); public slots: void reloadCustomEffect(const QString &path); private: EffectListWidgetProxy *m_proxy; signals: void reloadFavorites(); }; // see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property class EffectListWidgetProxy : public QObject { Q_OBJECT Q_PROPERTY(bool showDescription READ showDescription WRITE setShowDescription NOTIFY showDescriptionChanged) public: EffectListWidgetProxy(EffectListWidget *parent) : QObject(parent) , q(parent) { } Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); } Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); } - Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite);q->updateFavorite(index);} + Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite, true);q->updateFavorite(index);} Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); } Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); } Q_INVOKABLE void activate(const QModelIndex &ix) { q->activate(ix); } Q_INVOKABLE void setFilterType(const QString &type) { q->setFilterType(type); } Q_INVOKABLE void setFilterName(const QString &pattern) { q->setFilterName(pattern); } Q_INVOKABLE QString getMimeType(const QString &assetId) const { return q->getMimeType(assetId); } bool showDescription() const { return KdenliveSettings::showeffectinfo(); } void setShowDescription(bool show) { KdenliveSettings::setShoweffectinfo(show); emit showDescriptionChanged(); } signals: void showDescriptionChanged(); private: EffectListWidget *q; }; #endif diff --git a/src/transitions/transitionlist/view/transitionlistwidget.hpp b/src/transitions/transitionlist/view/transitionlistwidget.hpp index ee8db3b54..0b6d75f10 100644 --- a/src/transitions/transitionlist/view/transitionlistwidget.hpp +++ b/src/transitions/transitionlist/view/transitionlistwidget.hpp @@ -1,92 +1,92 @@ /*************************************************************************** * 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 TRANSITIONLISTWIDGET_H #define TRANSITIONLISTWIDGET_H #include "assets/assetlist/view/assetlistwidget.hpp" #include "kdenlivesettings.h" class TransitionListWidgetProxy; /* @brief This class is a widget that display the list of available effects */ class TransitionListWidget : public AssetListWidget { Q_OBJECT public: TransitionListWidget(QWidget *parent = Q_NULLPTR); ~TransitionListWidget(); void setFilterType(const QString &type); /*@brief Return mime type used for drag and drop. It will be kdenlive/composition or kdenlive/transition*/ QString getMimeType(const QString &assetId) const override; void updateFavorite(const QModelIndex &index); void downloadNewLumas(); private: TransitionListWidgetProxy *m_proxy; int getNewStuff(const QString &configFile); signals: void reloadFavorites(); }; // see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property class TransitionListWidgetProxy : public QObject { Q_OBJECT Q_PROPERTY(bool showDescription READ showDescription WRITE setShowDescription NOTIFY showDescriptionChanged) public: TransitionListWidgetProxy(TransitionListWidget *parent) : QObject(parent) , q(parent) { } Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); } Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); } - Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite); q->updateFavorite(index); } + Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite, false); q->updateFavorite(index); } Q_INVOKABLE void setFilterType(const QString &type) { q->setFilterType(type); } Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); } Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); } Q_INVOKABLE void activate(const QModelIndex &ix) { q->activate(ix); } Q_INVOKABLE void setFilterName(const QString &pattern) { q->setFilterName(pattern); } Q_INVOKABLE QString getMimeType(const QString &assetId) const { return q->getMimeType(assetId); } Q_INVOKABLE void downloadNewLumas() { q->downloadNewLumas(); } bool showDescription() const { return KdenliveSettings::showeffectinfo(); } void setShowDescription(bool show) { KdenliveSettings::setShoweffectinfo(show); emit showDescriptionChanged(); } signals: void showDescriptionChanged(); private: TransitionListWidget *q; }; #endif