diff options
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/frameworkplugin.cpp | 47 | ||||
-rw-r--r-- | framework/src/frameworkplugin.h | 3 |
2 files changed, 49 insertions, 1 deletions
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 @@ | |||
42 | #include "controller.h" | 42 | #include "controller.h" |
43 | 43 | ||
44 | #include <QtQml> | 44 | #include <QtQml> |
45 | #include <QQuickImageProvider> | ||
46 | #include <QIcon> | ||
47 | |||
48 | class KubeImageProvider : public QQuickImageProvider | ||
49 | { | ||
50 | public: | ||
51 | KubeImageProvider() | ||
52 | : QQuickImageProvider(QQuickImageProvider::Pixmap) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE | ||
57 | { | ||
58 | //The platform theme plugin can overwrite our setting again once it gets loaded, | ||
59 | //so we check on every icon load request... | ||
60 | if (QIcon::themeName() != "kube") { | ||
61 | QIcon::setThemeName("kube"); | ||
62 | } | ||
63 | const auto icon = QIcon::fromTheme(id); | ||
64 | auto expectedSize = requestedSize; | ||
65 | //Get the largest size that is still smaller or equal than requested | ||
66 | //Except if we only have larger sizes, then just pick the closest one | ||
67 | bool first = true; | ||
68 | for (const auto s : icon.availableSizes()) { | ||
69 | if (first && s.width() > requestedSize.width()) { | ||
70 | expectedSize = s; | ||
71 | break; | ||
72 | } | ||
73 | first = false; | ||
74 | if (s.width() <= requestedSize.width()) { | ||
75 | expectedSize = s; | ||
76 | } | ||
77 | } | ||
78 | const auto pixmap = icon.pixmap(expectedSize); | ||
79 | if (size) { | ||
80 | *size = pixmap.size(); | ||
81 | } | ||
82 | return pixmap; | ||
83 | } | ||
84 | }; | ||
85 | |||
45 | 86 | ||
46 | static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) | 87 | static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) |
47 | { | 88 | { |
@@ -66,6 +107,12 @@ static QObject *keyring_singletontype_provider(QQmlEngine *engine, QJSEngine *sc | |||
66 | return instance; | 107 | return instance; |
67 | } | 108 | } |
68 | 109 | ||
110 | void FrameworkPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | ||
111 | { | ||
112 | Q_UNUSED(uri); | ||
113 | engine->addImageProvider(QLatin1String("kube"), new KubeImageProvider); | ||
114 | } | ||
115 | |||
69 | void FrameworkPlugin::registerTypes (const char *uri) | 116 | void FrameworkPlugin::registerTypes (const char *uri) |
70 | { | 117 | { |
71 | qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); | 118 | qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); |
diff --git a/framework/src/frameworkplugin.h b/framework/src/frameworkplugin.h index 519e0ba9..d5fd918f 100644 --- a/framework/src/frameworkplugin.h +++ b/framework/src/frameworkplugin.h | |||
@@ -29,5 +29,6 @@ class FrameworkPlugin : public QQmlExtensionPlugin | |||
29 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") | 29 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") |
30 | 30 | ||
31 | public: | 31 | public: |
32 | virtual void registerTypes(const char *uri); | 32 | void registerTypes(const char *uri) Q_DECL_OVERRIDE; |
33 | void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE; | ||
33 | }; | 34 | }; |