mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Fonts] Migrate ChatLog surfaces to theme font role
This commit is contained in:
parent
ecc3ecd4ea
commit
2a3a31c24c
10 changed files with 85 additions and 24 deletions
|
|
@ -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>
|
||||||
|
|
@ -655,8 +656,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: chat logs rendered monospace (matching the report dialogs),
|
||||||
|
// card text from a serif basis, everything else from the app font.
|
||||||
|
if (role == 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;
|
||||||
|
}
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,9 @@ 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 (monospace for
|
||||||
|
* ChatLog, serif basis for CardText, the application font for the
|
||||||
|
* remaining roles). */
|
||||||
QFont appFont(AppFont::Role role) const;
|
QFont appFont(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
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#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"
|
||||||
|
|
@ -70,13 +71,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);
|
||||||
QFont monoFont("monospace");
|
applyChatLogFont();
|
||||||
monoFont.setStyleHint(QFont::Monospace);
|
connect(themeManager, &ThemeManager::fontsChanged, this, &DlgMyReports::applyChatLogFont);
|
||||||
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
|
|
||||||
if (systemPointSize > 0) {
|
|
||||||
monoFont.setPointSize(systemPointSize);
|
|
||||||
}
|
|
||||||
chatLogEdit->setFont(monoFont);
|
|
||||||
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);
|
||||||
|
|
@ -129,6 +125,18 @@ DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgMyReports::applyChatLogFont()
|
||||||
|
{
|
||||||
|
// Family comes from the ChatLog theme role; size stays caller-side as before.
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
selectedReportIdBeforeRefresh = selectedReportId;
|
selectedReportIdBeforeRefresh = selectedReportId;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "dlg_report_user.h"
|
#include "dlg_report_user.h"
|
||||||
|
|
||||||
|
#include "../interface/theme_manager.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
|
|
||||||
|
|
@ -92,13 +93,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);
|
||||||
QFont monoFont("monospace");
|
applyChatLogFont();
|
||||||
monoFont.setStyleHint(QFont::Monospace);
|
connect(themeManager, &ThemeManager::fontsChanged, this, &DlgReportUser::applyChatLogFont);
|
||||||
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
|
|
||||||
if (systemPointSize > 0) {
|
|
||||||
monoFont.setPointSize(systemPointSize);
|
|
||||||
}
|
|
||||||
chatLogEdit->setFont(monoFont);
|
|
||||||
if (!_autoChatLog.isEmpty()) {
|
if (!_autoChatLog.isEmpty()) {
|
||||||
chatLogEdit->setPlainText(_autoChatLog);
|
chatLogEdit->setPlainText(_autoChatLog);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -127,6 +123,18 @@ DlgReportUser::DlgReportUser(AbstractClient *_client,
|
||||||
layout->addWidget(buttonBox);
|
layout->addWidget(buttonBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgReportUser::applyChatLogFont()
|
||||||
|
{
|
||||||
|
// Family comes from the ChatLog theme role; size stays caller-side as before.
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
const QString description = descriptionEdit->toPlainText().trimmed();
|
const QString description = descriptionEdit->toPlainText().trimmed();
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
@ -138,13 +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);
|
||||||
QFont monoFont("monospace");
|
applyChatLogFont();
|
||||||
monoFont.setStyleHint(QFont::Monospace);
|
connect(themeManager, &ThemeManager::fontsChanged, this, &TabReport::applyChatLogFont);
|
||||||
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
|
|
||||||
if (systemPointSize > 0) {
|
|
||||||
monoFont.setPointSize(systemPointSize);
|
|
||||||
}
|
|
||||||
chatLogEdit->setFont(monoFont);
|
|
||||||
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);
|
||||||
|
|
@ -277,6 +273,18 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabReport::applyChatLogFont()
|
||||||
|
{
|
||||||
|
// Family comes from the ChatLog theme role; size stays caller-side as before.
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
userContextMenu->retranslateUi();
|
userContextMenu->retranslateUi();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue