effectlistwidget.cpp 3.16 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 24 25 26
/***************************************************************************
 *   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/effecttreemodel.hpp"
#include "../model/effectfilter.hpp"
#include "effects/effectsrepository.hpp"

Nicolas Carion's avatar
Nicolas Carion committed
27
#include <KDeclarative/KDeclarative>
28 29 30 31 32 33 34 35 36 37 38 39
#include <QStandardPaths>
#include <QQmlContext>

EffectListWidget::EffectListWidget(QWidget *parent)
    : QQuickWidget(parent)
{
    QString effectCategory = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdenliveeffectscategory.rc"));
    m_model.reset(new EffectTreeModel(effectCategory, this));


    m_proxyModel = new EffectFilter(this);
    m_proxyModel->setSourceModel(m_model.get());
Nicolas Carion's avatar
Nicolas Carion committed
40 41
    m_proxyModel->setSortRole(EffectTreeModel::NameRole);
    m_proxyModel->sort(0, Qt::AscendingOrder);
42

Nicolas Carion's avatar
Nicolas Carion committed
43 44 45 46
    KDeclarative::KDeclarative kdeclarative;
    kdeclarative.setDeclarativeEngine(engine());
    kdeclarative.setupBindings();

47 48
    setResizeMode(QQuickWidget::SizeRootObjectToView);
    rootContext()->setContextProperty("effectlist", this);
49
    rootContext()->setContextProperty("effectListModel", m_proxyModel);
50 51 52 53 54 55 56 57 58 59 60 61

    m_effectIconProvider.reset(new EffectIconProvider);
    engine()->addImageProvider(QStringLiteral("effecticon"), m_effectIconProvider.get());
    setSource(QUrl(QStringLiteral("qrc:/qml/effectList.qml")));
    setFocusPolicy(Qt::StrongFocus);
}


QString EffectListWidget::getName(const QModelIndex& index) const
{
    return m_model->getName(m_proxyModel->mapToSource(index));
}
62 63 64 65 66

QString EffectListWidget::getDescription(const QModelIndex& index) const
{
    return m_model->getDescription(m_proxyModel->mapToSource(index));
}
Nicolas Carion's avatar
Nicolas Carion committed
67 68 69 70 71

void EffectListWidget::setFilterName(const QString& pattern)
{
    m_proxyModel->setFilterName(!pattern.isEmpty(), pattern);
}