Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d1f1c80
qt: Make sure font size in MasternodeList gets scaled as expected
xdustinface Sep 24, 2020
1aa660c
qt: Make sure font size in ShutdownWindow gets scaled as expected
xdustinface Sep 24, 2020
7440622
qt: Drop obsolete application font updates
xdustinface Sep 25, 2020
33b7861
qt: Scale QMenu and QMessageBox globally
xdustinface Sep 25, 2020
5d49661
qt: Avoid redundant scaling for tooltips and menus
xdustinface Sep 25, 2020
3ab9f20
qt: Only update widget's font if required
xdustinface Sep 25, 2020
2cb0a9a
qt: Merge GUIUtil::mapFontSizeUpdates into GUIUtil::mapNormalFontUpdates
xdustinface Sep 25, 2020
e689b6f
qt: Remove obsolete setFixedPitchFont call
xdustinface Sep 25, 2020
35223e6
qt: Use setFixedPitchFont in SendCoinsEntry
xdustinface Sep 25, 2020
67b0f3b
qt: Scale font size in increments of 0.25
xdustinface Sep 25, 2020
b4ecfdc
qt: Properly scale network traffic stats depending on font metrics
xdustinface Sep 25, 2020
d351fca
qt: Update min/max width of OptionsDialog depending on buttons width
xdustinface Sep 25, 2020
a8faee8
qt: Emit a signal whenever any attribute of AppearanceWidget changed
xdustinface Sep 26, 2020
42aab45
qt: Update OptionsDialog width if the appearance changed
xdustinface Sep 26, 2020
838ac3b
qt: Calculate the initial wide right after the window showed up
xdustinface Sep 26, 2020
957be48
qt: Call parent class showEvent + override it explicit
xdustinface Sep 26, 2020
3a8d9a4
qt: Let OptionsDialog emit a signal if appearance gets changed
xdustinface Sep 26, 2020
c0447b0
qt: Resize main toolbar depending on visible buttons / font attributes
xdustinface Sep 26, 2020
851e993
qt: Reset max width after it has been set to still allow window resizing
xdustinface Sep 26, 2020
43511ec
qt: Properly update the weight of widgets with default font attributes
xdustinface Sep 27, 2020
78af796
qt: Handle updates to the font attributes
xdustinface Sep 27, 2020
c2395c7
qt: Use resize() instead of setMaximumWidth()
xdustinface Sep 28, 2020
4caa74a
qt: Call GUIUtil::updateFonts in ModalOverlay constructor
xdustinface Sep 28, 2020
d82c5d7
qt: Make sure default fonts are stored properly for the related widget
xdustinface Sep 28, 2020
cb23aae
qt: Ignore some low level classes in GUIUtil::updateFont
xdustinface Sep 28, 2020
a964fe6
rpc: Remove obsolete `.arg()` call
xdustinface Sep 28, 2020
5d2854c
qt: Drop fixedPitchFont
xdustinface Sep 28, 2020
ab6154c
qt: Avoid redundant font updates. Let GUIUtil::updateFont handle them
xdustinface Sep 28, 2020
ab0ae5a
qt: Scale recent transactions on OverviewPage
xdustinface Sep 28, 2020
e364cce
qt: Ignore QListView in GUIUtil::updateFonts
xdustinface Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
QFont font;
if(index.column() == Address)
{
font = GUIUtil::fixedPitchFont();
font = GUIUtil::getFontNormal();
}
return font;
}
Expand Down
6 changes: 6 additions & 0 deletions src/qt/appearancewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/qt/appearancewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class AppearanceWidget : public QWidget

void setModel(OptionsModel* model);

Q_SIGNALS:
void appearanceChanged();

public Q_SLOTS:
void accept();

Expand Down
30 changes: 30 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,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
Expand Down Expand Up @@ -924,6 +926,9 @@ void BitcoinGUI::optionsClicked()

OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
connect(&dlg, &OptionsDialog::appearanceChanged, [=]() {
updateWidth();
});
dlg.exec();

updatePrivateSendVisibility();
Expand Down Expand Up @@ -1010,6 +1015,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()
Expand Down Expand Up @@ -1171,6 +1177,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<int>(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<int>(980, (nWidthWidestButton + 30) * (nButtonsVisible + 1));
setMinimumWidth(nWidth);
resize(nWidth, height());
}

void BitcoinGUI::updateToolBarShortcuts()
Expand Down Expand Up @@ -1490,6 +1516,10 @@ void BitcoinGUI::showEvent(QShowEvent *event)
openRepairAction->setEnabled(true);
aboutAction->setEnabled(true);
optionsAction->setEnabled(true);

