Commit 9c0574de authored by Nicolas Carion's avatar Nicolas Carion

abstarct away icon provider

parent 5d2ae613
......@@ -92,6 +92,7 @@ install(FILES kdenlivesettings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
kconfig_add_kcfg_files(kdenlive_SRCS kdenlivesettings.kcfgc)
add_subdirectory(abstractmodel)
add_subdirectory(assets)
add_subdirectory(effects)
add_subdirectory(doc)
add_subdirectory(project)
......
set(kdenlive_SRCS
${kdenlive_SRCS}
assets/assetlist/view/qmltypes/asseticonprovider.cpp
PARENT_SCOPE)
......@@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "effecticonprovider.hpp"
#include "asseticonprovider.hpp"
#include "effects/effectsrepository.hpp"
#include <QDebug>
#include <QIcon>
......@@ -27,12 +27,13 @@
#include <QFont>
#include "utils/KoIconUtils.h"
EffectIconProvider::EffectIconProvider()
AssetIconProvider::AssetIconProvider(bool effect)
: QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading)
{
m_effect = effect;
}
QImage EffectIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
QImage AssetIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
QImage result;
......@@ -41,7 +42,7 @@ QImage EffectIconProvider::requestImage(const QString &id, QSize *size, const QS
return pix.toImage();
}
if (EffectsRepository::get()->exists(id)) {
if (m_effect && EffectsRepository::get()->exists(id)) {
if (EffectsRepository::get()->getType(id) == EffectType::Custom) {
QIcon folder_icon = KoIconUtils::themedIcon(QStringLiteral("folder"));
result = folder_icon.pixmap(30,30).toImage();
......@@ -53,13 +54,13 @@ QImage EffectIconProvider::requestImage(const QString &id, QSize *size, const QS
*size = result.size();
}
} else {
qDebug() << "Effect not found "<<id;
qDebug() << "Asset not found "<<id;
}
return result;
}
QImage EffectIconProvider::makeIcon(const QString &effectId, const QString &effectName, const QSize& size)
QImage AssetIconProvider::makeIcon(const QString &effectId, const QString &effectName, const QSize& size)
{
QPixmap pix(30,30);
if (effectName.isEmpty()) {
......@@ -71,7 +72,10 @@ QImage EffectIconProvider::makeIcon(const QString &effectId, const QString &effe
uint hex = qHash(effectName);
QString t = "#" + QString::number(hex, 16).toUpper().left(6);
QColor col(t);
bool isAudio = EffectsRepository::get()->getType(effectId) == EffectType::Audio;
bool isAudio = false;
if (m_effect) {
isAudio = EffectsRepository::get()->getType(effectId) == EffectType::Audio;
}
if (isAudio) {
pix.fill(Qt::transparent);
} else {
......
......@@ -19,23 +19,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef EFFECTICONPROVIDER_H
#define EFFECTICONPROVIDER_H
#ifndef ASSETICONPROVIDER_H
#define ASSETICONPROVIDER_H
#include <QQuickImageProvider>
#include <KImageCache>
#include <QCache>
#include <memory>
class EffectIconProvider : public QQuickImageProvider
class AssetIconProvider : public QQuickImageProvider
{
public:
explicit EffectIconProvider();
explicit AssetIconProvider(bool effect);
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
private:
QImage makeIcon(const QString &effectId, const QString &effectName, const QSize& size);
std::unique_ptr<KImageCache> m_cache;
bool m_effect;
};
#endif
......@@ -2,7 +2,6 @@ set(kdenlive_SRCS
${kdenlive_SRCS}
effects/effectsrepository.cpp
effects/effectlist/view/effectlistwidget.cpp
effects/effectlist/view/qmltypes/effecticonprovider.cpp
effects/effectlist/model/effecttreemodel.cpp
effects/effectlist/model/effectfilter.cpp
PARENT_SCOPE)
......
......@@ -22,6 +22,7 @@
#include "effectlistwidget.hpp"
#include "../model/effecttreemodel.hpp"
#include "../model/effectfilter.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include <KDeclarative/KDeclarative>
#include <QStandardPaths>
......@@ -49,8 +50,8 @@ EffectListWidget::EffectListWidget(QWidget *parent)
rootContext()->setContextProperty("assetListModel", m_proxyModel);
rootContext()->setContextProperty("isEffectList", true);
m_effectIconProvider.reset(new EffectIconProvider);
engine()->addImageProvider(QStringLiteral("asseticon"), m_effectIconProvider.get());
m_assetIconProvider.reset(new AssetIconProvider(true));
engine()->addImageProvider(QStringLiteral("asseticon"), m_assetIconProvider.get());
setSource(QUrl(QStringLiteral("qrc:/qml/assetList.qml")));
setFocusPolicy(Qt::StrongFocus);
}
......
......@@ -24,8 +24,8 @@
#include <QQuickWidget>
#include <memory>
#include "qmltypes/effecticonprovider.hpp"
#include "effects/effectsrepository.hpp"
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
/* @brief This class is a widget that display the list of available effects
*/
......@@ -48,7 +48,7 @@ private:
std::unique_ptr<EffectTreeModel> m_model;
EffectFilter *m_proxyModel;
std::unique_ptr<EffectIconProvider> m_effectIconProvider;
std::unique_ptr<AssetIconProvider> m_assetIconProvider;
signals:
};
......
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