effectlistwidget.cpp 4.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/***************************************************************************
 *   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 <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#include "effectlistwidget.hpp"
#include "../model/effectfilter.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
24
#include "../model/effecttreemodel.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
25
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
26

27
28
#include <KActionCategory>
#include <QMenu>
29
30
#include <QQmlContext>
#include <QStandardPaths>
Nicolas Carion's avatar
Nicolas Carion committed
31
#include <memory>
32
33
EffectListWidget::EffectListWidget(QWidget *parent)
    : AssetListWidget(parent)
34
{
35

36
    QString effectCategory = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdenliveeffectscategory.rc"));
37
    m_model = EffectTreeModel::construct(effectCategory, this);
38

Nicolas Carion's avatar
Nicolas Carion committed
39
    m_proxyModel = std::make_unique<EffectFilter>(this);
40
    m_proxyModel->setSourceModel(m_model.get());
Nicolas Carion's avatar
Nicolas Carion committed
41
42
    m_proxyModel->setSortRole(EffectTreeModel::NameRole);
    m_proxyModel->sort(0, Qt::AscendingOrder);
43
44
    m_proxy = new EffectListWidgetProxy(this);
    rootContext()->setContextProperty("assetlist", m_proxy);
45
    rootContext()->setContextProperty("assetListModel", m_proxyModel.get());
Nicolas Carion's avatar
Nicolas Carion committed
46
    rootContext()->setContextProperty("isEffectList", true);
47
    m_assetIconProvider = new AssetIconProvider(true);
48

49
    setup();
50
51
    // Activate "Main effects" filter
    setFilterType("");
Nicolas Carion's avatar
Nicolas Carion committed
52
}
53

54
55
56
void EffectListWidget::updateFavorite(const QModelIndex &index)
{
    m_proxyModel->dataChanged(index, index, QVector<int>());
57
58
    m_proxyModel->reloadFilterOnFavorite();
    emit reloadFavorites();
59
60
}

61
62
EffectListWidget::~EffectListWidget()
{
Nicolas Carion's avatar
linting    
Nicolas Carion committed
63
    qDebug() << " - - -Deleting effect list widget";
64
65
}

Nicolas Carion's avatar
Nicolas Carion committed
66
void EffectListWidget::setFilterType(const QString &type)
67
68
{
    if (type == "video") {
Nicolas Carion's avatar
Nicolas Carion committed
69
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, EffectType::Video);
70
    } else if (type == "audio") {
Nicolas Carion's avatar
Nicolas Carion committed
71
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, EffectType::Audio);
72
    } else if (type == "custom") {
Nicolas Carion's avatar
Nicolas Carion committed
73
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, EffectType::Custom);
74
75
    } else if (type == "favorites") {
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, EffectType::Favorites);
76
    } else {
77
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, EffectType::Preferred);
78
79
    }
}
80

Nicolas Carion's avatar
Nicolas Carion committed
81
QString EffectListWidget::getMimeType(const QString &assetId) const
82
83
84
85
{
    Q_UNUSED(assetId);
    return QStringLiteral("kdenlive/effect");
}
86

87
88
89
90
91
void EffectListWidget::reloadCustomEffect(const QString &path)
{
    static_cast<EffectTreeModel *>(m_model.get())->reloadEffect(path);
}

92
93
94
95
void EffectListWidget::reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions)
{
    m_model->reloadAssetMenu(effectsMenu, effectActions);
}