diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 52f5489c00..aeb1cab8ac 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -218,7 +218,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const QFont font; if(index.column() == Address) { - font = GUIUtil::fixedPitchFont(); + font = GUIUtil::getFontNormal(); } return font; } diff --git a/src/qt/appearancewidget.cpp b/src/qt/appearancewidget.cpp index 4fe3ae5fcf..b85a5e84ca 100644 --- a/src/qt/appearancewidget.cpp +++ b/src/qt/appearancewidget.cpp @@ -51,6 +51,12 @@ AppearanceWidget::AppearanceWidget(QWidget* parent) : connect(ui->fontScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontScale(int))); connect(ui->fontWeightNormalSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontWeightNormal(int))); connect(ui->fontWeightBoldSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontWeightBold(int))); + + connect(ui->theme, &QComboBox::currentTextChanged, [=]() { Q_EMIT appearanceChanged(); }); + connect(ui->fontFamily, &QComboBox::currentTextChanged, [=]() { Q_EMIT appearanceChanged(); }); + connect(ui->fontScaleSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); }); + connect(ui->fontWeightNormalSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); }); + connect(ui->fontWeightBoldSlider, &QSlider::sliderReleased, [=]() { Q_EMIT appearanceChanged(); }); } AppearanceWidget::~AppearanceWidget() diff --git a/src/qt/appearancewidget.h b/src/qt/appearancewidget.h index 33e3752d38..a1d2d895df 100644 --- a/src/qt/appearancewidget.h +++ b/src/qt/appearancewidget.h @@ -29,6 +29,9 @@ public: void setModel(OptionsModel* model); +Q_SIGNALS: + void appearanceChanged(); + public Q_SLOTS: void accept(); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index fc5ccf9331..07d302259f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -466,6 +466,8 @@ void BitcoinGUI::createActions() for (auto button : tabGroup->buttons()) { GUIUtil::setFont({button}, GUIUtil::FontWeight::Normal, 16); } + GUIUtil::updateFonts(); + // Give the selected tab button a bolder font. connect(tabGroup, SIGNAL(buttonToggled(QAbstractButton *, bool)), this, SLOT(highlightTabButton(QAbstractButton *, bool))); #endif // ENABLE_WALLET @@ -914,6 +916,9 @@ void BitcoinGUI::optionsClicked() OptionsDialog dlg(this, enableWallet); dlg.setModel(clientModel->getOptionsModel()); + connect(&dlg, &OptionsDialog::appearanceChanged, [=]() { + updateWidth(); + }); dlg.exec(); updatePrivateSendVisibility(); @@ -1000,6 +1005,7 @@ void BitcoinGUI::openClicked() void BitcoinGUI::highlightTabButton(QAbstractButton *button, bool checked) { GUIUtil::setFont({button}, checked ? GUIUtil::FontWeight::Bold : GUIUtil::FontWeight::Normal, 16); + GUIUtil::updateFonts(); } void BitcoinGUI::gotoOverviewPage() @@ -1161,6 +1167,26 @@ void BitcoinGUI::updatePrivateSendVisibility() privateSendCoinsMenuAction->setVisible(fEnabled); showPrivateSendHelpAction->setVisible(fEnabled); updateToolBarShortcuts(); + updateWidth(); +} + +void BitcoinGUI::updateWidth() +{ + int nWidthWidestButton{0}; + int nButtonsVisible{0}; + for (QAbstractButton* button : tabGroup->buttons()) { + if (!button->isEnabled()) { + continue; + } + QFontMetrics fm(button->font()); + nWidthWidestButton = std::max(nWidthWidestButton, fm.width(button->text())); + ++nButtonsVisible; + } + // Add 30 per button as padding and use minimum 980 which is the minimum required to show all tab's contents + // Use nButtonsVisible + 1 <- for the dash logo + int nWidth = std::max(980, (nWidthWidestButton + 30) * (nButtonsVisible + 1)); + setMinimumWidth(nWidth); + resize(nWidth, height()); } void BitcoinGUI::updateToolBarShortcuts() @@ -1478,6 +1504,10 @@ void BitcoinGUI::showEvent(QShowEvent *event) openRepairAction->setEnabled(true); aboutAction->setEnabled(true); optionsAction->setEnabled(true); + + if (!event->spontaneous()) { + updateWidth(); + } } #ifdef ENABLE_WALLET diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 83cd5ab10f..dea8769f1c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -322,6 +322,8 @@ private Q_SLOTS: void showModalOverlay(); void updatePrivateSendVisibility(); + + void updateWidth(); }; class UnitDisplayStatusBarControl : public QLabel diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index d44f2d2717..3e8b71574b 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -139,12 +139,8 @@ static QFont::Weight fontWeightNormal = defaultFontWeightNormal; // Application font weight for bold text. May be overwritten by -font-weight-bold. static QFont::Weight fontWeightBold = defaultFontWeightBold; -// Contains all widgets and its font attributes (weight, italic) with font changes due to GUIUtil::setFont -static std::map> mapNormalFontUpdates; -// Contains all widgets where a fixed pitch font has been set with GUIUtil::setFixedPitchFont -static std::set setFixedPitchFontUpdates; -// Contains all widgets where a non-default fontsize has been seet with GUIUtil::setFont -static std::map mapFontSizeUpdates; +// Contains all widgets and its font attributes (weight, italic, size) with font changes due to GUIUtil::setFont +static std::map> mapNormalFontUpdates; // Contains a list of supported font weights for all members of GUIUtil::FontFamily static std::map> mapSupportedWeights; @@ -269,25 +265,6 @@ QString dateTimeStr(qint64 nTime) return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); } -QFont fixedPitchFont() -{ - if (dashThemeActive()) { - return getFontNormal(); - } else { -#if QT_VERSION >= 0x50200 - return QFontDatabase::systemFont(QFontDatabase::FixedFont); -#else - QFont font("Monospace"); -#if QT_VERSION >= 0x040800 - font.setStyleHint(QFont::Monospace); -#else - font.setStyleHint(QFont::TypeWriter); -#endif - return font; -#endif - } -} - // Just some dummy data to generate an convincing random-looking (but consistent) address static const uint8_t dummydata[] = {0xeb,0x15,0x23,0x1d,0xfc,0xeb,0x60,0x92,0x58,0x86,0xb6,0x7d,0x06,0x52,0x99,0x92,0x59,0x15,0xae,0xb1,0x72,0xc0,0x66,0x47}; @@ -310,7 +287,6 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllow { parent->setFocusProxy(widget); - setFixedPitchFont({widget}); #if QT_VERSION >= 0x040700 // We don't want translators to use own addresses in translations // and this is the only place, where this address is supplied. @@ -1426,7 +1402,7 @@ void setFontScale(int nScale) double getScaledFontSize(int nSize) { - return (nSize * (1 + (fontScale * fontScaleSteps))); + return std::round(nSize * (1 + (fontScale * fontScaleSteps)) * 4) / 4.0; } bool loadFonts() @@ -1574,27 +1550,12 @@ void setApplicationFont() void setFont(const std::vector& vecWidgets, FontWeight weight, int nPointSize, bool fItalic) { - QFont font = getFont(weight, fItalic, nPointSize); - for (auto it : vecWidgets) { - auto fontAttributes = std::make_pair(weight, fItalic); - auto itw = mapNormalFontUpdates.emplace(std::make_pair(it, fontAttributes)); - if (!itw.second) itw.first->second = fontAttributes; - - if (nPointSize != -1) { - auto its = mapFontSizeUpdates.emplace(std::make_pair(it, nPointSize)); - if (!its.second) its.first->second = nPointSize; + auto fontAttributes = std::make_tuple(weight, fItalic, nPointSize); + auto itFontUpdate = mapNormalFontUpdates.emplace(std::make_pair(it, fontAttributes)); + if (!itFontUpdate.second) { + itFontUpdate.first->second = fontAttributes; } - - it->setFont(font); - } -} - -void setFixedPitchFont(const std::vector& vecWidgets) -{ - for (auto it : vecWidgets) { - setFixedPitchFontUpdates.emplace(it); - it->setFont(fixedPitchFont()); } } @@ -1605,75 +1566,100 @@ void updateFonts() return; } - setApplicationFont(); - - auto getKey = [](QWidget* w) -> QString { - return w->parent() ? w->parent()->objectName() + w->objectName() : w->objectName(); - }; - - static std::map mapDefaultFontSizes; - std::map mapWidgetFonts; + static std::map mapWidgetDefaultFontSizes; + static std::map mapClassDefaultFontSizes; + std::map> mapWidgetFonts; for (QWidget* w : qApp->allWidgets()) { + std::vector vecIgnore{ + "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()) { + continue; + } QFont font = w->font(); font.setFamily(qApp->font().family()); font.setWeight(getFontWeightNormal()); font.setStyleName(qApp->font().styleName()); font.setStyle(qApp->font().style()); // Set the font size based on the widgets default font size + the font scale - QString key = getKey(w); - if (!mapDefaultFontSizes.count(key)) { - mapDefaultFontSizes.emplace(std::make_pair(key, font.pointSize() > 0 ? font.pointSize() : defaultFontSize)); + bool fAdded = false; + if (!mapWidgetDefaultFontSizes.count(w)) { + mapWidgetDefaultFontSizes.emplace(std::make_pair(w, font.pointSize() > 0 ? font.pointSize() : defaultFontSize)); + fAdded = true; } - font.setPointSizeF(getScaledFontSize(mapDefaultFontSizes[key])); - mapWidgetFonts.emplace(w, font); + font.setPointSizeF(getScaledFontSize(mapWidgetDefaultFontSizes[w])); + bool fUpdateRequired = fAdded || (mapNormalFontUpdates.find(w) == mapNormalFontUpdates.end() && font != w->font()); + mapWidgetFonts.emplace(w, std::make_pair(font, fUpdateRequired)); } auto itn = mapNormalFontUpdates.begin(); while (itn != mapNormalFontUpdates.end()) { - if (mapWidgetFonts.count(itn->first)) { - mapWidgetFonts[itn->first] = getFont(itn->second.first, itn->second.second, mapDefaultFontSizes[getKey(itn->first)]); + auto itw = mapWidgetFonts.find(itn->first); + if (itw != mapWidgetFonts.end()) { + int nSize = std::get<2>(itn->second); + if (nSize == -1) { + nSize = mapWidgetDefaultFontSizes[itn->first]; + } + QFont&& font = getFont(std::get<0>(itn->second), std::get<1>(itn->second), nSize); + if (itn->first->font() != font) { + itw->second.first = font; + itw->second.second = true; + } ++itn; } else { itn = mapNormalFontUpdates.erase(itn); } } - auto its = mapFontSizeUpdates.begin(); - while (its != mapFontSizeUpdates.end()) { - if (mapWidgetFonts.count(its->first)) { - QFont font = mapWidgetFonts[its->first]; - font.setPointSizeF(getScaledFontSize(its->second)); - mapWidgetFonts[its->first] = font; - ++its; - } else { - its = mapFontSizeUpdates.erase(its); - } - } - auto itf = setFixedPitchFontUpdates.begin(); - while (itf != setFixedPitchFontUpdates.end()) { - if (mapWidgetFonts.count(*itf)) { - QFont font = fixedPitchFont(); - font.setPointSizeF(getScaledFontSize(mapDefaultFontSizes[getKey(*itf)])); - mapWidgetFonts[*itf] = font; - ++itf; - } else { - itf = setFixedPitchFontUpdates.erase(itf); - } - } for (auto it : mapWidgetFonts) { - it.first->setFont(it.second); + if (it.second.second) { + it.first->setFont(it.second.first); + } } - // Get the global font for QToolTip labels - QFont fontToolTip = qApp->font("QTipLabel"); - // Store the default QToolTip font size before ever applying any scale to it - if (!mapDefaultFontSizes.count("QTipLabel")) { - mapDefaultFontSizes.emplace("QTipLabel", fontToolTip.pointSize()); + // Cleanup mapDefaultFontSize to remove deleted widgets + auto itd = mapWidgetDefaultFontSizes.begin(); + while (itd != mapWidgetDefaultFontSizes.end()) { + if (qApp->allWidgets().contains(itd->first)) { + ++itd; + } else { + itd = mapWidgetDefaultFontSizes.erase(itd); + } + } + + // Scale the global font for QToolTip labels, QMenu and QMessageBox instances + QFont fontToolTip = qApp->font("QTipLabel"); + QFont fontMenu = qApp->font("QMenu"); + QFont fontMessageBox = qApp->font("QMessageBox"); + // Store their default font sizes before ever applying any scale to it + if (!mapClassDefaultFontSizes.count("QTipLabel")) { + mapClassDefaultFontSizes.emplace("QTipLabel", fontToolTip.pointSize()); + } + if (!mapClassDefaultFontSizes.count("QMenu")) { + mapClassDefaultFontSizes.emplace("QMenu", fontMenu.pointSize()); + } + if (!mapClassDefaultFontSizes.count("QMessageBox")) { + mapClassDefaultFontSizes.emplace("QMessageBox", fontMessageBox.pointSize()); + } + // And give them the proper scaled size based on their default sizes if required + double dSize = getScaledFontSize(mapClassDefaultFontSizes["QTipLabel"]); + if (fontToolTip.pointSizeF() != dSize) { + fontToolTip.setPointSizeF(dSize); + qApp->setFont(fontToolTip, "QTipLabel"); + } + dSize = getScaledFontSize(mapClassDefaultFontSizes["QMenu"]); + if (fontMenu.pointSizeF() != dSize) { + fontMenu.setPointSizeF(dSize); + qApp->setFont(fontMenu, "QMenu"); + } + dSize = getScaledFontSize(getScaledFontSize(mapClassDefaultFontSizes["QMessageBox"])); + if (fontMessageBox.pointSizeF() != dSize) { + fontMessageBox.setPointSizeF(dSize); + qApp->setFont(fontMessageBox, "QMessageBox"); } - // And give it the proper scaled size based on its default size - fontToolTip.setPointSizeF(getScaledFontSize(mapDefaultFontSizes["QTipLabel"])); - qApp->setFont(fontToolTip, "QTipLabel"); } QFont getFont(FontFamily family, QFont::Weight qWeight, bool fItalic, int nPointSize) diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index d73b15d7c4..1f5bc5af98 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -101,9 +101,6 @@ namespace GUIUtil QString dateTimeStr(const QDateTime &datetime); QString dateTimeStr(qint64 nTime); - // Return a monospace font - QFont fixedPitchFont(); - // Set up widgets for address and amounts void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllowURI = false); void setupAmountWidget(QLineEdit *widget, QWidget *parent); @@ -331,9 +328,6 @@ namespace GUIUtil theme changes. */ void setFont(const std::vector& vecWidgets, FontWeight weight, int nPointSize = -1, bool fItalic = false); - /** Workaround to set a fixed pitch font in traditional theme while keeping track of font updates */ - void setFixedPitchFont(const std::vector& vecWidgets); - /** Update the font of all widgets where a custom font has been set with GUIUtil::setFont */ void updateFonts(); diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index c1aded3c97..00bf4d258b 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -96,6 +96,8 @@ MasternodeList::MasternodeList(QWidget* parent) : timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateDIP3ListScheduled())); timer->start(1000); + + GUIUtil::updateFonts(); } MasternodeList::~MasternodeList() diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index b09afbe2f6..21056124ec 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -41,6 +41,8 @@ foreverHidden(false) blockProcessTime.clear(); setVisible(false); + + GUIUtil::updateFonts(); } ModalOverlay::~ModalOverlay() diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index bb323b79e2..5b189eda12 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : @@ -165,6 +166,11 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : appearanceLayout->addWidget(appearance); ui->widgetAppearance->setLayout(appearanceLayout); + connect(appearance, &AppearanceWidget::appearanceChanged, [=](){ + updateWidth(); + Q_EMIT appearanceChanged(); + }); + updatePrivateSendVisibility(); // Store the current PrivateSend enabled state to recover it if it gets changed but the dialog gets not accepted but declined. @@ -245,6 +251,7 @@ void OptionsDialog::setModel(OptionsModel *_model) if (_model != nullptr) { _model->emitPrivateSendEnabledChanged(); } + updateWidth(); }); } @@ -307,6 +314,7 @@ void OptionsDialog::showPage(int index) GUIUtil::setFont({btnActive}, GUIUtil::FontWeight::Bold, 16); GUIUtil::setFont(vecNormal, GUIUtil::FontWeight::Normal, 16); + GUIUtil::updateFonts(); ui->stackedWidgetOptions->setCurrentIndex(index); btnActive->setChecked(true); @@ -441,6 +449,32 @@ void OptionsDialog::updatePrivateSendVisibility() ui->btnPrivateSend->setVisible(fEnabled); } +void OptionsDialog::updateWidth() +{ + int nWidthWidestButton{0}; + int nButtonsVisible{0}; + for (QAbstractButton* button : pageButtons.buttons()) { + if (!button->isVisible()) { + continue; + } + QFontMetrics fm(button->font()); + nWidthWidestButton = std::max(nWidthWidestButton, fm.width(button->text())); + ++nButtonsVisible; + } + // Add 10 per button as padding and use minimum 585 which is what we used in css before + int nWidth = std::max(585, (nWidthWidestButton + 10) * nButtonsVisible); + setMinimumWidth(nWidth); + resize(nWidth, height()); +} + +void OptionsDialog::showEvent(QShowEvent* event) +{ + if (!event->spontaneous()) { + updateWidth(); + } + QDialog::showEvent(event); +} + ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : QValidator(parent) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 13a13fc972..57e1566ee5 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -64,7 +64,10 @@ private Q_SLOTS: void updatePrivateSendVisibility(); + void updateWidth(); + Q_SIGNALS: + void appearanceChanged(); void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); private: @@ -75,6 +78,8 @@ private: QString previousTheme; AppearanceWidget* appearance; bool fPrivateSendEnabledPrev{false}; + + void showEvent(QShowEvent* event) override; }; #endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 5475b43746..16a5ef0c70 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -62,7 +62,7 @@ public: // Draw first line (with slightly bigger font than the second line will get) // Content: Date/Time, Optional IS indicator, Amount QFont font = fontInitial; - font.setPointSize(font.pointSize() * 1.17); + font.setPointSizeF(GUIUtil::getScaledFontSize(font.pointSizeF() * 1.17)); painter->setFont(font); // Date/Time colorForeground = qvariant_cast(indexDate.data(Qt::ForegroundRole)); @@ -83,6 +83,7 @@ public: // Draw second line (with the initial font) // Content: Address/label, Optional Watchonly indicator + fontInitial.setPointSizeF(GUIUtil::getScaledFontSize(fontInitial.pointSizeF())); painter->setFont(fontInitial); // Address/Label colorForeground = qvariant_cast(indexAddress.data(Qt::ForegroundRole)); @@ -144,6 +145,8 @@ OverviewPage::OverviewPage(QWidget* parent) : ui->labelSpendable }, GUIUtil::FontWeight::Bold); + GUIUtil::updateFonts(); + // Recent transactions ui->listTransactions->setItemDelegate(txdelegate); // Note: minimum height of listTransactions will be set later in updateAdvancedPSUI() to reflect actual settings diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 51e51cf7ea..75030ff00c 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -31,6 +31,7 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(QWidget* parent) : GUIUtil::setFont({ui->label, ui->label_2, ui->label_3}, GUIUtil::FontWeight::Normal, 15); + GUIUtil::updateFonts(); #if QT_VERSION >= 0x040700 ui->reqLabel->setPlaceholderText(tr("Enter a label to associate with the new receiving address")); diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index 4fadb607ee..8813126611 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -194,7 +194,7 @@ void ReceiveRequestDialog::update() painter.fillRect(paddedRect, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_WIDGET)); painter.drawImage(2, 2, qrImage.scaled(QR_IMAGE_SIZE - 4, QR_IMAGE_SIZE - 4)); // calculate ideal font size - QFont font = GUIUtil::fixedPitchFont(); + QFont font = GUIUtil::getFontNormal(); qreal font_size = GUIUtil::calculateIdealFontSize((paddedRect.width() - 20), info.address, font); font.setPointSizeF(font_size); // paint the address diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index a2a6484564..8adb3ae796 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1259,7 +1259,6 @@ OptionsDialog ******************************************************/ QDialog#OptionsDialog { - min-width: 585px; } QDialog#OptionsDialog QValueComboBox, diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 769ca7da98..72e988b48e 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -462,6 +462,8 @@ RPCConsole::RPCConsole(QWidget* parent) : ui->banHeading }, GUIUtil::FontWeight::Bold, 16); + GUIUtil::updateFonts(); + GUIUtil::disableMacFocusRect(this); QSettings settings; @@ -833,7 +835,7 @@ void RPCConsole::clear(bool clearHistory) ui->lineEdit->setFocus(); // Set default style sheet - QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont()); + QFontInfo fixedFontInfo(GUIUtil::getFontNormal()); ui->messagesWidget->document()->setDefaultStyleSheet( QString( "table { }" @@ -841,7 +843,7 @@ void RPCConsole::clear(bool clearHistory) "td.message { " + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_PRIMARY) + " font-family: %1; font-size: %2; 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 * 0.1) + ).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize)) ); #ifdef Q_OS_MAC @@ -957,6 +959,7 @@ void RPCConsole::showPage(int index) GUIUtil::setFont({btnActive}, GUIUtil::FontWeight::Bold, 16); GUIUtil::setFont(vecNormal, GUIUtil::FontWeight::Normal, 16); + GUIUtil::updateFonts(); ui->stackedWidgetRPC->setCurrentIndex(index); btnActive->setChecked(true); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 12484c536b..9219461f97 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -86,6 +86,8 @@ SendCoinsDialog::SendCoinsDialog(bool _fPrivateSend, QWidget* parent) : addEntry(); + GUIUtil::updateFonts(); + connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 5cc3c5d731..2ebc0c8bf3 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -33,8 +33,6 @@ SendCoinsEntry::SendCoinsEntry(QWidget* parent) : // normal dash address field GUIUtil::setupAddressWidget(ui->payTo, this, true); - // just a label for displaying dash address(es) - ui->payTo_is->setFont(GUIUtil::fixedPitchFont()); GUIUtil::setFont({ui->payToLabel, ui->labellLabel, diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp index d964525e87..237b8a1d7e 100644 --- a/src/qt/signverifymessagedialog.cpp +++ b/src/qt/signverifymessagedialog.cpp @@ -52,9 +52,7 @@ SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget* parent) : ui->messageIn_VM->installEventFilter(this); ui->signatureIn_VM->installEventFilter(this); - GUIUtil::setFixedPitchFont({ui->signatureOut_SM, ui->signatureIn_VM}); - - GUIUtil::setFont({ui->signatureOut_SM}, GUIUtil::FontWeight::Normal, 11, true); + GUIUtil::setFont({ui->signatureOut_SM, ui->signatureIn_VM}, GUIUtil::FontWeight::Normal, 11, true); GUIUtil::setFont({ui->signatureLabel_SM}, GUIUtil::FontWeight::Bold, 16); GUIUtil::setFont({ui->statusLabel_SM, ui->statusLabel_VM}, GUIUtil::FontWeight::Bold); @@ -111,6 +109,7 @@ void SignVerifyMessageDialog::showPage(int index) GUIUtil::setFont({btnActive}, GUIUtil::FontWeight::Bold, 16); GUIUtil::setFont(vecNormal, GUIUtil::FontWeight::Normal, 16); + GUIUtil::updateFonts(); ui->stackedWidgetSig->setCurrentIndex(index); btnActive->setChecked(true); diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 3e72189382..48b2e0023d 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -159,16 +159,24 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) } // Draw statistic rect on top of everything else - const int nScale = GUIUtil::getFontScale() / 2; - const int nMarginStats = 20; const int nPadding = 5; - const int nWidthStats = 160 + nScale * 3 - 2 * nPadding; - const int nHeightStats = 110 + nScale - 2 * nPadding; - const int nSizeMark = nWidthStats * 0.15; - const int nWidthText = nWidthStats * 0.45; - const int nWidthBytes = nWidthStats * 0.4; - const int nHeightTotals = nHeightStats * 0.3; - const int nHeightInOut = nHeightStats * 0.35; + const int nMarginStats = 20; + const QString strTotal = tr("Total"); + const QString strReceived = tr("Received"); + const QString strSent = tr("Sent"); + // Get a bold font for the title and a normal one for the rest + QFont fontTotal = GUIUtil::getFont(GUIUtil::FontWeight::Bold, false, 16); + QFont fontInOut = GUIUtil::getFont(GUIUtil::FontWeight::Normal, false, 12); + // Use font metrics to determine minimum rect sizes depending on the font scale + QFontMetrics fmTotal(fontTotal); + QFontMetrics fmInOut(fontInOut); + const int nSizeMark = fmInOut.height() + 2 * nPadding; + const int nWidthText = fmInOut.width(strReceived) + 2 * nPadding; + const int nWidthBytes = fmInOut.width("1000 GB") + 2 * nPadding; + const int nHeightTotals = fmTotal.height() + 2 * nPadding; + const int nHeightInOut = fmInOut.height() + 2 * nPadding; + const int nWidthStats = nSizeMark + nWidthText + nWidthBytes + 2 * nPadding; + const int nHeightStats = nHeightTotals + 2 * nHeightInOut + 2 * nPadding; auto addPadding = [&](QRect& rect, int nPadding) { rect.adjust(nPadding, nPadding, -nPadding, -nPadding); }; @@ -177,26 +185,23 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) QRect rectContent = rectOuter; QRect rectContentPadded = rectContent; addPadding(rectContentPadded, nPadding); - QRect rectTotals(rectContentPadded.topLeft(), QSize(nWidthStats, nHeightTotals)); - QRect rectIn(rectTotals.bottomLeft(), QSize(nWidthStats, nHeightInOut)); - QRect rectOut(rectIn.bottomLeft(), QSize(nWidthStats, nHeightInOut)); + QRect rectTotals(rectContentPadded.topLeft(), QSize(rectContentPadded.width(), nHeightTotals)); + QRect rectIn(rectTotals.bottomLeft(), QSize(rectContentPadded.width(), nHeightInOut)); + QRect rectOut(rectIn.bottomLeft(), QSize(rectContentPadded.width(), nHeightInOut)); // Create subrects for received QRect rectInMark(rectIn.topLeft(), QSize(nSizeMark, nSizeMark)); QRect rectInText(rectInMark.topRight(), QSize(nWidthText, nHeightInOut)); - QRect rectInBytes(rectInText.topRight(), QSize(nWidthBytes - nPadding, nHeightInOut)); + QRect rectInBytes(rectInText.topRight(), QSize(nWidthBytes, nHeightInOut)); // Create subrects for sent QRect rectOutMark(rectOut.topLeft(), QSize(nSizeMark, nSizeMark)); QRect rectOutText(rectOutMark.topRight(), QSize(nWidthText, nHeightInOut)); - QRect rectOutBytes(rectOutText.topRight(), QSize(nWidthBytes - nPadding, nHeightInOut)); - // Get a bold font for the title and a normal one for the rest - QFont fontTotal = GUIUtil::getFont(GUIUtil::FontWeight::Bold, false, 16); - QFont fontInOut = GUIUtil::getFont(GUIUtil::FontWeight::Normal, false, 12); + QRect rectOutBytes(rectOutText.topRight(), QSize(nWidthBytes, nHeightInOut)); // Add padding where required addPadding(rectTotals, nPadding); - addPadding(rectInMark, nPadding); + addPadding(rectInMark, 1.6 * nPadding); addPadding(rectInText, nPadding); addPadding(rectInBytes, nPadding); - addPadding(rectOutMark, nPadding); + addPadding(rectOutMark, 1.6 * nPadding); addPadding(rectOutText, nPadding); addPadding(rectOutBytes, nPadding); // Finally draw it all @@ -205,11 +210,11 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) painter.fillRect(rectContent, GUIUtil::getThemedQColor(GUIUtil::ThemedColor::BACKGROUND_NETSTATS)); painter.setPen(axisCol); painter.setFont(fontTotal); - painter.drawText(rectTotals, Qt::AlignLeft, tr("Totals")); + painter.drawText(rectTotals, Qt::AlignLeft, strTotal); painter.setFont(fontInOut); - painter.drawText(rectInText, Qt::AlignLeft, tr("Received")); + painter.drawText(rectInText, Qt::AlignLeft, strReceived); painter.drawText(rectInBytes, Qt::AlignRight, GUIUtil::formatBytes(trafficGraphData.getLastBytesIn())); - painter.drawText(rectOutText, Qt::AlignLeft, tr("Sent")); + painter.drawText(rectOutText, Qt::AlignLeft, strSent); painter.drawText(rectOutBytes, Qt::AlignRight, GUIUtil::formatBytes(trafficGraphData.getLastBytesOut())); painter.setPen(green); painter.setBrush(green); diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 61014cc318..1605034d2d 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -217,6 +217,8 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "

" + tr("Do not shut down the computer until this window disappears."))); setLayout(layout); + + GUIUtil::updateFonts(); } QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index c0ad8e424a..2bb1a177ad 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -62,6 +62,7 @@ WalletView::WalletView(QWidget* parent) : GUIUtil::setFont({transactionSumLabel, transactionSum, }, GUIUtil::FontWeight::Bold, 14); + GUIUtil::updateFonts(); hbox_buttons->addWidget(transactionSum);