From 36899b4e06169b85638777602c6d62c6f160eca1 Mon Sep 17 00:00:00 2001 From: luisangelsm Date: Sun, 1 Feb 2026 14:26:22 +0100 Subject: [PATCH] Add new function to recolor svg files supporting 3 placeholders --- common/themes/icon_utils.cpp | 34 +++++++++++++++++++++++++--------- common/themes/icon_utils.h | 12 +++++++++--- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/common/themes/icon_utils.cpp b/common/themes/icon_utils.cpp index 826b31ef..0de175da 100644 --- a/common/themes/icon_utils.cpp +++ b/common/themes/icon_utils.cpp @@ -2,13 +2,6 @@ #include "yacreader_global.h" -QString recolorSvgXML(QString &svg, - const QString &placeHolder, - const QColor &color) -{ - return svg.replace(placeHolder, color.name(QColor::HexRgb), Qt::CaseInsensitive); -} - QString readSvg(const QString &resourcePath) { QFile in(resourcePath); @@ -48,6 +41,25 @@ QString writeSvg(const QString &svg, const QString &resourcePath, const QString return outPath; } +QString recolorSvgXML(QString &svg, + const QString &placeHolder, + const QColor &color) +{ + return svg.replace(placeHolder, color.name(QColor::HexRgb), Qt::CaseInsensitive); +} + +QString recoloredSvgToThemeFile(const QString &resourcePath, + const QColor &color, // #f0f (magenta) + const QString &themeName, + const QString &suffix) +{ + auto svg = readSvg(resourcePath); + + recolorSvgXML(svg, "#f0f", color); + + return writeSvg(svg, resourcePath, themeName, suffix); +} + QString recoloredSvgToThemeFile(const QString &resourcePath, const QColor &color1, // #f0f (magenta) const QColor &color2, // #0ff (cyan) @@ -63,13 +75,17 @@ QString recoloredSvgToThemeFile(const QString &resourcePath, } QString recoloredSvgToThemeFile(const QString &resourcePath, - const QColor &color, // #f0f (magenta) + const QColor &color1, // #f0f (magenta) + const QColor &color2, // #0ff (cyan) + const QColor &color3, // #ff0 (yellow) const QString &themeName, const QString &suffix) { auto svg = readSvg(resourcePath); - recolorSvgXML(svg, "#f0f", color); + recolorSvgXML(svg, "#f0f", color1); + recolorSvgXML(svg, "#0ff", color2); + recolorSvgXML(svg, "#ff0", color3); return writeSvg(svg, resourcePath, themeName, suffix); } diff --git a/common/themes/icon_utils.h b/common/themes/icon_utils.h index 014a1b69..132c4845 100644 --- a/common/themes/icon_utils.h +++ b/common/themes/icon_utils.h @@ -3,18 +3,24 @@ #include -QString recolorSvgXML(QString &svg, const QString &placeHolder, const QColor &color); QString readSvg(const QString &resourcePath); QString writeSvg(const QString &svg, const QString &resourcePath, const QString &themeName); + +QString recolorSvgXML(QString &svg, const QString &placeHolder, const QColor &color); +QString recoloredSvgToThemeFile(const QString &resourcePath, + const QColor &color, // #f0f (magenta) + const QString &themeName, + const QString &suffix = QString()); QString recoloredSvgToThemeFile(const QString &resourcePath, const QColor &color1, // #f0f (magenta) const QColor &color2, // #0ff (cyan) const QString &themeName, const QString &suffix = QString()); QString recoloredSvgToThemeFile(const QString &resourcePath, - const QColor &color, // #f0f (magenta) + const QColor &color1, // #f0f (magenta) + const QColor &color2, // #0ff (cyan) + const QColor &color3, // #ff0 (yellow) const QString &themeName, const QString &suffix = QString()); -QString createMenuArrowSvg(const QColor &color, const QString &themeName); #endif // ICON_UTILS_H