if (!event->spontaneous()) {
updateWidth();
}
}

#ifdef ENABLE_WALLET
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ private Q_SLOTS:
void showModalOverlay();

void updatePrivateSendVisibility();

void updateWidth();
};

class UnitDisplayStatusBarControl : public QLabel
Expand Down
154 changes: 75 additions & 79 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,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<QWidget*, std::pair<FontWeight, bool>> mapNormalFontUpdates;
// Contains all widgets where a fixed pitch font has been set with GUIUtil::setFixedPitchFont
static std::set<QWidget*> setFixedPitchFontUpdates;
// Contains all widgets where a non-default fontsize has been seet with GUIUtil::setFont
static std::map<QWidget*, int> mapFontSizeUpdates;
// Contains all widgets and its font attributes (weight, italic, size) with font changes due to GUIUtil::setFont
static std::map<QWidget*, std::tuple<FontWeight, bool, int>> mapNormalFontUpdates;
// Contains a list of supported font weights for all members of GUIUtil::FontFamily
static std::map<FontFamily, std::vector<QFont::Weight>> mapSupportedWeights;

Expand Down Expand Up @@ -262,15 +258,6 @@ QString dateTimeStr(qint64 nTime)
return dateTimeStr(QDateTime::fromTime_t((qint32)nTime));
}

QFont fixedPitchFont()
{
if (dashThemeActive()) {
return getFontNormal();
} else {
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
}
}

// Just some dummy data to generate a 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};

Expand All @@ -293,7 +280,6 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllow
{
parent->setFocusProxy(widget);

setFixedPitchFont({widget});
// We don't want translators to use own addresses in translations
// and this is the only place, where this address is supplied.
widget->setPlaceholderText(QObject::tr("Enter a Dash address (e.g. %1)").arg(
Expand Down Expand Up @@ -1387,7 +1373,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()
Expand Down Expand Up @@ -1535,27 +1521,12 @@ void setApplicationFont()

void setFont(const std::vector<QWidget*>& 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<QWidget*>& vecWidgets)
{
for (auto it : vecWidgets) {
setFixedPitchFontUpdates.emplace(it);
it->setFont(fixedPitchFont());
}
}

Expand All @@ -1566,75 +1537,100 @@ void updateFonts()
return;
}

setApplicationFont();

auto getKey = [](QWidget* w) -> QString {
return w->parent() ? w->parent()->objectName() + w->objectName() : w->objectName();
};

static std::map<QString, int> mapDefaultFontSizes;
std::map<QWidget*, QFont> mapWidgetFonts;
static std::map<QWidget*, int> mapWidgetDefaultFontSizes;
static std::map<QString, int> mapClassDefaultFontSizes;
std::map<QWidget*, std::pair<QFont, bool>> mapWidgetFonts;

for (QWidget* w : qApp->allWidgets()) {
std::vector<QString> 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);

for (auto it : mapWidgetFonts) {
if (it.second.second) {
it.first->setFont(it.second.first);
}
}
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;

// Cleanup mapDefaultFontSize to remove deleted widgets
auto itd = mapWidgetDefaultFontSizes.begin();
while (itd != mapWidgetDefaultFontSizes.end()) {
if (qApp->allWidgets().contains(itd->first)) {
++itd;
} else {
itf = setFixedPitchFontUpdates.erase(itf);
itd = mapWidgetDefaultFontSizes.erase(itd);
}
}

for (auto it : mapWidgetFonts) {
it.first->setFont(it.second);
}

// Get the global font for QToolTip labels
// Scale the global font for QToolTip labels, QMenu and QMessageBox instances
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());
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)
Expand Down
6 changes: 0 additions & 6 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,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);
Expand Down Expand Up @@ -332,9 +329,6 @@ namespace GUIUtil
theme changes. */
void setFont(const std::vector<QWidget*>& 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<QWidget*>& vecWidgets);

/** Update the font of all widgets where a custom font has been set with
GUIUtil::setFont */
void updateFonts();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ MasternodeList::MasternodeList(QWidget* parent) :
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateDIP3ListScheduled()));
timer->start(1000);

GUIUtil::updateFonts();
}

MasternodeList::~MasternodeList()
Expand Down
2 changes: 2 additions & 0 deletions src/qt/modaloverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ foreverHidden(false)

blockProcessTime.clear();
setVisible(false);

GUIUtil::updateFonts();
}

ModalOverlay::~ModalOverlay()
Expand Down
Loading