effectlistwidget.cpp 5.72 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>
Vivek Yadav's avatar
Vivek Yadav committed
32 33 34 35 36 37
#include <QFormLayout>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <QTextEdit>

38 39
EffectListWidget::EffectListWidget(QWidget *parent)
    : AssetListWidget(parent)
40
{
41

42
    QString effectCategory = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdenliveeffectscategory.rc"));
43
    m_model = EffectTreeModel::construct(effectCategory, this);
44

Nicolas Carion's avatar
Nicolas Carion committed
45
    m_proxyModel = std::make_unique<EffectFilter>(this);
46
    m_proxyModel->setSourceModel(m_model.get());
Nicolas Carion's avatar
Nicolas Carion committed
47 48
    m_proxyModel->setSortRole(EffectTreeModel::NameRole);
    m_proxyModel->sort(0, Qt::AscendingOrder);
49 50
    m_proxy = new EffectListWidgetProxy(this);
    rootContext()->setContextProperty("assetlist", m_proxy);
51
    rootContext()->setContextProperty("assetListModel", m_proxyModel.get());
Nicolas Carion's avatar
Nicolas Carion committed
52
    rootContext()->setContextProperty("isEffectList", true);
53
    m_assetIconProvider = new AssetIconProvider(true);
54

55
    setup();
56 57
    // Activate "Main effects" filter
    setFilterType("");
Nicolas Carion's avatar
Nicolas Carion committed
58
}
59

60 61
void EffectListWidget::updateFavorite(const QModelIndex &index)
{
Vincent Pinon's avatar
Vincent Pinon committed
62
    emit m_proxyModel->dataChanged(index, index, QVector<int>());
63 64
    m_proxyModel->reloadFilterOnFavorite();
    emit reloadFavorites();
65 66
}

67 68
EffectListWidget::~EffectListWidget()
{
Nicolas Carion's avatar
linting  
Nicolas Carion committed
69
    qDebug() << " - - -Deleting effect list widget";
70 71
}

Nicolas Carion's avatar
Nicolas Carion committed
72
void EffectListWidget::setFilterType(const QString &type)
73 74
{
    if (type == "video") {
75
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, AssetListType::AssetType::Video);
76
    } else if (type == "audio") {
77
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, AssetListType::AssetType::Audio);
78
    } else if (type == "custom") {
79
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, AssetListType::AssetType::Custom);
80
    } else if (type == "favorites") {
81
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, AssetListType::AssetType::Favorites);
82
    } else {
83
        static_cast<EffectFilter *>(m_proxyModel.get())->setFilterType(true, AssetListType::AssetType::Preferred);
84 85
    }
}
86

Nicolas Carion's avatar
Nicolas Carion committed
87
QString EffectListWidget::getMimeType(const QString &assetId) const
88 89 90 91
{
    Q_UNUSED(assetId);
    return QStringLiteral("kdenlive/effect");
}
92

93 94 95 96 97 98 99
void EffectListWidget::reloadCustomEffectIx(const QModelIndex &index)
{
    static_cast<EffectTreeModel *>(m_model.get())->reloadEffectFromIndex(m_proxyModel->mapToSource(index));
    m_proxyModel->sort(0, Qt::AscendingOrder);
}


100 101 102
void EffectListWidget::reloadCustomEffect(const QString &path)
{
    static_cast<EffectTreeModel *>(m_model.get())->reloadEffect(path);
103
    m_proxyModel->sort(0, Qt::AscendingOrder);
104 105
}

106 107 108 109
void EffectListWidget::reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions)
{
    m_model->reloadAssetMenu(effectsMenu, effectActions);
}
Vivek Yadav's avatar
Vivek Yadav committed
110 111 112

void EffectListWidget::editCustomAsset(const QModelIndex &index)
{
Vivek Yadav's avatar
Vivek Yadav committed
113
    QDialog dialog(this);
Vivek Yadav's avatar
Vivek Yadav committed
114
    QFormLayout form(&dialog);
115
    QString currentName = getName(index);
Vivek Yadav's avatar
Vivek Yadav committed
116 117 118 119 120
    QString desc = getDescription(true, index);
    // Strip effect Name
    if (desc.contains(QLatin1Char('('))) {
        desc = desc.section(QLatin1Char('('), 0, -2).simplified();
    }
121
    QLineEdit *effectName = new QLineEdit(currentName, &dialog);
Vivek Yadav's avatar
Vivek Yadav committed
122
    QTextEdit *descriptionBox = new QTextEdit(desc, &dialog);
Vivek Yadav's avatar
Vivek Yadav committed
123 124
    form.addRow(i18n("Name : "), effectName);
    form.addRow(i18n("Comments : "), descriptionBox);
Vivek Yadav's avatar
Vivek Yadav committed
125 126 127 128 129
    QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
    form.addRow(&buttonBox);
    QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
    QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
    if(dialog.exec() == QDialog::Accepted) {
Vivek Yadav's avatar
Vivek Yadav committed
130 131 132 133 134 135 136
        QString name = effectName->text();
        QString enteredDescription = descriptionBox->toPlainText();
        if (name.trimmed().isEmpty() && enteredDescription.trimmed().isEmpty()) {
           return;
        }

        m_model->editCustomAsset(name, enteredDescription, m_proxyModel->mapToSource(index));
Vivek Yadav's avatar
Vivek Yadav committed
137
    }
Vivek Yadav's avatar
Vivek Yadav committed
138
}