[Fonts] Migrate ChatLog surfaces to theme font role (#7537)

* [Fonts] Migrate ChatLog surfaces to theme font role

* [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.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-11-04 07:57:53 +01:00 • committed by GitHub
parent 634f8115a5
commit 7a40ed9079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 89 additions and 7 deletions

View file

@ -12,6 +12,7 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QFlags> #include <QFlags>
#include <QFontDatabase>
#include <QGuiApplication> #include <QGuiApplication>
#include <QIODevice> #include <QIODevice>
#include <QLatin1Char> #include <QLatin1Char>
@ -658,11 +659,24 @@ QFont ThemeManager::appFont(AppFont::Role role) const
return it.value(); return it.value();
} }
// No per-role scaling: every unset role resolves to the application font, // Role fallbacks preserve the pre-theme defaults when no fonts.toml is
// so with no fonts.toml present the result is identical to before. // present: card text starts from a serif basis, everything else from the
// application font. The report dialogs that used to hardcode monospace ask
// for it explicitly (report_utils::reportLogFont).
if (role == AppFont::CardText) {
return QFont(QStringLiteral("Serif"));
}
// No per-role scaling: every other unset role resolves to the application
// font, so with no fonts.toml present the result is identical to before.
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,8 +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 the application font. */ * value when present, otherwise a per-role fallback (serif basis
* for CardText, the application font for the 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

@ -1,11 +1,13 @@
#include "dlg_my_reports.h" #include "dlg_my_reports.h"
#include "../interface/theme_manager.h"
#include "../utility/report_utils.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 "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>
@ -24,7 +26,6 @@
#include <libcockatrice/protocol/pb/response_report_details.pb.h> #include <libcockatrice/protocol/pb/response_report_details.pb.h>
#include <libcockatrice/protocol/pb/response_report_my_list.pb.h> #include <libcockatrice/protocol/pb/response_report_my_list.pb.h>
#include <libcockatrice/protocol/pending_command.h> #include <libcockatrice/protocol/pending_command.h>
#include <libcockatrice/utility/qt_utils.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <string> #include <string>
@ -69,7 +70,8 @@ DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
auto *chatGroup = new QGroupBox(tr("Chat Log Context")); auto *chatGroup = new QGroupBox(tr("Chat Log Context"));
chatLogEdit = new QTextEdit; chatLogEdit = new QTextEdit;
chatLogEdit->setReadOnly(true); chatLogEdit->setReadOnly(true);
chatLogEdit->setFont(QtUtils::monospaceFont()); applyChatLogFont();
connect(themeManager, &ThemeManager::fontsChanged, this, &DlgMyReports::applyChatLogFont);
auto *chatLayout = new QVBoxLayout(chatGroup); auto *chatLayout = new QVBoxLayout(chatGroup);
chatLayout->setContentsMargins(4, 4, 4, 4); chatLayout->setContentsMargins(4, 4, 4, 4);
chatLayout->addWidget(chatLogEdit); chatLayout->addWidget(chatLogEdit);
@ -122,6 +124,11 @@ DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
refreshList(); refreshList();
} }
void DlgMyReports::applyChatLogFont()
{
chatLogEdit->setFont(report_utils::reportLogFont());
}
void DlgMyReports::refreshList() void DlgMyReports::refreshList()
{ {
selectedReportIdBeforeRefresh = selectedReportId; selectedReportIdBeforeRefresh = selectedReportId;

View file

@ -29,6 +29,7 @@ private slots:
void reportDetailsResponse(const Response &response); void reportDetailsResponse(const Response &response);
void addComment(); void addComment();
void addCommentResponse(const Response &response); void addCommentResponse(const Response &response);
void applyChatLogFont();
private: private:
void loadReportDetails(const ServerInfo_Report &report); void loadReportDetails(const ServerInfo_Report &report);

View file

@ -1,10 +1,13 @@
#include "dlg_report_user.h" #include "dlg_report_user.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>
@ -91,7 +94,8 @@ DlgReportUser::DlgReportUser(AbstractClient *_client,
auto *chatLayout = new QVBoxLayout(chatGroup); auto *chatLayout = new QVBoxLayout(chatGroup);
chatLogEdit = new QTextEdit; chatLogEdit = new QTextEdit;
chatLogEdit->setReadOnly(true); chatLogEdit->setReadOnly(true);
chatLogEdit->setFont(QtUtils::monospaceFont()); applyChatLogFont();
connect(themeManager, &ThemeManager::fontsChanged, this, &DlgReportUser::applyChatLogFont);
if (!_autoChatLog.isEmpty()) { if (!_autoChatLog.isEmpty()) {
chatLogEdit->setPlainText(_autoChatLog); chatLogEdit->setPlainText(_autoChatLog);
} else { } else {
@ -120,6 +124,11 @@ DlgReportUser::DlgReportUser(AbstractClient *_client,
layout->addWidget(buttonBox); layout->addWidget(buttonBox);
} }
void DlgReportUser::applyChatLogFont()
{
chatLogEdit->setFont(report_utils::reportLogFont());
}
void DlgReportUser::actSubmit() void DlgReportUser::actSubmit()
{ {
const QString description = descriptionEdit->toPlainText().trimmed(); const QString description = descriptionEdit->toPlainText().trimmed();

View file

@ -27,6 +27,7 @@ public:
private slots: private slots:
void actSubmit(); void actSubmit();
void reportResponse(const Response &response); void reportResponse(const Response &response);
void applyChatLogFont();
private: private:
static QString categoryLabel(const QString &key); static QString categoryLabel(const QString &key);

View file

@ -4,6 +4,7 @@
#include "../../client/sound_engine.h" #include "../../client/sound_engine.h"
#include "../../interface/card_localization.h" #include "../../interface/card_localization.h"
#include "../../interface/pixel_map_generator.h" #include "../../interface/pixel_map_generator.h"
#include "../../interface/theme_manager.h"
#include "../../tabs/tab_supervisor.h" #include "../../tabs/tab_supervisor.h"
#include "../user/user_context_menu.h" #include "../user/user_context_menu.h"
#include "../user/user_list_manager.h" #include "../user/user_list_manager.h"
@ -63,6 +64,9 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _sho
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, &ChatView::adjustColorsToPalette); connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, &ChatView::adjustColorsToPalette);
applyChatFont();
connect(themeManager, &ThemeManager::fontsChanged, this, &ChatView::applyChatFont);
userContextMenu = new UserContextMenu(tabSupervisor, this, game); userContextMenu = new UserContextMenu(tabSupervisor, this, game);
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool))); connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
@ -108,6 +112,16 @@ void ChatView::adjustColorsToPalette()
QTimer::singleShot(0, this, &ChatView::refreshBlockColors); QTimer::singleShot(0, this, &ChatView::refreshBlockColors);
} }
void ChatView::applyChatFont()
{
// Family comes from the ChatLog theme role; the message char formats carry
// no family of their own, so they (and new content) follow the widget and
// document default fonts. Weights/italics stay caller-side as before.
const QFont chatFont = themeManager->appFont(AppFont::ChatLog);
setFont(chatFont);
document()->setDefaultFont(chatFont);
}
void ChatView::refreshBlockColors() void ChatView::refreshBlockColors()
{ {
QTextDocument *doc = document(); QTextDocument *doc = document();

View file

@ -111,6 +111,7 @@ private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);
void actMessageClicked(); void actMessageClicked();
void adjustColorsToPalette(); void adjustColorsToPalette();
void applyChatFont();
void refreshBlockColors(); void refreshBlockColors();
void onScrollBarRangeChanged(); void onScrollBarRangeChanged();
void onScrollBarValueChanged(int value); void onScrollBarValueChanged(int value);

View file

@ -1,5 +1,6 @@
#include "tab_report.h" #include "tab_report.h"
#include "../interface/theme_manager.h"
#include "../server/user/user_context_menu.h" #include "../server/user/user_context_menu.h"
#include "../utility/report_utils.h" #include "../utility/report_utils.h"
#include "abstract_client.h" #include "abstract_client.h"
@ -12,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>
@ -137,7 +139,8 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
chatGroup = new QGroupBox; chatGroup = new QGroupBox;
chatLogEdit = new QTextEdit; chatLogEdit = new QTextEdit;
chatLogEdit->setReadOnly(true); chatLogEdit->setReadOnly(true);
chatLogEdit->setFont(QtUtils::monospaceFont()); applyChatLogFont();
connect(themeManager, &ThemeManager::fontsChanged, this, &TabReport::applyChatLogFont);
auto *chatLayout = new QVBoxLayout(chatGroup); auto *chatLayout = new QVBoxLayout(chatGroup);
chatLayout->setContentsMargins(4, 4, 4, 4); chatLayout->setContentsMargins(4, 4, 4, 4);
chatLayout->addWidget(chatLogEdit); chatLayout->addWidget(chatLogEdit);
@ -269,6 +272,11 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
refreshList(); refreshList();
} }
void TabReport::applyChatLogFont()
{
chatLogEdit->setFont(report_utils::reportLogFont());
}
void TabReport::retranslateUi() void TabReport::retranslateUi()
{ {
userContextMenu->retranslateUi(); userContextMenu->retranslateUi();

View file

@ -62,6 +62,7 @@ private slots:
void statsResponse(const Response &response); void statsResponse(const Response &response);
void reopenReport(); void reopenReport();
void reopenResponse(const Response &response); void reopenResponse(const Response &response);
void applyChatLogFont();
private: private:
int selectedReportId() const; int selectedReportId() const;

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);