summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/kube/main.cpp41
-rw-r--r--framework/src/frameworkplugin.cpp47
-rw-r--r--framework/src/frameworkplugin.h3
3 files changed, 49 insertions, 42 deletions
diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp
index 345d35bf..a7a3354e 100644
--- a/applications/kube/main.cpp
+++ b/applications/kube/main.cpp
@@ -36,8 +36,6 @@
36#include <QJsonDocument> 36#include <QJsonDocument>
37#include <QFileInfo> 37#include <QFileInfo>
38 38
39#include <QStandardPaths>
40#include <QQuickImageProvider>
41#include <QIcon> 39#include <QIcon>
42#include <QtWebEngine> 40#include <QtWebEngine>
43 41
@@ -133,44 +131,6 @@ void terminateHandler()
133 std::abort(); 131 std::abort();
134} 132}
135 133
136class KubeImageProvider : public QQuickImageProvider
137{
138public:
139 KubeImageProvider()
140 : QQuickImageProvider(QQuickImageProvider::Pixmap)
141 {
142 }
143
144 QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE
145 {
146 //The platform theme plugin can overwrite our setting again once it gets loaded,
147 //so we check on every icon load request...
148 if (QIcon::themeName() != "kube") {
149 QIcon::setThemeName("kube");
150 }
151 const auto icon = QIcon::fromTheme(id);
152 auto expectedSize = requestedSize;
153 //Get the largest size that is still smaller or equal than requested
154 //Except if we only have larger sizes, then just pick the closest one
155 bool first = true;
156 for (const auto s : icon.availableSizes()) {
157 if (first && s.width() > requestedSize.width()) {
158 expectedSize = s;
159 break;
160 }
161 first = false;
162 if (s.width() <= requestedSize.width()) {
163 expectedSize = s;
164 }
165 }
166 const auto pixmap = icon.pixmap(expectedSize);
167 if (size) {
168 *size = pixmap.size();
169 }
170 return pixmap;
171 }
172};
173
174int main(int argc, char *argv[]) 134int main(int argc, char *argv[])
175{ 135{
176 std::signal(SIGSEGV, crashHandler); 136 std::signal(SIGSEGV, crashHandler);
@@ -211,7 +171,6 @@ int main(int argc, char *argv[])
211 QIcon::setThemeName("kube"); 171 QIcon::setThemeName("kube");
212 172
213 QQmlApplicationEngine engine; 173 QQmlApplicationEngine engine;
214 engine.addImageProvider(QLatin1String("kube"), new KubeImageProvider);
215 const auto file = "/org/kube/components/kube/main.qml"; 174 const auto file = "/org/kube/components/kube/main.qml";
216 const auto mainFile = [&] { 175 const auto mainFile = [&] {
217 for (const auto &path : engine.importPathList()) { 176 for (const auto &path : engine.importPathList()) {
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
48class KubeImageProvider : public QQuickImageProvider
49{
50public:
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
46static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) 87static 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
110void FrameworkPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
111{
112 Q_UNUSED(uri);
113 engine->addImageProvider(QLatin1String("kube"), new KubeImageProvider);
114}
115
69void FrameworkPlugin::registerTypes (const char *uri) 116void 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
31public: 31public:
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};