qt: Use system default fixed pitch font for Console (#3831)

* Use system default fixed pitch font for Console

* qt: RPCConsole::messagesWidget - Directly apply the fixed pitch font

Instead of setting the font family in the stylesheet.

* qt: Introduce vecIgnoreObjects and add messagesWidget to it

Exclude messagesWidget from font updates because it should have a fixed pitch font.

* qt: Set the default consoleFontSize based on the used font

* Clamp consoleFontSize instead of ignoring invalid values

Co-authored-by: xdustinface <xdustinfacex@gmail.com>
This commit is contained in:
UdjinM6 2020-11-28 22:26:40 +03:00 committed by GitHub
parent 46eddc8e03
commit 13c1ffb345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -1576,12 +1576,16 @@ void updateFonts()
std::map<QWidget*, QFont> mapWidgetFonts;
// Loop through all widgets
for (QWidget* w : qApp->allWidgets()) {
std::vector<QString> vecIgnore{
std::vector<QString> vecIgnoreClasses{
"QWidget", "QDialog", "QFrame", "QStackedWidget", "QDesktopWidget", "QDesktopScreenWidget",
"QTipLabel", "QMessageBox", "QMenu", "QComboBoxPrivateScroller", "QComboBoxPrivateContainer",
"QScrollBar", "QListView", "BitcoinGUI", "WalletView", "WalletFrame"
};
if (std::find(vecIgnore.begin(), vecIgnore.end(), w->metaObject()->className()) != vecIgnore.end()) {
std::vector<QString> vecIgnoreObjects{
"messagesWidget"
};
if (std::find(vecIgnoreClasses.begin(), vecIgnoreClasses.end(), w->metaObject()->className()) != vecIgnoreClasses.end() ||
std::find(vecIgnoreObjects.begin(), vecIgnoreObjects.end(), w->objectName()) != vecIgnoreObjects.end()) {
continue;
}
++nUpdatable;

View File

@ -31,6 +31,7 @@
#include <QButtonGroup>
#include <QDir>
#include <QDesktopWidget>
#include <QFontDatabase>
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
@ -527,7 +528,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(GUIUtil::getFontNormal()).pointSize()).toInt();
setFontSize(settings.value(fontSizeSettingsKey, QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).pointSize()).toInt());
pageButtons = new QButtonGroup(this);
pageButtons->addButton(ui->btnInfo, pageButtons->buttons().size());
@ -778,9 +779,7 @@ void RPCConsole::setFontSize(int newSize)
{
QSettings settings;
//don't allow an insane font size
if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
return;
newSize = std::min(std::max(newSize, FONT_RANGE.width()), FONT_RANGE.height());
// temp. store the console content
QString str = ui->messagesWidget->toHtml();
@ -876,15 +875,15 @@ void RPCConsole::clear(bool clearHistory)
ui->lineEdit->setFocus();
// Set default style sheet
QFontInfo fixedFontInfo(GUIUtil::getFontNormal());
ui->messagesWidget->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
ui->messagesWidget->document()->setDefaultStyleSheet(
QString(
"table { }"
"td.time { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_SECONDARY) + " font-size: %2; } "
"td.message { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_PRIMARY) + " font-family: %1; font-size: %2; white-space:pre-wrap; } "
"td.time { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_SECONDARY) + " font-size: %1pt; } "
"td.message { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_PRIMARY) + " font-size: %1pt; white-space:pre-wrap; } "
"td.cmd-request, b { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_COMMAND) + " } "
"td.cmd-error, .secwarning { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + " }"
).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
).arg(consoleFontSize)
);
#ifdef Q_OS_MAC