Skip to content

Commit

Permalink
gui: Add monospaced font settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Feb 21, 2021
1 parent 22e0114 commit 67f2631
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 1 deletion.
100 changes: 100 additions & 0 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,106 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="font_groupBox">
<property name="title">
<string>Monospaced font in the Overview tab:</string>
</property>
<layout class="QVBoxLayout" name="font_verticalLayout">
<item>
<layout class="QHBoxLayout" name="embeddedFont_horizontalLayout">
<item>
<widget class="QRadioButton" name="embeddedFont_radioButton">
<property name="text">
<string>embedded &quot;%1&quot;</string>
</property>
</widget>
</item>
<item>
<spacer name="embeddedFont_horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="embeddedFont_verticalLayout">
<item>
<widget class="QLabel" name="embeddedFont_label_1">
<property name="text">
<string>111.11111111 BTC</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="embeddedFont_label_9">
<property name="text">
<string>909.09090909 BTC</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="font_line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="systemFont_horizontalLayout">
<item>
<widget class="QRadioButton" name="systemFont_radioButton">
<property name="text">
<string>closest matching &quot;%1&quot;</string>
</property>
</widget>
</item>
<item>
<spacer name="systemFont_horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="systemFont_verticalLayout">
<item>
<widget class="QLabel" name="systemFont_label_1">
<property name="text">
<string>111.11111111 BTC</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="systemFont_label_9">
<property name="text">
<string>909.09090909 BTC</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_Display">
<property name="orientation">
Expand Down
15 changes: 15 additions & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
ui->minimizeToTray->setEnabled(false);
}

QFont embedded_font{GUIUtil::fixedPitchFont(true)};
ui->embeddedFont_radioButton->setText(ui->embeddedFont_radioButton->text().arg(QFontInfo(embedded_font).family()));
embedded_font.setWeight(QFont::Bold);
ui->embeddedFont_label_1->setFont(embedded_font);
ui->embeddedFont_label_9->setFont(embedded_font);

QFont system_font{GUIUtil::fixedPitchFont(false)};
ui->systemFont_radioButton->setText(ui->systemFont_radioButton->text().arg(QFontInfo(system_font).family()));
system_font.setWeight(QFont::Bold);
ui->systemFont_label_1->setFont(system_font);
ui->systemFont_label_9->setFont(system_font);
// Checking the embeddedFont_radioButton automatically unchecks the systemFont_radioButton.
ui->systemFont_radioButton->setChecked(true);

GUIUtil::handleCloseWindowShortcut(this);
}

Expand Down Expand Up @@ -246,6 +260,7 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->lang, OptionsModel::Language);
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
}

void OptionsDialog::setOkButtonState(bool fState)
Expand Down
13 changes: 13 additions & 0 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ void OptionsModel::Init(bool resetSettings)
addOverriddenOption("-lang");

language = settings.value("language").toString();

if (!settings.contains("UseEmbeddedMonospacedFont")) {
settings.setValue("UseEmbeddedMonospacedFont", "true");
}
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
}

/** Helper function to copy contents from one QSettings to another.
Expand Down Expand Up @@ -326,6 +332,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return strThirdPartyTxUrls;
case Language:
return settings.value("language");
case UseEmbeddedMonospacedFont:
return m_use_embedded_monospaced_font;
case CoinControlFeatures:
return fCoinControlFeatures;
case Prune:
Expand Down Expand Up @@ -453,6 +461,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
setRestartRequired(true);
}
break;
case UseEmbeddedMonospacedFont:
m_use_embedded_monospaced_font = value.toBool();
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
break;
case CoinControlFeatures:
fCoinControlFeatures = value.toBool();
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
Expand Down
4 changes: 4 additions & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class OptionsModel : public QAbstractListModel
DisplayUnit, // BitcoinUnits::Unit
ThirdPartyTxUrls, // QString
Language, // QString
UseEmbeddedMonospacedFont, // bool
CoinControlFeatures, // bool
ThreadsScriptVerif, // int
Prune, // bool
Expand All @@ -84,6 +85,7 @@ class OptionsModel : public QAbstractListModel
bool getMinimizeOnClose() const { return fMinimizeOnClose; }
int getDisplayUnit() const { return nDisplayUnit; }
QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }

Expand All @@ -107,6 +109,7 @@ class OptionsModel : public QAbstractListModel
QString language;
int nDisplayUnit;
QString strThirdPartyTxUrls;
bool m_use_embedded_monospaced_font;
bool fCoinControlFeatures;
/* settings that were overridden by command-line */
QString strOverriddenByCommandLine;
Expand All @@ -120,6 +123,7 @@ class OptionsModel : public QAbstractListModel
void displayUnitChanged(int unit);
void coinControlFeaturesChanged(bool);
void showTrayIconChanged(bool);
void useEmbeddedMonospacedFontChanged(bool);
};

#endif // BITCOIN_QT_OPTIONSMODEL_H
3 changes: 2 additions & 1 deletion src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ void OverviewPage::setClientModel(ClientModel *model)
connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts);
updateAlerts(model->getStatusBarWarnings());

setMonospacedFont(false);
connect(model->getOptionsModel(), &OptionsModel::useEmbeddedMonospacedFontChanged, this, &OverviewPage::setMonospacedFont);
setMonospacedFont(model->getOptionsModel()->getUseEmbeddedMonospacedFont());
}
}

Expand Down

0 comments on commit 67f2631

Please sign in to comment.