mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-06 01:53:25 -08:00
Compare commits
3 commits
816210dc20
...
ecc3ecd4ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecc3ecd4ea | ||
|
|
c0aeaf72e8 | ||
|
|
c63a359c3d |
4 changed files with 32 additions and 16 deletions
|
|
@ -76,9 +76,11 @@ void FontGridWidget::loadFonts(const FontConfig &cfg)
|
|||
auto role = static_cast<AppFont::Role>(fontEnum.value(i));
|
||||
const FontRow &row = fontRows[role];
|
||||
|
||||
// Roles absent from the file resolve to the theme's effective font, so
|
||||
// unset roles visibly show the system default instead of blanks.
|
||||
const QFont font = cfg.fonts.value(role, themeManager->appFont(role));
|
||||
// Roles absent from the file resolve to the startup font, not to the
|
||||
// live preview: appFont() would return the previewed config, so Reset
|
||||
// and a first load would both show the edited font instead of the
|
||||
// theme's real default.
|
||||
const QFont font = cfg.fonts.value(role, themeManager->defaultAppFont(role));
|
||||
row.familyCombo->setCurrentFont(font);
|
||||
|
||||
int size = font.pointSize();
|
||||
|
|
|
|||
|
|
@ -392,6 +392,10 @@ void PaletteEditorDialog::onReset()
|
|||
{
|
||||
workingConfig[loadedScheme] = savedConfig[loadedScheme];
|
||||
paletteGrid->loadPalette(savedConfig[loadedScheme]);
|
||||
// Restore the live theme before re-reading the grid: loadFonts resolves
|
||||
// unset roles, and the preview has currentFonts pointing at the edited
|
||||
// config until the theme is reloaded.
|
||||
themeManager->reloadCurrentTheme();
|
||||
fontGrid->loadFonts(savedFontConfig);
|
||||
seedAccentFromScheme(loadedScheme);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,9 +127,9 @@ static QString usableDefaultStyle(const QString &style)
|
|||
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
defaultStyleName = usableDefaultStyle(qApp->style()->objectName());
|
||||
// Capture the untouched application palette before any theme is applied.
|
||||
// Capture the untouched application palette and font before any theme is
|
||||
// applied.
|
||||
defaultPalette = qApp->palette();
|
||||
// Capture the untouched application font before any theme font is applied.
|
||||
defaultFont = qApp->font();
|
||||
ensureThemeDirectoryExists();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
|
|
@ -534,18 +534,15 @@ void ThemeManager::previewFonts(const FontConfig &cfg)
|
|||
{
|
||||
currentFonts = cfg;
|
||||
|
||||
// QApplication::setFont already sends a font change to every widget, so a
|
||||
// repolish pass is not needed for fonts (unlike the palette path).
|
||||
const auto it = cfg.fonts.constFind(AppFont::InterfaceDefault);
|
||||
if (it != cfg.fonts.constEnd()) {
|
||||
qApp->setFont(it.value());
|
||||
|
||||
// Repolish every widget immediately so the preview applies without
|
||||
// waiting for natural expose events, mirroring applyStyleAndPalette.
|
||||
QStyle *style = qApp->style();
|
||||
for (QWidget *widget : qApp->allWidgets()) {
|
||||
style->unpolish(widget);
|
||||
style->polish(widget);
|
||||
widget->update();
|
||||
}
|
||||
} else {
|
||||
// A config without InterfaceDefault means "no override": restore the
|
||||
// startup font instead of leaving the last preview applied.
|
||||
qApp->setFont(defaultFont);
|
||||
}
|
||||
|
||||
emit fontsChanged();
|
||||
|
|
@ -663,6 +660,14 @@ QFont ThemeManager::appFont(AppFont::Role role) const
|
|||
return qApp->font();
|
||||
}
|
||||
|
||||
QFont ThemeManager::defaultAppFont(AppFont::Role /*role*/) const
|
||||
{
|
||||
// No per-role scaling and no preview: an unset role resolves to the font
|
||||
// captured at startup, which is what the theme falls back to once the
|
||||
// editor closes.
|
||||
return defaultFont;
|
||||
}
|
||||
|
||||
void ThemeManager::themeChangedSlot()
|
||||
{
|
||||
QString themeName = SettingsCache::instance().getThemeName();
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ private:
|
|||
// switching away from a custom palette restores the original colours.
|
||||
QPalette defaultPalette;
|
||||
// Pristine application font captured at startup, before any theme font is
|
||||
// applied. Used to restore the original font when a theme supplies none,
|
||||
// mirroring defaultPalette above.
|
||||
// applied. Restored when a theme (or a preview) supplies no InterfaceDefault
|
||||
// font, so switching away from a themed font cannot leave it behind.
|
||||
QFont defaultFont;
|
||||
QString currentThemePath;
|
||||
std::array<QBrush, Role::MaxRole + 1> brushes;
|
||||
|
|
@ -152,6 +152,11 @@ public:
|
|||
/** @brief Resolves an application font role: the theme's stored [Fonts]
|
||||
* value when present, otherwise the application font. */
|
||||
QFont appFont(AppFont::Role role) const;
|
||||
/** @brief Resolves an application font role against the startup font only,
|
||||
* ignoring any previewed config in currentFonts. Editors that show
|
||||
* "what this role resolves to" must use this, because appFont()
|
||||
* reflects a live preview while the editor is open. */
|
||||
QFont defaultAppFont(AppFont::Role role) const;
|
||||
|
||||
QBrush &getBgBrush(Role zone);
|
||||
QBrush getExtraBgBrush(Role zone, int zoneId = 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue