mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Fonts] Restore the startup font when a config has no InterfaceDefault
- Capture the untouched application font next to the default palette and use it in previewFonts' else branch, so a config without InterfaceDefault restores the startup font instead of leaving the last preview applied. - Drop the unpolish/polish loop from previewFonts: QApplication::setFont already notifies every widget, and the loop ran on every editor auto-apply.
This commit is contained in:
parent
58ee72543a
commit
c63a359c3d
2 changed files with 13 additions and 10 deletions
|
|
@ -127,8 +127,10 @@ static QString usableDefaultStyle(const QString &style)
|
||||||
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
|
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
defaultStyleName = usableDefaultStyle(qApp->style()->objectName());
|
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();
|
defaultPalette = qApp->palette();
|
||||||
|
defaultFont = qApp->font();
|
||||||
ensureThemeDirectoryExists();
|
ensureThemeDirectoryExists();
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||||
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, [this] {
|
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, [this] {
|
||||||
|
|
@ -520,18 +522,15 @@ void ThemeManager::previewFonts(const FontConfig &cfg)
|
||||||
{
|
{
|
||||||
currentFonts = 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);
|
const auto it = cfg.fonts.constFind(AppFont::InterfaceDefault);
|
||||||
if (it != cfg.fonts.constEnd()) {
|
if (it != cfg.fonts.constEnd()) {
|
||||||
qApp->setFont(it.value());
|
qApp->setFont(it.value());
|
||||||
|
} else {
|
||||||
// Repolish every widget immediately so the preview applies without
|
// A config without InterfaceDefault means "no override": restore the
|
||||||
// waiting for natural expose events, mirroring applyStyleAndPalette.
|
// startup font instead of leaving the last preview applied.
|
||||||
QStyle *style = qApp->style();
|
qApp->setFont(defaultFont);
|
||||||
for (QWidget *widget : qApp->allWidgets()) {
|
|
||||||
style->unpolish(widget);
|
|
||||||
style->polish(widget);
|
|
||||||
widget->update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit fontsChanged();
|
emit fontsChanged();
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ private:
|
||||||
// palette is applied. Used as the base when a theme supplies no palette, so
|
// palette is applied. Used as the base when a theme supplies no palette, so
|
||||||
// switching away from a custom palette restores the original colours.
|
// switching away from a custom palette restores the original colours.
|
||||||
QPalette defaultPalette;
|
QPalette defaultPalette;
|
||||||
|
// Pristine application font captured at startup, before any theme font is
|
||||||
|
// 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;
|
QString currentThemePath;
|
||||||
std::array<QBrush, Role::MaxRole + 1> brushes;
|
std::array<QBrush, Role::MaxRole + 1> brushes;
|
||||||
QStringMap availableThemes;
|
QStringMap availableThemes;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue