frontend: Add icon coloring for labels

Updates idian utils to also support QLabel widgets for icon coloring.
This commit is contained in:
Warchamp7
2026-09-01 16:15:04 -04:00
committed by Ryan Foster
parent eee6a81ddc
commit 49aff0cc87
3 changed files with 30 additions and 6 deletions
@@ -17,10 +17,10 @@
#include <Idian/StateEventFilter.hpp>
#include <Idian/Utils.hpp>
#include <QAbstractButton>
#include <QFocusEvent>
#include <QStyleOptionButton>
#include <QTimer>
#include <QLabel>
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<QLabel *>(widget)) {
QMetaObject::invokeMethod(
this, [this, label]() { utils->applyColorToIcon(label); }, Qt::QueuedConnection);
} else if (QAbstractButton *button = qobject_cast<QAbstractButton *>(widget)) {
QMetaObject::invokeMethod(
this, [this, button]() { utils->applyColorToIcon(button); }, Qt::QueuedConnection);
}
}
return QObject::eventFilter(obj, event);
+16 -2
View File
@@ -20,13 +20,14 @@
#include <Idian/StateEventFilter.hpp>
#include <QAbstractButton>
#include <QLabel>
#include <QPainter>
#include <QStyleOptionButton>
#include <QStyleOptionFrame>
namespace idian {
void Utils::applyColorToIcon(QWidget *widget)
void Utils::applyColorToIcon(QAbstractButton *button)
{
QAbstractButton *button = qobject_cast<QAbstractButton *>(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();
+5 -1
View File
@@ -21,6 +21,9 @@
#include <QStyle>
#include <QWidget>
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);