From bb33c9a0c4c16ad05220d948f63c88e1ce8bcf2a Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 11 Jul 2024 00:09:34 -0700 Subject: [PATCH] core/global: add Quickshell.iconPath Replaces "image://icon/" in user facing code. --- src/core/qmlglobal.cpp | 5 +++++ src/core/qmlglobal.hpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 05197f26..3321fcf3 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -19,6 +19,7 @@ #include #include "generation.hpp" +#include "iconimageprovider.hpp" #include "qmlscreen.hpp" #include "rootwrapper.hpp" @@ -188,6 +189,10 @@ QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT return qEnvironmentVariable(vstr.data()); } +QString QuickshellGlobal::iconPath(const QString& icon) { + return IconImageProvider::requestString(icon, ""); +} + QuickshellGlobal* QuickshellGlobal::create(QQmlEngine* engine, QJSEngine* /*unused*/) { auto* qsg = new QuickshellGlobal(); auto* generation = EngineGeneration::findEngineGeneration(engine); diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 8de55fc2..14d99c52 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -125,6 +125,11 @@ public: /// Returns the string value of an environment variable or null if it is not set. Q_INVOKABLE QVariant env(const QString& variable); + /// Returns a source string usable in an [Image] for a given system icon. + /// + /// [Image]: https://doc.qt.io/qt-6/qml-qtquick-image.html + Q_INVOKABLE static QString iconPath(const QString& icon); + [[nodiscard]] QString workingDirectory() const; void setWorkingDirectory(QString workingDirectory);