diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index ef20ddddb7c..1b7ccee0b60 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -374,6 +374,19 @@ void Theme::setHelpMenu(QMenu *menu) #endif } +expected_str Theme::colorToken(const QString &tokenName, + [[maybe_unused]] TokenFlags flags) +{ + const QString colorName = "Token_" + tokenName; + static const QMetaEnum colorEnum = QMetaEnum::fromType(); + bool ok = false; + const Color result = static_cast(colorEnum.keyToValue(colorName.toLatin1(), &ok)); + if (!ok) + return make_unexpected(QString::fromLatin1("%1 - Color token \"%2\" not found.") + .arg(Q_FUNC_INFO).arg(tokenName)); + return result; +} + QPalette Theme::initialPalette() { if (!m_initialPalette) { diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h index dbf39780ac2..9508cfd7aeb 100644 --- a/src/libs/utils/theme/theme.h +++ b/src/libs/utils/theme/theme.h @@ -5,6 +5,8 @@ #include "../utils_global.h" +#include + #include // QGradientStops #include @@ -535,9 +537,14 @@ public: QDSTheme }; + enum TokenFlag { + UsedInToolbar = 1, + }; + Q_ENUM(Color) Q_ENUM(ImageFile) Q_ENUM(Flag) + Q_DECLARE_FLAGS(TokenFlags, TokenFlag) Q_INVOKABLE bool flag(Utils::Theme::Flag f) const; Q_INVOKABLE QColor color(Utils::Theme::Color role) const; @@ -560,6 +567,8 @@ public: static void setHelpMenu(QMenu *menu); + static expected_str colorToken(const QString &token, TokenFlags flags = {}); + protected: Theme(Theme *originTheme, QObject *parent = nullptr); ThemePrivate *d;