[Fonts] Keep ChatView on the app font and share the report log font

- ChatLog's unset fallback is qApp->font() again: ChatView never set a font
  before the role existed, so an unset role must not switch chat and the game
  log to monospace at the system GeneralFont size.
- Move the monospace fallback the report dialogs used before into
  report_utils::reportLogFont(), which returns the theme's ChatLog role when it
  is set and the old monospace otherwise. tab_report, dlg_my_reports and
  dlg_report_user now share it, so they cannot drift and they honour a themed
  size instead of overriding it.
This commit is contained in:
Lukas Brübach 2026-11-01 14:06:05 +01:00
parent 1bdd43d921
commit 4e78edf794
7 changed files with 42 additions and 38 deletions

View file

@ -660,17 +660,9 @@ QFont ThemeManager::appFont(AppFont::Role role) const
} }
// Role fallbacks preserve the pre-theme defaults when no fonts.toml is // Role fallbacks preserve the pre-theme defaults when no fonts.toml is
// present: chat logs rendered monospace (matching the report dialogs), // present: card text starts from a serif basis, everything else from the
// card text from a serif basis, everything else from the app font. // application font. The report dialogs that used to hardcode monospace ask
if (role == AppFont::ChatLog) { // for it explicitly (report_utils::reportLogFont).
QFont monoFont(QStringLiteral("monospace"));
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
return monoFont;
}
if (role == AppFont::CardText) { if (role == AppFont::CardText) {
return QFont(QStringLiteral("Serif")); return QFont(QStringLiteral("Serif"));
} }
@ -680,6 +672,11 @@ QFont ThemeManager::appFont(AppFont::Role role) const
return qApp->font(); return qApp->font();
} }
bool ThemeManager::hasAppFont(AppFont::Role role) const
{
return currentFonts.fonts.contains(role);
}
QFont ThemeManager::defaultAppFont(AppFont::Role /*role*/) const QFont ThemeManager::defaultAppFont(AppFont::Role /*role*/) const
{ {
// No per-role scaling and no preview: an unset role resolves to the font // No per-role scaling and no preview: an unset role resolves to the font

View file

@ -150,10 +150,11 @@ public:
// when present, otherwise a palette-accent-derived fallback. // when present, otherwise a palette-accent-derived fallback.
QColor appColor(AppColor::Role role) const; QColor appColor(AppColor::Role role) const;
/** @brief Resolves an application font role: the theme's stored [Fonts] /** @brief Resolves an application font role: the theme's stored [Fonts]
* value when present, otherwise a per-role fallback (monospace for * value when present, otherwise a per-role fallback (serif basis
* ChatLog, serif basis for CardText, the application font for the * for CardText, the application font for the remaining roles). */
* remaining roles). */
QFont appFont(AppFont::Role role) const; QFont appFont(AppFont::Role role) const;
/** @brief Whether the active theme defines this role in fonts.toml. */
bool hasAppFont(AppFont::Role role) const;
/** @brief Resolves an application font role against the startup font only, /** @brief Resolves an application font role against the startup font only,
* ignoring any previewed config in currentFonts. Editors that show * ignoring any previewed config in currentFonts. Editors that show
* "what this role resolves to" must use this, because appFont() * "what this role resolves to" must use this, because appFont()

View file

@ -7,6 +7,7 @@
#include "libcockatrice/protocol/pb/serverinfo_report.pb.h" #include "libcockatrice/protocol/pb/serverinfo_report.pb.h"
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QFont>
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QHeaderView> #include <QHeaderView>
@ -125,14 +126,7 @@ DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
void DlgMyReports::applyChatLogFont() void DlgMyReports::applyChatLogFont()
{ {
// Family comes from the ChatLog theme role; size stays caller-side as before. chatLogEdit->setFont(report_utils::reportLogFont());
QFont monoFont = themeManager->appFont(AppFont::ChatLog);
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
chatLogEdit->setFont(monoFont);
} }
void DlgMyReports::refreshList() void DlgMyReports::refreshList()

View file

@ -1,11 +1,13 @@
#include "dlg_report_user.h" #include "dlg_report_user.h"
#include "../interface/theme_manager.h" #include "../interface/theme_manager.h"
#include "../utility/report_utils.h"
#include "abstract_client.h" #include "abstract_client.h"
#include "libcockatrice/protocol/pb/response.pb.h" #include "libcockatrice/protocol/pb/response.pb.h"
#include <QComboBox> #include <QComboBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFont>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
@ -124,14 +126,7 @@ DlgReportUser::DlgReportUser(AbstractClient *_client,
void DlgReportUser::applyChatLogFont() void DlgReportUser::applyChatLogFont()
{ {
// Family comes from the ChatLog theme role; size stays caller-side as before. chatLogEdit->setFont(report_utils::reportLogFont());
QFont monoFont = themeManager->appFont(AppFont::ChatLog);
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
chatLogEdit->setFont(monoFont);
} }
void DlgReportUser::actSubmit() void DlgReportUser::actSubmit()

View file

@ -13,6 +13,7 @@
#include <QComboBox> #include <QComboBox>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QFont>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -273,14 +274,7 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
void TabReport::applyChatLogFont() void TabReport::applyChatLogFont()
{ {
// Family comes from the ChatLog theme role; size stays caller-side as before. chatLogEdit->setFont(report_utils::reportLogFont());
QFont monoFont = themeManager->appFont(AppFont::ChatLog);
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
chatLogEdit->setFont(monoFont);
} }
void TabReport::retranslateUi() void TabReport::retranslateUi()

View file

@ -1,5 +1,6 @@
#include "report_utils.h" #include "report_utils.h"
#include "../../theme_manager.h"
#include "libcockatrice/protocol/pb/serverinfo_report.pb.h" #include "libcockatrice/protocol/pb/serverinfo_report.pb.h"
#include <QApplication> #include <QApplication>
@ -7,6 +8,7 @@
#include <QChar> #include <QChar>
#include <QColor> #include <QColor>
#include <QDateTime> #include <QDateTime>
#include <QFontDatabase>
#include <QPalette> #include <QPalette>
#include <QSharedPointer> #include <QSharedPointer>
#include <QTableWidget> #include <QTableWidget>
@ -19,6 +21,20 @@
namespace report_utils namespace report_utils
{ {
QFont reportLogFont()
{
if (themeManager->hasAppFont(AppFont::ChatLog)) {
return themeManager->appFont(AppFont::ChatLog);
}
QFont monoFont(QStringLiteral("monospace"));
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
return monoFont;
}
namespace namespace
{ {
QColor reportStatusColor(const QString &status) QColor reportStatusColor(const QString &status)

View file

@ -1,6 +1,7 @@
#ifndef REPORT_UTILS_H #ifndef REPORT_UTILS_H
#define REPORT_UTILS_H #define REPORT_UTILS_H
#include <QFont>
#include <QString> #include <QString>
#include <QtGlobal> #include <QtGlobal>
@ -11,6 +12,12 @@ class ServerInfo_Report;
namespace report_utils namespace report_utils
{ {
/** @brief Font for the report chat-log views: the theme's ChatLog role when it
* sets one, otherwise the monospace font these views used before the
* role existed. Shared by the three report surfaces so they cannot
* drift apart. */
QFont reportLogFont();
QString formatReportCategory(const QString &category); QString formatReportCategory(const QString &category);
QString formatReportTime(qint64 secondsSinceEpoch); QString formatReportTime(qint64 secondsSinceEpoch);