Commit 92e51289 authored by Nicolas Carion's avatar Nicolas Carion

Abstract away effectlistwidget

parent 6266d020
set(kdenlive_SRCS
${kdenlive_SRCS}
assets/assetlist/view/qmltypes/asseticonprovider.cpp
assets/assetlist/view/assetlistwidget.cpp
assets/assetlist/model/assetfilter.cpp
assets/assetlist/model/assettreemodel.cpp
PARENT_SCOPE)
......
/***************************************************************************
* 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 "assetlistwidget.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include <KDeclarative/KDeclarative>
#include <QStandardPaths>
#include <QQmlContext>
AssetListWidget::AssetListWidget(QWidget *parent)
: QQuickWidget(parent)
{
}
void AssetListWidget::setup()
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setupBindings();
setResizeMode(QQuickWidget::SizeRootObjectToView);
engine()->addImageProvider(QStringLiteral("asseticon"), m_assetIconProvider.get());
setSource(QUrl(QStringLiteral("qrc:/qml/assetList.qml")));
setFocusPolicy(Qt::StrongFocus);
}
QString AssetListWidget::getName(const QModelIndex& index) const
{
return m_model->getName(m_proxyModel->mapToSource(index));
}
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);
}
/***************************************************************************
* 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/>. *
***************************************************************************/
#ifndef ASSETLISTWIDGET_H
#define ASSETLISTWIDGET_H
#include <QQuickWidget>
#include <memory>
#include "effects/effectsrepository.hpp"
#include "../model/assettreemodel.hpp"
#include "../model/assetfilter.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
/* @brief This class is a generic widget that display the list of available assets
*/
class AssetListWidget : public QQuickWidget
{
Q_OBJECT
public:
AssetListWidget(QWidget *parent = Q_NULLPTR);
Q_INVOKABLE QString getName(const QModelIndex& index) const;
Q_INVOKABLE QString getDescription(const QModelIndex& index) const;
Q_INVOKABLE void setFilterName(const QString& pattern);
protected:
void setup();
std::unique_ptr<AssetTreeModel> m_model;
std::unique_ptr<AssetFilter> m_proxyModel;
std::unique_ptr<AssetIconProvider> m_assetIconProvider;
signals:
};
#endif
......@@ -24,63 +24,39 @@
#include "../model/effectfilter.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include <KDeclarative/KDeclarative>
#include <QStandardPaths>
#include <QQmlContext>
EffectListWidget::EffectListWidget(QWidget *parent)
: QQuickWidget(parent)
: AssetListWidget(parent)
{
QString effectCategory = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdenliveeffectscategory.rc"));
m_model.reset(new EffectTreeModel(effectCategory, this));
m_proxyModel = new EffectFilter(this);
m_proxyModel.reset(new EffectFilter(this));
m_proxyModel->setSourceModel(m_model.get());
m_proxyModel->setSortRole(EffectTreeModel::NameRole);
m_proxyModel->sort(0, Qt::AscendingOrder);
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setupBindings();
setResizeMode(QQuickWidget::SizeRootObjectToView);
rootContext()->setContextProperty("assetlist", this);
rootContext()->setContextProperty("assetListModel", m_proxyModel);
rootContext()->setContextProperty("assetListModel", m_proxyModel.get());
rootContext()->setContextProperty("isEffectList", true);
m_assetIconProvider.reset(new AssetIconProvider(true));
engine()->addImageProvider(QStringLiteral("asseticon"), m_assetIconProvider.get());
setSource(QUrl(QStringLiteral("qrc:/qml/assetList.qml")));
setFocusPolicy(Qt::StrongFocus);
}
QString EffectListWidget::getName(const QModelIndex& index) const
{
return m_model->getName(m_proxyModel->mapToSource(index));
}
QString EffectListWidget::getDescription(const QModelIndex& index) const
{
return m_model->getDescription(m_proxyModel->mapToSource(index));
}
void EffectListWidget::setFilterName(const QString& pattern)
{
m_proxyModel->setFilterName(!pattern.isEmpty(), pattern);
setup();
}
void EffectListWidget::setFilterType(const QString& type)
{
if (type == "video") {
m_proxyModel->setFilterType(true, EffectType::Video);
static_cast<EffectFilter*>(m_proxyModel.get())->setFilterType(true, EffectType::Video);
} else if (type == "audio") {
m_proxyModel->setFilterType(true, EffectType::Audio);
static_cast<EffectFilter*>(m_proxyModel.get())->setFilterType(true, EffectType::Audio);
} else if (type == "custom") {
m_proxyModel->setFilterType(true, EffectType::Custom);
static_cast<EffectFilter*>(m_proxyModel.get())->setFilterType(true, EffectType::Custom);
} else {
m_proxyModel->setFilterType(false, EffectType::Video);
static_cast<EffectFilter*>(m_proxyModel.get())->setFilterType(false, EffectType::Video);
}
}
......@@ -27,6 +27,7 @@
#include "effects/effectsrepository.hpp"
#include "../model/effecttreemodel.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include "assets/assetlist/view/assetlistwidget.hpp"
/* @brief This class is a widget that display the list of available effects
*/
......@@ -34,24 +35,14 @@
class EffectFilter;
class EffectTreeModel;
class EffectListWidget : public QQuickWidget
class EffectListWidget : public AssetListWidget
{
Q_OBJECT
public:
EffectListWidget(QWidget *parent = Q_NULLPTR);
Q_INVOKABLE QString getName(const QModelIndex& index) const;
Q_INVOKABLE QString getDescription(const QModelIndex& index) const;
Q_INVOKABLE void setFilterName(const QString& pattern);
Q_INVOKABLE void setFilterType(const QString& type);
private:
std::unique_ptr<EffectTreeModel> m_model;
EffectFilter *m_proxyModel;
std::unique_ptr<AssetIconProvider> m_assetIconProvider;
signals:
};
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment