core/icon: add icon image provider

This commit is contained in:
outfoxxed 2024-04-05 17:54:51 -07:00
parent 8e530b6b77
commit d47a7f2cff
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 31 additions and 1 deletions

View file

@ -22,6 +22,7 @@ qt_add_library(quickshell-core STATIC
incubator.cpp incubator.cpp
lazyloader.cpp lazyloader.cpp
easingcurve.cpp easingcurve.cpp
iconimageprovider.cpp
) )
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}") set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}")

View file

@ -14,6 +14,7 @@
#include <qqmlincubator.h> #include <qqmlincubator.h>
#include <qtimer.h> #include <qtimer.h>
#include "iconimageprovider.hpp"
#include "incubator.hpp" #include "incubator.hpp"
#include "plugin.hpp" #include "plugin.hpp"
#include "qsintercept.hpp" #include "qsintercept.hpp"
@ -30,6 +31,8 @@ EngineGeneration::EngineGeneration(QmlScanner scanner)
this->engine.addUrlInterceptor(&this->urlInterceptor); this->engine.addUrlInterceptor(&this->urlInterceptor);
this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory); this->engine.setNetworkAccessManagerFactory(&this->interceptNetFactory);
this->engine.setIncubationController(&this->delayedIncubationController); this->engine.setIncubationController(&this->delayedIncubationController);
this->engine.addImageProvider("icon", new IconImageProvider());
} }
EngineGeneration::~EngineGeneration() { EngineGeneration::~EngineGeneration() {

View file

@ -0,0 +1,16 @@
#include "iconimageprovider.hpp"
#include <qicon.h>
#include <qlogging.h>
#include <qpixmap.h>
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;
}

View file

@ -0,0 +1,11 @@
#pragma once
#include <qpixmap.h>
#include <qquickimageprovider.h>
class IconImageProvider: public QQuickImageProvider {
public:
explicit IconImageProvider(): QQuickImageProvider(QQuickImageProvider::Pixmap) {}
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
};

View file

@ -1,6 +1,5 @@
set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES
CLASSNAME DBusPropertiesInterface CLASSNAME DBusPropertiesInterface
#INCLUDE dbus_properties_types.hpp
) )
qt_add_dbus_interface(DBUS_INTERFACES qt_add_dbus_interface(DBUS_INTERFACES