mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-11 20:43:25 -08:00
The System theme derived icon ink from the platform palette, which rendered blue under the default palette. Author Icon/IconStrong/IconSoft explicitly: a black ladder in light mode, a white ladder in dark mode. Pin authorship, achromaticity and ordering in the render test.
140 lines
3.9 KiB
C++
140 lines
3.9 KiB
C++
#ifndef COCKATRICE_THEME_CONFIG_H
|
|
#define COCKATRICE_THEME_CONFIG_H
|
|
|
|
#include <QColor>
|
|
#include <QFont>
|
|
#include <QMap>
|
|
#include <QPalette>
|
|
#include <QSharedPointer>
|
|
#include <QString>
|
|
#include <qtmetamacros.h>
|
|
|
|
// Application-specific color roles, layered on top of the fixed QPalette role
|
|
// set. Stored in the same palette-<scheme>.toml under an [AppColors] section
|
|
// and editable from the palette editor, so theme authors can control colors
|
|
// beyond what Qt's palette can express.
|
|
//
|
|
// The icon families carry one role per emphasis level. Icon is the neutral
|
|
// glyph ink; IconStrong and IconSoft are its primary and quiet levels. Positive
|
|
// and Negative follow the same pattern, so an emphasis never has to be computed
|
|
// from a hue at paint time: the theme authors all three levels. Naming a variant
|
|
// explicitly (`IconStrong`) pins that level; naming the family (`Icon`) lets the
|
|
// caller's emphasis choose.
|
|
namespace AppColor
|
|
{
|
|
Q_NAMESPACE
|
|
enum Role
|
|
{
|
|
AccentStrong,
|
|
AccentSoft,
|
|
Icon,
|
|
IconStrong,
|
|
IconSoft,
|
|
Positive,
|
|
PositiveStrong,
|
|
PositiveSoft,
|
|
Negative,
|
|
NegativeStrong,
|
|
NegativeSoft,
|
|
};
|
|
Q_ENUM_NS(Role)
|
|
} // namespace AppColor
|
|
|
|
// Application-specific font roles, one configurable family + point size per
|
|
// purpose. Stored in a shared fonts.toml under a [Fonts] section (one file per
|
|
// theme, not split by light/dark). Only family and point size are stored;
|
|
// weight/italic are stripped on load and stay caller-side concerns.
|
|
namespace AppFont
|
|
{
|
|
Q_NAMESPACE
|
|
enum Role
|
|
{
|
|
InterfaceDefault,
|
|
ChatLog,
|
|
CardText,
|
|
DeckList,
|
|
};
|
|
Q_ENUM_NS(Role)
|
|
} // namespace AppFont
|
|
|
|
/**
|
|
* @brief Fallback for an application color role when the active theme does not
|
|
* define one.
|
|
*
|
|
* Accent roles and the neutral Icon family return an invalid QColor because
|
|
* ThemeManager derives them from the palette: the accent from the highlight,
|
|
* the icon ink from the neutral text color plus the highlight. Semantic roles
|
|
* return an opaque default that suits the scheme, so themes written before the
|
|
* role existed still render it. A theme with no authored icon family keeps
|
|
* deriving its icon ink from the platform palette instead of pinning one
|
|
* scheme's colors.
|
|
*/
|
|
QColor defaultAppColor(AppColor::Role role, bool dark);
|
|
|
|
struct ThemeConfig
|
|
{
|
|
QString colorScheme;
|
|
QString styleName;
|
|
|
|
bool isEmpty() const;
|
|
QString toIni() const;
|
|
|
|
static ThemeConfig fromThemeDir(const QString &themeDirPath);
|
|
bool save(const QString &themeDirPath) const;
|
|
};
|
|
|
|
struct PaletteConfig
|
|
{
|
|
QMap<QPalette::ColorGroup, QMap<QPalette::ColorRole, QColor>> colors;
|
|
QMap<AppColor::Role, QColor> appColors;
|
|
|
|
bool operator==(const PaletteConfig &rhs) const
|
|
{
|
|
return colors == rhs.colors && appColors == rhs.appColors;
|
|
}
|
|
bool operator!=(const PaletteConfig &rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
bool hasPalette() const;
|
|
QString toToml() const;
|
|
|
|
static QString fileName(const QString &colorScheme);
|
|
|
|
static PaletteConfig fromFile(const QString &filePath);
|
|
static PaletteConfig fromScheme(const QString &themeDirPath, const QString &colorScheme);
|
|
static PaletteConfig fromDefault(const QString &themeDirPath, const QString &colorScheme);
|
|
|
|
QPalette apply(QPalette base) const;
|
|
};
|
|
|
|
/** @brief Per-purpose font configuration, stored as family + point size only.
|
|
*
|
|
* Serialized to a shared fonts.toml file with a [Fonts] section, e.g.
|
|
* @code
|
|
* [Fonts]
|
|
* InterfaceDefault = "Inter, 10"
|
|
* @endcode
|
|
*/
|
|
struct FontConfig
|
|
{
|
|
QMap<AppFont::Role, QFont> fonts;
|
|
|
|
bool operator==(const FontConfig &rhs) const
|
|
{
|
|
return fonts == rhs.fonts;
|
|
}
|
|
bool operator!=(const FontConfig &rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
bool hasFonts() const;
|
|
QString toToml() const;
|
|
|
|
static QString fileName();
|
|
|
|
static FontConfig fromFile(const QString &filePath);
|
|
static FontConfig fromThemeDir(const QString &themeDirPath);
|
|
};
|
|
|
|
#endif // COCKATRICE_THEME_CONFIG_H
|