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; std::map<QWidget*, QFont> mapWidgetFonts;
// Loop through all widgets // Loop through all widgets
for (QWidget* w : qApp->allWidgets()) { for (QWidget* w : qApp->allWidgets()) {
std::vector<QString> vecIgnore{ std::vector<QString> vecIgnoreClasses{
"QWidget", "QDialog", "QFrame", "QStackedWidget", "QDesktopWidget", "QDesktopScreenWidget", "QWidget", "QDialog", "QFrame", "QStackedWidget", "QDesktopWidget", "QDesktopScreenWidget",
"QTipLabel", "QMessageBox", "QMenu", "QComboBoxPrivateScroller", "QComboBoxPrivateContainer", "QTipLabel", "QMessageBox", "QMenu", "QComboBoxPrivateScroller", "QComboBoxPrivateContainer",
"QScrollBar", "QListView", "BitcoinGUI", "WalletView", "WalletFrame" "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; continue;
} }
++nUpdatable; ++nUpdatable;

View File

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