From d47a7f2cffdf2b0c2620ae31d9c8d805bf52b9dc Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 5 Apr 2024 17:54:51 -0700 Subject: [PATCH] core/icon: add icon image provider --- src/core/CMakeLists.txt | 1 + src/core/generation.cpp | 3 +++ src/core/iconimageprovider.cpp | 16 ++++++++++++++++ src/core/iconimageprovider.hpp | 11 +++++++++++ src/dbus/CMakeLists.txt | 1 - 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/core/iconimageprovider.cpp create mode 100644 src/core/iconimageprovider.hpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2cfae69..eaff747 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -22,6 +22,7 @@ qt_add_library(quickshell-core STATIC incubator.cpp lazyloader.cpp easingcurve.cpp + iconimageprovider.cpp ) set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}") diff --git a/src/core/generation.cpp b/src/core/generation.cpp index 76d1910..a925ec8 100644 --- a/src/core/generation.cpp +++ b/src/core/generation.cpp @@ -14,6 +14,7 @@ #include #include +#include "iconimageprovider.hpp" #include "incubator.hpp" #include "plugin.hpp" #include "qsintercept.hpp" @@ -30,6 +31,8 @@ EngineGeneration::EngineGeneration(QmlScanner scanner) this->engine.addUrlInterceptor(&this->urlInterceptor); this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory); this->engine.setIncubationController(&this->delayedIncubationController); + + this->engine.addImageProvider("icon", new IconImageProvider()); } EngineGeneration::~EngineGeneration() { diff --git a/src/core/iconimageprovider.cpp b/src/core/iconimageprovider.cpp new file mode 100644 index 0000000..45aa956 --- /dev/null +++ b/src/core/iconimageprovider.cpp @@ -0,0 +1,16 @@ +#include "iconimageprovider.hpp" + +#include +#include +#include + +QPixmap +IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) { + auto icon = QIcon::fromTheme(id); + + auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100); + auto pixmap = icon.pixmap(targetSize.width(), targetSize.height()); + + if (size != nullptr) *size = pixmap.size(); + return pixmap; +} diff --git a/src/core/iconimageprovider.hpp b/src/core/iconimageprovider.hpp new file mode 100644 index 0000000..eba59de --- /dev/null +++ b/src/core/iconimageprovider.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +class IconImageProvider: public QQuickImageProvider { +public: + explicit IconImageProvider(): QQuickImageProvider(QQuickImageProvider::Pixmap) {} + + QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override; +}; diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt index 1a0d23e..7ec9915 100644 --- a/src/dbus/CMakeLists.txt +++ b/src/dbus/CMakeLists.txt @@ -1,6 +1,5 @@ set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES CLASSNAME DBusPropertiesInterface - #INCLUDE dbus_properties_types.hpp ) qt_add_dbus_interface(DBUS_INTERFACES