File indexing completed on 2024-05-19 04:53:43

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "effects/effectsrepository.hpp"
0009 #include <QTreeView>
0010 #include <QWidget>
0011 #include <memory>
0012 
0013 class AssetIconProvider;
0014 class AssetFilter;
0015 class AssetTreeModel;
0016 class QToolBar;
0017 class QVBoxLayout;
0018 class QMenu;
0019 class QTextDocument;
0020 class QLineEdit;
0021 
0022 /** @class AssetListWidget
0023     @brief This class is a generic widget that display the list of available assets
0024  */
0025 class AssetListWidget : public QWidget
0026 {
0027     Q_OBJECT
0028     /** @brief Should the descriptive info box be displayed
0029      */
0030     Q_PROPERTY(bool showDescription READ showDescription WRITE setShowDescription NOTIFY showDescriptionChanged)
0031 
0032 public:
0033     AssetListWidget(bool isEffect, QWidget *parent = Q_NULLPTR);
0034     ~AssetListWidget() override;
0035 
0036     virtual bool isEffect() const = 0;
0037 
0038     /** @brief Returns the name of the asset given its model index */
0039     QString getName(const QModelIndex &index) const;
0040 
0041     /** @brief Returns true if this effect belongs to favorites */
0042     bool isFavorite(const QModelIndex &index) const;
0043 
0044     /** @brief Sets whether this effect belongs to favorites */
0045     void setFavorite(const QModelIndex &index, bool favorite = true);
0046 
0047     /** @brief Delete a custom effect */
0048     void deleteCustomEffect(const QModelIndex &index);
0049     virtual void reloadCustomEffectIx(const QModelIndex &index) = 0;
0050     virtual void reloadTemplates() = 0;
0051     virtual void editCustomAsset(const QModelIndex &index) = 0;
0052     /** @brief Returns the description of the asset given its model index */
0053     QString getDescription(const QModelIndex &index) const;
0054 
0055     /** @brief Sets the pattern against which the assets' names are filtered */
0056     void setFilterName(const QString &pattern);
0057 
0058     virtual void setFilterType(const QString &type) = 0;
0059 
0060     /** @brief Return mime type used for drag and drop. It can be kdenlive/effect,
0061      *  kdenlive/composition or kdenlive/transition
0062      */
0063     virtual QString getMimeType(const QString &assetId) const = 0;
0064     virtual bool isAudio(const QString &assetId) const = 0;
0065 
0066     QVariantMap getMimeData(const QString &assetId) const;
0067 
0068     void activate(const QModelIndex &ix);
0069     virtual void exportCustomEffect(const QModelIndex &index) = 0;
0070 
0071     /** @brief Should the descriptive info box be displayed
0072      */
0073     bool showDescription() const;
0074     void setShowDescription(bool show);
0075 
0076 private:
0077     QToolBar *m_toolbar;
0078     QVBoxLayout *m_lay;
0079     QTextDocument *m_infoDocument;
0080 
0081 protected:
0082     bool m_isEffect;
0083     std::shared_ptr<AssetTreeModel> m_model;
0084     std::unique_ptr<AssetFilter> m_proxyModel;
0085     QMenu *m_contextMenu;
0086     QLineEdit *m_searchLine;
0087     QTreeView *m_effectsTree;
0088     bool eventFilter(QObject *obj, QEvent *event) override;
0089     const QString buildLink(const QString id, AssetListType::AssetType type) const;
0090 
0091 private Q_SLOTS:
0092     void onCustomContextMenu(const QPoint &pos);
0093 
0094 public Q_SLOTS:
0095     void updateAssetInfo(const QModelIndex &current, const QModelIndex &);
0096     virtual void reloadCustomEffect(const QString &path) = 0;
0097 
0098 Q_SIGNALS:
0099     void activateAsset(const QVariantMap data);
0100     void showDescriptionChanged();
0101     void reloadFavorites();
0102 };