From abb569c99602febfec6d5822b26d36eb1af4a83f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 19 Dec 2017 11:13:03 +0100 Subject: Set the imageprovider as part of the framework plugin --- framework/src/frameworkplugin.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'framework/src/frameworkplugin.cpp') diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 4aff5708..1de776a5 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -42,6 +42,47 @@ #include "controller.h" #include +#include +#include + +class KubeImageProvider : public QQuickImageProvider +{ +public: + KubeImageProvider() + : QQuickImageProvider(QQuickImageProvider::Pixmap) + { + } + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE + { + //The platform theme plugin can overwrite our setting again once it gets loaded, + //so we check on every icon load request... + if (QIcon::themeName() != "kube") { + QIcon::setThemeName("kube"); + } + const auto icon = QIcon::fromTheme(id); + auto expectedSize = requestedSize; + //Get the largest size that is still smaller or equal than requested + //Except if we only have larger sizes, then just pick the closest one + bool first = true; + for (const auto s : icon.availableSizes()) { + if (first && s.width() > requestedSize.width()) { + expectedSize = s; + break; + } + first = false; + if (s.width() <= requestedSize.width()) { + expectedSize = s; + } + } + const auto pixmap = icon.pixmap(expectedSize); + if (size) { + *size = pixmap.size(); + } + return pixmap; + } +}; + static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { @@ -66,6 +107,12 @@ static QObject *keyring_singletontype_provider(QQmlEngine *engine, QJSEngine *sc return instance; } +void FrameworkPlugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + Q_UNUSED(uri); + engine->addImageProvider(QLatin1String("kube"), new KubeImageProvider); +} + void FrameworkPlugin::registerTypes (const char *uri) { qmlRegisterType(uri, 1, 0, "FolderListModel"); -- cgit v1.2.3