From 49aff0cc8773fe69c5dddf20350969de667029f2 Mon Sep 17 00:00:00 2001 From: Warchamp7 Date: Fri, 28 Aug 2026 20:31:05 +0200 Subject: [PATCH] frontend: Add icon coloring for labels Updates idian utils to also support QLabel widgets for icon coloring. --- .../idian/include/Idian/StateEventFilter.cpp | 12 +++++++++--- shared/qt/idian/include/Idian/Utils.cpp | 18 ++++++++++++++++-- shared/qt/idian/include/Idian/Utils.hpp | 6 +++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/shared/qt/idian/include/Idian/StateEventFilter.cpp b/shared/qt/idian/include/Idian/StateEventFilter.cpp index 9fca1f6a5..be7820a29 100644 --- a/shared/qt/idian/include/Idian/StateEventFilter.cpp +++ b/shared/qt/idian/include/Idian/StateEventFilter.cpp @@ -17,10 +17,10 @@ #include #include + #include #include -#include -#include +#include namespace idian { StateEventFilter::StateEventFilter(idian::Utils *utils, QWidget *target) : QObject(target), target(target), utils(utils) @@ -102,7 +102,13 @@ bool StateEventFilter::eventFilter(QObject *obj, QEvent *event) if (updateIconColors) { // Delay icon update - QTimer::singleShot(0, this, [this, widget]() { utils->applyColorToIcon(widget); }); + if (QLabel *label = qobject_cast(widget)) { + QMetaObject::invokeMethod( + this, [this, label]() { utils->applyColorToIcon(label); }, Qt::QueuedConnection); + } else if (QAbstractButton *button = qobject_cast(widget)) { + QMetaObject::invokeMethod( + this, [this, button]() { utils->applyColorToIcon(button); }, Qt::QueuedConnection); + } } return QObject::eventFilter(obj, event); diff --git a/shared/qt/idian/include/Idian/Utils.cpp b/shared/qt/idian/include/Idian/Utils.cpp index f1ecd4068..6783590d0 100644 --- a/shared/qt/idian/include/Idian/Utils.cpp +++ b/shared/qt/idian/include/Idian/Utils.cpp @@ -20,13 +20,14 @@ #include #include +#include #include #include +#include namespace idian { -void Utils::applyColorToIcon(QWidget *widget) +void Utils::applyColorToIcon(QAbstractButton *button) { - QAbstractButton *button = qobject_cast(widget); if (button && !button->icon().isNull()) { // Filter is on a widget with an icon set, update its colors QStyleOptionButton opt; @@ -42,6 +43,19 @@ void Utils::applyColorToIcon(QWidget *widget) } } +void Utils::applyColorToIcon(QLabel *label) +{ + if (label && !label->pixmap().isNull()) { + QStyleOptionFrame opt; + opt.initFrom(label); + + QColor color = opt.palette.color(QPalette::Text); + QPixmap tinted = recolorPixmap(label->pixmap(), color); + + label->setPixmap(tinted); + } +} + QPixmap Utils::recolorPixmap(const QPixmap &src, const QColor &color) { QImage img = src.toImage(); diff --git a/shared/qt/idian/include/Idian/Utils.hpp b/shared/qt/idian/include/Idian/Utils.hpp index 0dd5fb0f5..9ada1f5f0 100644 --- a/shared/qt/idian/include/Idian/Utils.hpp +++ b/shared/qt/idian/include/Idian/Utils.hpp @@ -21,6 +21,9 @@ #include #include +class QAbstractButton; +class QLabel; + namespace idian { // Helpers for OBS Idian widgets @@ -114,7 +117,8 @@ public: } } - static void applyColorToIcon(QWidget *widget); + static void applyColorToIcon(QAbstractButton *button); + static void applyColorToIcon(QLabel *label); static QPixmap recolorPixmap(const QPixmap &src, const QColor &color);