From 8b9916e3113466a3d8e1e79f5f7f7003e4f423c7 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 16 Jun 2020 00:21:02 +0200 Subject: [PATCH 01/14] qt: Add "Appearance Tab" to OptionsDialog and move "Theme" into it --- src/qt/forms/optionsdialog.ui | 42 ++++++++++++++++++++++------------ src/qt/optionsdialog.cpp | 17 ++++++++------ src/qt/optionsmodel.cpp | 1 + src/qt/res/css/dark.css | 4 ++++ src/qt/res/css/general.css | 5 ++++ src/qt/res/css/light.css | 4 ++++ src/qt/res/css/traditional.css | 4 ++++ 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index c507210394a8..8499257462e1 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -75,6 +75,16 @@ + + + + &Appearance + + + true + + + @@ -777,20 +787,6 @@ https://www.transifex.com/projects/p/dash/ - - - - - - User Interface Theme: - - - - - - - - @@ -875,6 +871,24 @@ https://www.transifex.com/projects/p/dash/ + + + + + + + + Theme: + + + + + + + + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index b40d73d0e2a8..641527b0e1ed 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -89,6 +89,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : pageButtons.addButton(ui->btnWindow, pageButtons.buttons().size()); #endif pageButtons.addButton(ui->btnDisplay, pageButtons.buttons().size()); + pageButtons.addButton(ui->btnAppearance, pageButtons.buttons().size()); connect(&pageButtons, SIGNAL(buttonClicked(int)), this, SLOT(showPage(int))); @@ -103,12 +104,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : ui->digits->addItem(digits, digits); } - /* Theme selector */ - for (const QString& entry : GUIUtil::listThemes()) { - ui->theme->addItem(entry, QVariant(entry)); - } - connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); - /* Language selector */ QDir translations(":translations"); @@ -135,6 +130,11 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : } ui->thirdPartyTxUrls->setPlaceholderText("https://example.com/tx/%s"); + /* Theme selector */ + for (const QString& entry : GUIUtil::listThemes()) { + ui->theme->addItem(entry, QVariant(entry)); + } + ui->unit->setModel(new BitcoinUnits(this)); /* Widget-to-option mapper */ @@ -194,6 +194,8 @@ void OptionsDialog::setModel(OptionsModel *_model) connect(ui->digits, SIGNAL(valueChanged()), this, SLOT(showRestartWarning())); connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning())); connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); + /* Appearance */ + connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); } void OptionsDialog::setMapper() @@ -235,11 +237,12 @@ void OptionsDialog::setMapper() /* Display */ mapper->addMapping(ui->digits, OptionsModel::Digits); - mapper->addMapping(ui->theme, OptionsModel::Theme); mapper->addMapping(ui->lang, OptionsModel::Language); mapper->addMapping(ui->unit, OptionsModel::DisplayUnit); mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); + /* Appearance */ + mapper->addMapping(ui->theme, OptionsModel::Theme); } void OptionsDialog::showPage(int index) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index efb95f56e80c..26223c972943 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -84,6 +84,7 @@ void OptionsModel::Init(bool resetSettings) settings.setValue("strThirdPartyTxUrls", ""); strThirdPartyTxUrls = settings.value("strThirdPartyTxUrls", "").toString(); + // Appearance if (!settings.contains("theme")) settings.setValue("theme", GUIUtil::getDefaultTheme()); diff --git a/src/qt/res/css/dark.css b/src/qt/res/css/dark.css index a3e1d5f03f5d..0e23b7b3e226 100644 --- a/src/qt/res/css/dark.css +++ b/src/qt/res/css/dark.css @@ -402,6 +402,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork, #btnWindow, #btnDisplay, +#btnAppearance, /* Sign/Verify dialog buttons */ #btnSignMessage, #btnVerifyMessage { @@ -421,6 +422,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:checked, #btnWindow:hover:checked, #btnDisplay:hover:checked, +#btnAppearance:hover:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:checked, #btnVerifyMessage:hover:checked { @@ -440,6 +442,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:!checked, #btnWindow:hover:!checked, #btnDisplay:hover:!checked, +#btnAppearance:hover:!checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:!checked, #btnVerifyMessage:hover:!checked { @@ -459,6 +462,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:checked, #btnWindow:checked, #btnDisplay:checked, +#btnAppearance:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:checked, #btnVerifyMessage:checked { diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index 1982e5555f9e..9722dc268860 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -649,6 +649,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork, #btnWindow, #btnDisplay, +#btnAppearance, /* Sign/Verify dialog buttons */ #btnSignMessage, #btnVerifyMessage { @@ -671,6 +672,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:checked, #btnWindow:hover:checked, #btnDisplay:hover:checked, +#btnAppearance:hover:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:checked, #btnVerifyMessage:hover:checked { @@ -693,6 +695,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:!checked, #btnWindow:hover:!checked, #btnDisplay:hover:!checked, +#btnAppearance:hover:!checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:!checked, #btnVerifyMessage:hover:!checked { @@ -715,6 +718,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:checked, #btnWindow:checked, #btnDisplay:checked, +#btnAppearance:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:checked, #btnVerifyMessage:checked { @@ -736,6 +740,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:pressed, #btnWindow:hover:pressed, #btnDisplay:hover:pressed, +#btnAppearance:hover:pressed, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:pressed, #btnVerifyMessage:hover:pressed { diff --git a/src/qt/res/css/light.css b/src/qt/res/css/light.css index 297de242a9c5..f6e0b3db2fa4 100644 --- a/src/qt/res/css/light.css +++ b/src/qt/res/css/light.css @@ -383,6 +383,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork, #btnWindow, #btnDisplay, +#btnAppearance, /* Sign/Verify dialog buttons */ #btnSignMessage, #btnVerifyMessage { @@ -402,6 +403,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:checked, #btnWindow:hover:checked, #btnDisplay:hover:checked, +#btnAppearance:hover:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:checked, #btnVerifyMessage:hover:checked { @@ -421,6 +423,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:!checked, #btnWindow:hover:!checked, #btnDisplay:hover:!checked, +#btnAppearance:hover:!checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:!checked, #btnVerifyMessage:hover:!checked { @@ -440,6 +443,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:checked, #btnWindow:checked, #btnDisplay:checked, +#btnAppearance:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:checked, #btnVerifyMessage:checked { diff --git a/src/qt/res/css/traditional.css b/src/qt/res/css/traditional.css index 0fed15c2307b..9ed3dacc91d1 100644 --- a/src/qt/res/css/traditional.css +++ b/src/qt/res/css/traditional.css @@ -56,6 +56,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork, #btnWindow, #btnDisplay, +#btnAppearance, /* Sign/Verify dialog buttons */ #btnSignMessage, #btnVerifyMessage { @@ -79,6 +80,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:checked, #btnWindow:hover:checked, #btnDisplay:hover:checked, +#btnAppearance:hover:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:checked, #btnVerifyMessage:hover:checked { @@ -101,6 +103,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:hover:!checked, #btnWindow:hover:!checked, #btnDisplay:hover:!checked, +#btnAppearance:hover:!checked, /* Sign/Verify dialog buttons */ #btnSignMessage:hover:!checked, #btnVerifyMessage:hover:!checked { @@ -123,6 +126,7 @@ QPushButton - Special case, tabbar replacement buttons #btnNetwork:checked, #btnWindow:checked, #btnDisplay:checked, +#btnAppearance:checked, /* Sign/Verify dialog buttons */ #btnSignMessage:checked, #btnVerifyMessage:checked { From 73a6c336b593e0bde61f7c58891222d8121b1de5 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 16 Jun 2020 00:26:49 +0200 Subject: [PATCH 02/14] qt: Add "Font scale" settings to Appearance Tab of OptionsDialog Allows to scale the font in the same way like with -font-scale. --- src/qt/forms/optionsdialog.ui | 78 +++++++++++++++++++++++++++++++++++ src/qt/optionsdialog.cpp | 8 ++++ src/qt/optionsdialog.h | 1 + src/qt/optionsmodel.cpp | 12 ++++++ src/qt/optionsmodel.h | 1 + src/qt/res/css/general.css | 5 +++ 6 files changed, 105 insertions(+) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 8499257462e1..57b206e26864 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -887,6 +887,84 @@ https://www.transifex.com/projects/p/dash/ + + + + 0 + + + + + Font Scale: + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 80 + 20 + + + + + + + + Smaller + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + -30 + + + 30 + + + Qt::Horizontal + + + + + + + Bigger + + + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 641527b0e1ed..83f85736b30f 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -196,6 +196,7 @@ void OptionsDialog::setModel(OptionsModel *_model) connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); /* Appearance */ connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); + connect(ui->fontScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFontScale(int))); } void OptionsDialog::setMapper() @@ -243,6 +244,7 @@ void OptionsDialog::setMapper() /* Appearance */ mapper->addMapping(ui->theme, OptionsModel::Theme); + mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale); } void OptionsDialog::showPage(int index) @@ -392,6 +394,12 @@ void OptionsDialog::updateTheme(const QString& theme) } } +void OptionsDialog::updateFontScale(int nScale) +{ + GUIUtil::setFontScale(nScale); + GUIUtil::updateFonts(); +} + ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : QValidator(parent) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 2a9a65005371..f3d27257eb0c 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -61,6 +61,7 @@ private Q_SLOTS: /* query the networks, for which the default proxy is used */ void updateDefaultProxyNets(); void updateTheme(const QString& toTheme = QString()); + void updateFontScale(int nScale); Q_SIGNALS: void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 26223c972943..00f9a98bdb5a 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -88,6 +88,11 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("theme")) settings.setValue("theme", GUIUtil::getDefaultTheme()); + if (!settings.contains("fontScale")) + settings.setValue("fontScale", GUIUtil::getFontScaleDefault()); + if (!gArgs.SoftSetArg("-font-scale", settings.value("fontScale").toString().toStdString())) + addOverriddenOption("-font-scale"); + #ifdef ENABLE_WALLET if (!settings.contains("fCoinControlFeatures")) settings.setValue("fCoinControlFeatures", false); @@ -338,6 +343,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const #endif // ENABLE_WALLET case Theme: return settings.value("theme"); + case FontScale: + return settings.value("fontScale"); case Language: return settings.value("language"); #ifdef ENABLE_WALLET @@ -514,6 +521,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in // Set in OptionsDialog::updateTheme slot now // to allow instant theme changes. break; + case FontScale: + if (settings.value("fontScale") != value) { + settings.setValue("fontScale", value); + } + break; case Language: if (settings.value("language") != value) { settings.setValue("language", value); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 01a7181dad01..09bfc37c068e 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -45,6 +45,7 @@ class OptionsModel : public QAbstractListModel ThirdPartyTxUrls, // QString Digits, // QString Theme, // QString + FontScale, // int Language, // QString CoinControlFeatures, // bool ThreadsScriptVerif, // int diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index 9722dc268860..12d74cfac0ef 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1276,6 +1276,11 @@ QDialog#OptionsDialog QLabel#label_3 { /* Translations Missing? Label */ color: #c79304; } +QDialog#OptionsDialog #lblSmaller, +QDialog#OptionsDialog #lblBigger { + min-width: 60px; +} + QDialog#OptionsDialog #line, QDialog#OptionsDialog #frame { border-top: 1px solid red; From 4b9a3aca3009b9b7dc45373c49e4a55c54397a1d Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 16 Jun 2020 15:00:18 +0200 Subject: [PATCH 03/14] qt: Add font weight settings to Appearance tab of OptionsDialog Allows to set the weight for normal and bold text --- src/qt/forms/optionsdialog.ui | 162 ++++++++++++++++++++++++++++++++++ src/qt/optionsdialog.cpp | 20 +++++ src/qt/optionsdialog.h | 2 + src/qt/optionsmodel.cpp | 24 +++++ src/qt/optionsmodel.h | 2 + src/qt/res/css/general.css | 6 +- 6 files changed, 215 insertions(+), 1 deletion(-) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 57b206e26864..4888e3545d75 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -965,6 +965,168 @@ https://www.transifex.com/projects/p/dash/ + + + + 0 + + + + + Font Weight Normal: + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 80 + 20 + + + + + + + + Lighter + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + 0 + + + 5 + + + 0 + + + Qt::Horizontal + + + + + + + Bolder + + + + + + + + + 0 + + + + + Font Weight Bold: + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 80 + 20 + + + + + + + + Lighter + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + 3 + + + 8 + + + 3 + + + Qt::Horizontal + + + + + + + Bolder + + + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 83f85736b30f..773c10554eaa 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -197,6 +197,8 @@ void OptionsDialog::setModel(OptionsModel *_model) /* Appearance */ connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); 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))); } void OptionsDialog::setMapper() @@ -245,6 +247,8 @@ void OptionsDialog::setMapper() /* Appearance */ mapper->addMapping(ui->theme, OptionsModel::Theme); mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale); + mapper->addMapping(ui->fontWeightNormalSlider, OptionsModel::FontWeightNormal); + mapper->addMapping(ui->fontWeightBoldSlider, OptionsModel::FontWeightBold); } void OptionsDialog::showPage(int index) @@ -400,6 +404,22 @@ void OptionsDialog::updateFontScale(int nScale) GUIUtil::updateFonts(); } +void OptionsDialog::updateFontWeightNormal(int nValue) +{ + QFont::Weight weight; + assert(GUIUtil::weightFromArg(nValue, weight)); + GUIUtil::setFontWeightNormal(weight); + GUIUtil::updateFonts(); +} + +void OptionsDialog::updateFontWeightBold(int nValue) +{ + QFont::Weight weight; + assert(GUIUtil::weightFromArg(nValue, weight)); + GUIUtil::setFontWeightBold(weight); + GUIUtil::updateFonts(); +} + ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : QValidator(parent) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index f3d27257eb0c..ca2f8ddaee28 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -62,6 +62,8 @@ private Q_SLOTS: void updateDefaultProxyNets(); void updateTheme(const QString& toTheme = QString()); void updateFontScale(int nScale); + void updateFontWeightNormal(int nValue); + void updateFontWeightBold(int nValue); Q_SIGNALS: void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 00f9a98bdb5a..49984dbec826 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -93,6 +93,16 @@ void OptionsModel::Init(bool resetSettings) if (!gArgs.SoftSetArg("-font-scale", settings.value("fontScale").toString().toStdString())) addOverriddenOption("-font-scale"); + if (!settings.contains("fontWeightNormal")) + settings.setValue("fontWeightNormal", GUIUtil::weightToArg(GUIUtil::getFontWeightNormalDefault())); + if (!gArgs.SoftSetArg("-font-weight-normal", settings.value("fontWeightNormal").toString().toStdString())) + addOverriddenOption("-font-weight-normal"); + + if (!settings.contains("fontWeightBold")) + settings.setValue("fontWeightBold", GUIUtil::weightToArg(GUIUtil::getFontWeightBoldDefault())); + if (!gArgs.SoftSetArg("-font-weight-bold", settings.value("fontWeightBold").toString().toStdString())) + addOverriddenOption("-font-weight-bold"); + #ifdef ENABLE_WALLET if (!settings.contains("fCoinControlFeatures")) settings.setValue("fCoinControlFeatures", false); @@ -345,6 +355,10 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return settings.value("theme"); case FontScale: return settings.value("fontScale"); + case FontWeightNormal: + return settings.value("fontWeightNormal"); + case FontWeightBold: + return settings.value("fontWeightBold"); case Language: return settings.value("language"); #ifdef ENABLE_WALLET @@ -526,6 +540,16 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in settings.setValue("fontScale", value); } break; + case FontWeightNormal: + if (settings.value("fontWeightNormal") != value) { + settings.setValue("fontWeightNormal", value); + } + break; + case FontWeightBold: + if (settings.value("fontWeightBold") != value) { + settings.setValue("fontWeightBold", value); + } + break; case Language: if (settings.value("language") != value) { settings.setValue("language", value); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 09bfc37c068e..5398baa258de 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -46,6 +46,8 @@ class OptionsModel : public QAbstractListModel Digits, // QString Theme, // QString FontScale, // int + FontWeightNormal, // int + FontWeightBold, // int Language, // QString CoinControlFeatures, // bool ThreadsScriptVerif, // int diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index 12d74cfac0ef..aa8cb22f640b 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1277,7 +1277,11 @@ QDialog#OptionsDialog QLabel#label_3 { /* Translations Missing? Label */ } QDialog#OptionsDialog #lblSmaller, -QDialog#OptionsDialog #lblBigger { +QDialog#OptionsDialog #lblBigger, +QDialog#OptionsDialog #lblBolderNormal, +QDialog#OptionsDialog #lblBolderBold, +QDialog#OptionsDialog #lblLighterNormal, +QDialog#OptionsDialog #lblLighterBold { min-width: 60px; } From 75383e03fe806098623c77e16e7c381df4fc7c98 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 16 Jun 2020 15:16:56 +0200 Subject: [PATCH 04/14] qt: Add font family setting to Appearance tab of OptionsDialog Allows to choose between system default font or montserrat --- src/qt/forms/optionsdialog.ui | 14 ++++++++++++++ src/qt/optionsdialog.cpp | 13 +++++++++++++ src/qt/optionsdialog.h | 1 + src/qt/optionsmodel.cpp | 10 ++++++++++ src/qt/optionsmodel.h | 1 + 5 files changed, 39 insertions(+) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 4888e3545d75..e7b309687c02 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -887,6 +887,20 @@ https://www.transifex.com/projects/p/dash/ + + + + + + Font Family: + + + + + + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 773c10554eaa..35c1d8dbfa92 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -135,6 +135,11 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : ui->theme->addItem(entry, QVariant(entry)); } + QString strMontserrat = GUIUtil::toString(GUIUtil::FontFamily::Montserrat); + QString strSystem = GUIUtil::toString(GUIUtil::FontFamily::SystemDefault); + ui->fontFamily->addItem(strMontserrat, QVariant(strMontserrat)); + ui->fontFamily->addItem(strSystem, QVariant(strSystem)); + ui->unit->setModel(new BitcoinUnits(this)); /* Widget-to-option mapper */ @@ -196,6 +201,7 @@ void OptionsDialog::setModel(OptionsModel *_model) connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); /* Appearance */ connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); + connect(ui->fontFamily, SIGNAL(currentTextChanged(const QString&)), this, SLOT(updateFontFamily(const QString&))); 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))); @@ -246,6 +252,7 @@ void OptionsDialog::setMapper() /* Appearance */ mapper->addMapping(ui->theme, OptionsModel::Theme); + mapper->addMapping(ui->fontFamily, OptionsModel::FontFamily); mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale); mapper->addMapping(ui->fontWeightNormalSlider, OptionsModel::FontWeightNormal); mapper->addMapping(ui->fontWeightBoldSlider, OptionsModel::FontWeightBold); @@ -398,6 +405,12 @@ void OptionsDialog::updateTheme(const QString& theme) } } +void OptionsDialog::updateFontFamily(const QString& family) +{ + GUIUtil::setFontFamily(GUIUtil::fromString(family)); + GUIUtil::updateFonts(); +} + void OptionsDialog::updateFontScale(int nScale) { GUIUtil::setFontScale(nScale); diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index ca2f8ddaee28..4f23c6936785 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -61,6 +61,7 @@ private Q_SLOTS: /* query the networks, for which the default proxy is used */ void updateDefaultProxyNets(); void updateTheme(const QString& toTheme = QString()); + void updateFontFamily(const QString& family); void updateFontScale(int nScale); void updateFontWeightNormal(int nValue); void updateFontWeightBold(int nValue); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 49984dbec826..a1d0b152ba41 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -88,6 +88,9 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("theme")) settings.setValue("theme", GUIUtil::getDefaultTheme()); + if (!settings.contains("fontFamily")) + settings.setValue("fontFamily", GUIUtil::fontFamilyToString(GUIUtil::getFontFamilyDefault())); + if (!settings.contains("fontScale")) settings.setValue("fontScale", GUIUtil::getFontScaleDefault()); if (!gArgs.SoftSetArg("-font-scale", settings.value("fontScale").toString().toStdString())) @@ -353,6 +356,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const #endif // ENABLE_WALLET case Theme: return settings.value("theme"); + case FontFamily: + return settings.value("fontFamily"); case FontScale: return settings.value("fontScale"); case FontWeightNormal: @@ -535,6 +540,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in // Set in OptionsDialog::updateTheme slot now // to allow instant theme changes. break; + case FontFamily: + if (settings.value("fontFamily") != value) { + settings.setValue("fontFamily", value); + } + break; case FontScale: if (settings.value("fontScale") != value) { settings.setValue("fontScale", value); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 5398baa258de..711318998dff 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -45,6 +45,7 @@ class OptionsModel : public QAbstractListModel ThirdPartyTxUrls, // QString Digits, // QString Theme, // QString + FontFamily, // int FontScale, // int FontWeightNormal, // int FontWeightBold, // int From 0e902b1f8dbd9fb2bbb6a575eeb9786fc797926c Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 17 Jul 2020 15:52:20 +0200 Subject: [PATCH 05/14] qt: GUIUtil - Maintain a map with supported weights for all fonts. --- src/qt/guiutil.cpp | 55 +++++++++++++++++++++++++++++++++++++++++----- src/qt/guiutil.h | 7 ++++-- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index f688a9a9531a..034e22ca73c8 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -131,6 +131,8 @@ static std::map> mapNormalFontUpdates; static std::set setFixedPitchFontUpdates; // Contains all widgets where a non-default fontsize has been seet with GUIUtil::setFont static std::map mapFontSizeUpdates; +// Contains a list of supported font weights for all members of GUIUtil::FontFamily +static std::map> mapSupportedWeights; #ifdef Q_OS_MAC // Contains all widgets where the macOS focus rect has been disabled. @@ -1316,6 +1318,37 @@ bool loadFonts() setApplicationFont(); + // Initialize supported font weights for all available fonts + // Generate a vector with supported font weights by comparing the width of a certain test text for all font weights + auto supportedWeights = [](FontFamily family) -> std::vector { + auto getTestWidth = [&](QFont::Weight weight) -> int { + QFont font = getFont(family, weight, false, defaultFontSize); + return QFontMetrics(font).width("Check the width of this text to see if the weight change has an impact!"); + }; + std::vector vecWeights{QFont::Thin, QFont::ExtraLight, QFont::Light, + QFont::Normal, QFont::Medium, QFont::DemiBold, + QFont::Bold, QFont::Black}; + std::vector vecSupported; + QFont::Weight prevWeight = vecWeights.front(); + for (auto weight = vecWeights.begin() + 1; weight != vecWeights.end(); ++weight) { + if (getTestWidth(prevWeight) != getTestWidth(*weight)) { + if (vecSupported.empty()) { + vecSupported.push_back(prevWeight); + } + vecSupported.push_back(*weight); + } + prevWeight = *weight; + } + return vecSupported; + }; + + FontFamily prevFontFamily = fontFamily; + setFontFamily(FontFamily::SystemDefault); + mapSupportedWeights.insert(std::make_pair(FontFamily::SystemDefault, supportedWeights(FontFamily::SystemDefault))); + setFontFamily(FontFamily::Montserrat); + mapSupportedWeights.insert(std::make_pair(FontFamily::Montserrat, supportedWeights(FontFamily::Montserrat))); + setFontFamily(prevFontFamily); + return true; } @@ -1440,13 +1473,11 @@ void updateFonts() } } -QFont getFont(FontWeight weight, bool fItalic, int nPointSize) +QFont getFont(FontFamily family, QFont::Weight qWeight, bool fItalic, int nPointSize) { QFont font; - QFont::Weight qWeight = toQFontWeight(weight); - - if (fontFamily == FontFamily::Montserrat) { + if (family == FontFamily::Montserrat) { static std::map mapMontserratMapping{ {QFont::Thin, "Thin"}, {QFont::ExtraLight, "ExtraLight"}, @@ -1496,12 +1527,21 @@ QFont getFont(FontWeight weight, bool fItalic, int nPointSize) } if (gArgs.GetBoolArg("-debug-ui", false)) { - qDebug() << __func__ << ": font size: " << font.pointSizeF() << " family: " << font.family() << ", style: " << font.styleName() << " match: " << font.exactMatch(); + qDebug() << __func__ << ": font size: " << font.pointSizeF() << " family: " << font.family() << ", style: " << font.styleName() << ", weight:" << font.weight() << " match: " << font.exactMatch(); } return font; } +QFont getFont(QFont::Weight qWeight, bool fItalic, int nPointSize) +{ + return getFont(fontFamily, qWeight, fItalic, nPointSize); +} +QFont getFont(FontWeight weight, bool fItalic, int nPointSize) +{ + return getFont(toQFontWeight(weight), fItalic, nPointSize); +} + QFont getFontNormal() { return getFont(FontWeight::Normal); @@ -1512,6 +1552,11 @@ QFont getFontBold() return getFont(FontWeight::Bold); } +std::vector getSupportedWeights(FontFamily family) +{ + return mapSupportedWeights[family]; +} + QString getActiveTheme() { QSettings settings; diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 5d44c428251b..7bac77364265 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -322,8 +322,9 @@ namespace GUIUtil GUIUtil::setFont */ void updateFonts(); - /** Get a properly weighted QFont object with the font Montserrat - Use ExtraLight as default as this lines up with the default in css. */ + /** Get a properly weighted QFont object with the selected font. */ + QFont getFont(FontFamily family, QFont::Weight qWeight, bool fItalic = false, int nPointSize = -1); + QFont getFont(QFont::Weight qWeight, bool fItalic = false, int nPointSize = -1); QFont getFont(FontWeight weight, bool fItalic = false, int nPointSize = -1); /** Get the default normal QFont */ @@ -332,6 +333,8 @@ namespace GUIUtil /** Get the default bold QFont */ QFont getFontBold(); + std::vector getSupportedWeights(FontFamily family); + /** Return the name of the currently active theme.*/ QString getActiveTheme(); From 1fc66fb9240e652c881a5b737dab5d24a0664a2f Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 2 Jul 2020 07:31:18 +0200 Subject: [PATCH 06/14] qt: Introduce AppearanceWidget A widget which just wraps all appearance related settings. Also replaces Appearance settings in OptionsDialog with the introduced widget. --- contrib/dash-qt.pro | 1 + src/Makefile.qt.include | 4 + src/qt/appearancewidget.cpp | 159 ++++++++++ src/qt/appearancewidget.h | 56 ++++ src/qt/bitcoingui.cpp | 1 - src/qt/forms/appearancewidget.ui | 486 +++++++++++++++++++++++++++++++ src/qt/forms/optionsdialog.ui | 284 ++---------------- src/qt/optionsdialog.cpp | 78 +---- src/qt/optionsdialog.h | 8 +- src/qt/optionsmodel.cpp | 2 +- src/qt/res/css/dark.css | 6 + src/qt/res/css/general.css | 47 ++- src/qt/res/css/light.css | 6 + src/qt/res/css/traditional.css | 38 +++ 14 files changed, 829 insertions(+), 347 deletions(-) create mode 100644 src/qt/appearancewidget.cpp create mode 100644 src/qt/appearancewidget.h create mode 100644 src/qt/forms/appearancewidget.ui diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index cde8c56930a8..708978d1d574 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,6 +1,7 @@ FORMS += \ ../src/qt/forms/aboutdialog.ui \ ../src/qt/forms/addressbookpage.ui \ + ../src/qt/forms/appearancewidget.ui \ ../src/qt/forms/askpassphrasedialog.ui \ ../src/qt/forms/coincontroldialog.ui \ ../src/qt/forms/debugwindow.ui \ diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index b975e8161342..3c1f09a870ee 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -32,6 +32,7 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ + qt/forms/appearancewidget.ui \ qt/forms/askpassphrasedialog.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ @@ -54,6 +55,7 @@ QT_FORMS_UI = \ QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ qt/moc_addresstablemodel.cpp \ + qt/moc_appearancewidget.cpp \ qt/moc_askpassphrasedialog.cpp \ qt/moc_bantablemodel.cpp \ qt/moc_bitcoinaddressvalidator.cpp \ @@ -126,6 +128,7 @@ PROTOBUF_PROTO = qt/paymentrequest.proto BITCOIN_QT_H = \ qt/addressbookpage.h \ qt/addresstablemodel.h \ + qt/appearancewidget.h \ qt/askpassphrasedialog.h \ qt/bantablemodel.h \ qt/bitcoinaddressvalidator.h \ @@ -238,6 +241,7 @@ RES_ICONS = \ qt/res/icons/network_disabled.png BITCOIN_QT_BASE_CPP = \ + qt/appearancewidget.cpp \ qt/bantablemodel.cpp \ qt/bitcoinaddressvalidator.cpp \ qt/bitcoinamountfield.cpp \ diff --git a/src/qt/appearancewidget.cpp b/src/qt/appearancewidget.cpp new file mode 100644 index 000000000000..51a5dc69b8b1 --- /dev/null +++ b/src/qt/appearancewidget.cpp @@ -0,0 +1,159 @@ +// Copyright (c) 2020 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include + +#include +#include + +#include + +#include +#include +#include +#include + +AppearanceWidget::AppearanceWidget(QWidget* parent) : + QWidget(parent), + ui(new Ui::AppearanceWidget), + fAcceptChanges(false), + prevTheme(GUIUtil::getActiveTheme()), + prevFontFamily(GUIUtil::getFontFamily()), + prevScale(GUIUtil::getFontScale()), + prevWeightNormal(GUIUtil::getFontWeightNormal()), + prevWeightBold(GUIUtil::getFontWeightBold()) +{ + ui->setupUi(this); + + for (const QString& entry : GUIUtil::listThemes()) { + ui->theme->addItem(entry, QVariant(entry)); + } + + GUIUtil::FontFamily fontSystem = GUIUtil::FontFamily::SystemDefault; + GUIUtil::FontFamily fontMontserrat = GUIUtil::FontFamily::Montserrat; + + ui->fontFamily->addItem(GUIUtil::fontFamilyToString(fontSystem), QVariant(static_cast(fontSystem))); + ui->fontFamily->addItem(GUIUtil::fontFamilyToString(fontMontserrat), QVariant(static_cast(fontMontserrat))); + + updateWeightSlider(); + + mapper = new QDataWidgetMapper(this); + mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + mapper->setOrientation(Qt::Vertical); + + connect(ui->theme, SIGNAL(currentTextChanged(const QString&)), this, SLOT(updateTheme(const QString&))); + connect(ui->fontFamily, SIGNAL(activated(int)), this, SLOT(updateFontFamily(int))); + 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))); +} + +AppearanceWidget::~AppearanceWidget() +{ + if (fAcceptChanges) { + mapper->submit(); + } else { + if (prevTheme != GUIUtil::getActiveTheme()) { + updateTheme(prevTheme); + } + if (prevFontFamily != GUIUtil::getFontFamily()) { + GUIUtil::setFontFamily(prevFontFamily); + } + if (prevScale != GUIUtil::getFontScale()) { + GUIUtil::setFontScale(prevScale); + } + if (prevWeightNormal != GUIUtil::getFontWeightNormal()) { + GUIUtil::setFontWeightNormal(prevWeightNormal); + } + if (prevWeightBold != GUIUtil::getFontWeightBold()) { + GUIUtil::setFontWeightBold(prevWeightBold); + } + } + delete ui; +} + +void AppearanceWidget::setModel(OptionsModel* _model) +{ + this->model = _model; + + if (_model) { + mapper->setModel(_model); + mapper->addMapping(ui->theme, OptionsModel::Theme); + mapper->addMapping(ui->fontFamily, OptionsModel::FontFamily); + mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale); + mapper->addMapping(ui->fontWeightNormalSlider, OptionsModel::FontWeightNormal); + mapper->addMapping(ui->fontWeightBoldSlider, OptionsModel::FontWeightBold); + mapper->toFirst(); + } +} + +void AppearanceWidget::accept() +{ + fAcceptChanges = true; +} + +void AppearanceWidget::updateTheme(const QString& theme) +{ + QString newValue = theme.isEmpty() ? ui->theme->currentData().toString() : theme; + if (GUIUtil::getActiveTheme() != newValue) { + QSettings().setValue("theme", newValue); + GUIUtil::loadTheme(); + } +} + +void AppearanceWidget::updateFontFamily(int index) +{ + GUIUtil::setFontFamily(static_cast(ui->fontFamily->itemData(index).toInt())); + updateWeightSlider(); +} + +void AppearanceWidget::updateFontScale(int nScale) +{ + GUIUtil::setFontScale(nScale); +} + +void AppearanceWidget::updateFontWeightNormal(int nValue, bool fForce) +{ + int nSliderValue = nValue; + if (nValue > ui->fontWeightBoldSlider->value() && !fForce) { + nSliderValue = ui->fontWeightBoldSlider->value(); + } + const QSignalBlocker blocker(ui->fontWeightNormalSlider); + ui->fontWeightNormalSlider->setValue(nSliderValue); + GUIUtil::setFontWeightNormal(GUIUtil::getSupportedWeights(GUIUtil::getFontFamily())[ui->fontWeightNormalSlider->value()]); +} + +void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce) +{ + int nSliderValue = nValue; + if (nValue < ui->fontWeightNormalSlider->value() && !fForce) { + nSliderValue = ui->fontWeightNormalSlider->value(); + } + const QSignalBlocker blocker(ui->fontWeightBoldSlider); + ui->fontWeightBoldSlider->setValue(nSliderValue); + GUIUtil::setFontWeightBold(GUIUtil::getSupportedWeights(GUIUtil::getFontFamily())[ui->fontWeightBoldSlider->value()]); +} + +void AppearanceWidget::updateWeightSlider() +{ + int nMaximum = GUIUtil::getSupportedWeights(GUIUtil::getFontFamily()).size() - 1; + + ui->fontWeightNormalSlider->setMinimum(0); + ui->fontWeightNormalSlider->setMaximum(nMaximum); + + ui->fontWeightBoldSlider->setMinimum(0); + ui->fontWeightBoldSlider->setMaximum(nMaximum); + + if (nMaximum < 4) { + updateFontWeightNormal(0, true); + updateFontWeightBold(nMaximum, true); + } else { + updateFontWeightNormal(1, true); + updateFontWeightBold(4, true); + } +} diff --git a/src/qt/appearancewidget.h b/src/qt/appearancewidget.h new file mode 100644 index 000000000000..b97496ced83c --- /dev/null +++ b/src/qt/appearancewidget.h @@ -0,0 +1,56 @@ +// Copyright (c) 2020 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef DASH_QT_APPEARANCE_WIDGET_H +#define DASH_QT_APPEARANCE_WIDGET_H + +#include + +#include + +namespace Ui { +class AppearanceWidget; +} + +class OptionsModel; + +class QDataWidgetMapper; +class QSlider; +class QComboBox; + +class AppearanceWidget : public QWidget +{ + Q_OBJECT + +public: + explicit AppearanceWidget(QWidget* parent = 0); + ~AppearanceWidget(); + + void setModel(OptionsModel* model); + +public Q_SLOTS: + void accept(); + +private Q_SLOTS: + void updateTheme(const QString& toTheme = QString()); + void updateFontFamily(int index); + void updateFontScale(int nScale); + void updateFontWeightNormal(int nValue, bool fForce = false); + void updateFontWeightBold(int nValue, bool fForce = false); + +private: + Ui::AppearanceWidget* ui; + QDataWidgetMapper* mapper; + OptionsModel* model; + bool fAcceptChanges; + QString prevTheme; + int prevScale; + GUIUtil::FontFamily prevFontFamily; + QFont::Weight prevWeightNormal; + QFont::Weight prevWeightBold; + + void updateWeightSlider(); +}; + +#endif // DASH_QT_APPEARANCE_WIDGET_H diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 63886e2346ae..7735be536310 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -842,7 +842,6 @@ void BitcoinGUI::optionsClicked() OptionsDialog dlg(this, enableWallet); dlg.setModel(clientModel->getOptionsModel()); - connect(&dlg, &OptionsDialog::themeChanged, [=]() { GUIUtil::loadTheme(); }); dlg.exec(); } diff --git a/src/qt/forms/appearancewidget.ui b/src/qt/forms/appearancewidget.ui new file mode 100644 index 000000000000..d8d42ad007a6 --- /dev/null +++ b/src/qt/forms/appearancewidget.ui @@ -0,0 +1,486 @@ + + + AppearanceWidget + + + + 0 + 0 + 445 + 156 + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QLayout::SetDefaultConstraint + + + 0 + + + + + QLayout::SetFixedSize + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Lighter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + 0 + + + 5 + + + 0 + + + Qt::Horizontal + + + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Bolder + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 0 + 0 + + + + Font Weight Normal: + + + + + + + QLayout::SetFixedSize + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Smaller + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + -30 + + + 30 + + + 10 + + + 0 + + + Qt::Horizontal + + + QSlider::NoTicks + + + 3 + + + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Bigger + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 0 + 0 + + + + Font Scale: + + + + + + + QLayout::SetFixedSize + + + + + + 282 + 0 + + + + + 282 + 16777215 + + + + + + + + + + + 0 + 0 + + + + Font Family: + + + + + + + QLayout::SetFixedSize + + + + + + 282 + 0 + + + + + 282 + 16777215 + + + + + + + + + + + 0 + 0 + + + + Theme: + + + + + + + + 0 + 0 + + + + Font Weight Bold: + + + + + + + QLayout::SetFixedSize + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Lighter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + + 150 + 16777215 + + + + 3 + + + 8 + + + 3 + + + Qt::Horizontal + + + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Bolder + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + + 2 + 20 + + + + + + + + Qt::Horizontal + + + + 2 + 20 + + + + + + + + Qt::Horizontal + + + + 2 + 20 + + + + + + + + Qt::Horizontal + + + + 2 + 20 + + + + + + + + Qt::Horizontal + + + + 2 + 20 + + + + + + + + + + + diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index e7b309687c02..43f67725d869 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -6,10 +6,16 @@ 0 0 - 576 - 402 + 583 + 537 + + + 0 + 0 + + Options @@ -96,7 +102,7 @@ - 0 + 5 @@ -874,272 +880,20 @@ https://www.transifex.com/projects/p/dash/ - - - - - Theme: - - - - - - - - - - - - - - Font Family: - - - - - - - - - - - - 0 - - - - - Font Scale: - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 80 - 20 - - - - - - - - Smaller - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 150 - 0 - - - - - 150 - 16777215 - - - - -30 - - - 30 - - - Qt::Horizontal - - - - - - - Bigger - - - - + - - - 0 + + + Qt::Vertical - - - - Font Weight Normal: - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 80 - 20 - - - - - - - - Lighter - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 150 - 0 - - - - - 150 - 16777215 - - - - 0 - - - 5 - - - 0 - - - Qt::Horizontal - - - - - - - Bolder - - - - - - - - - 0 + + + 20 + 40 + - - - - Font Weight Bold: - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 80 - 20 - - - - - - - - Lighter - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 150 - 0 - - - - - 150 - 16777215 - - - - 3 - - - 8 - - - 3 - - - Qt::Horizontal - - - - - - - Bolder - - - - + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 35c1d8dbfa92..70c92bb84250 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -37,8 +38,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : { ui->setupUi(this); - previousTheme = GUIUtil::getActiveTheme(); - GUIUtil::setFont({ui->statusLabel}, GUIUtil::FontWeight::Bold, 16); GUIUtil::updateFonts(); @@ -130,16 +129,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : } ui->thirdPartyTxUrls->setPlaceholderText("https://example.com/tx/%s"); - /* Theme selector */ - for (const QString& entry : GUIUtil::listThemes()) { - ui->theme->addItem(entry, QVariant(entry)); - } - - QString strMontserrat = GUIUtil::toString(GUIUtil::FontFamily::Montserrat); - QString strSystem = GUIUtil::toString(GUIUtil::FontFamily::SystemDefault); - ui->fontFamily->addItem(strMontserrat, QVariant(strMontserrat)); - ui->fontFamily->addItem(strSystem, QVariant(strSystem)); - ui->unit->setModel(new BitcoinUnits(this)); /* Widget-to-option mapper */ @@ -154,6 +143,12 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : connect(ui->proxyIpTor, SIGNAL(validationDidChange(QValidatedLineEdit *)), this, SLOT(updateProxyValidationState())); connect(ui->proxyPort, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState())); connect(ui->proxyPortTor, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState())); + + QVBoxLayout* appearanceLayout = new QVBoxLayout(); + appearanceLayout->setContentsMargins(0, 0, 0, 0); + appearance = new AppearanceWidget(ui->widgetAppearance); + appearanceLayout->addWidget(appearance); + ui->widgetAppearance->setLayout(appearanceLayout); } OptionsDialog::~OptionsDialog() @@ -180,6 +175,8 @@ void OptionsDialog::setModel(OptionsModel *_model) setMapper(); mapper->toFirst(); + appearance->setModel(_model); + updateDefaultProxyNets(); } @@ -199,12 +196,6 @@ void OptionsDialog::setModel(OptionsModel *_model) connect(ui->digits, SIGNAL(valueChanged()), this, SLOT(showRestartWarning())); connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning())); connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); - /* Appearance */ - connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(updateTheme())); - connect(ui->fontFamily, SIGNAL(currentTextChanged(const QString&)), this, SLOT(updateFontFamily(const QString&))); - 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))); } void OptionsDialog::setMapper() @@ -250,12 +241,9 @@ void OptionsDialog::setMapper() mapper->addMapping(ui->unit, OptionsModel::DisplayUnit); mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); - /* Appearance */ - mapper->addMapping(ui->theme, OptionsModel::Theme); - mapper->addMapping(ui->fontFamily, OptionsModel::FontFamily); - mapper->addMapping(ui->fontScaleSlider, OptionsModel::FontScale); - mapper->addMapping(ui->fontWeightNormalSlider, OptionsModel::FontWeightNormal); - mapper->addMapping(ui->fontWeightBoldSlider, OptionsModel::FontWeightBold); + /* Appearance + See AppearanceWidget::setModel + */ } void OptionsDialog::showPage(int index) @@ -301,6 +289,7 @@ void OptionsDialog::on_resetButton_clicked() void OptionsDialog::on_okButton_clicked() { mapper->submit(); + appearance->accept(); #ifdef ENABLE_WALLET privateSendClient.nCachedNumBlocks = std::numeric_limits::max(); if(HasWallets()) @@ -312,9 +301,6 @@ void OptionsDialog::on_okButton_clicked() void OptionsDialog::on_cancelButton_clicked() { - if (previousTheme != GUIUtil::getActiveTheme()) { - updateTheme(previousTheme); - } reject(); } @@ -395,44 +381,6 @@ void OptionsDialog::updateDefaultProxyNets() (strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachTor->setChecked(true) : ui->proxyReachTor->setChecked(false); } -void OptionsDialog::updateTheme(const QString& theme) -{ - QString newValue = theme.isEmpty() ? ui->theme->value().toString() : theme; - if (GUIUtil::getActiveTheme() != newValue) { - QSettings().setValue("theme", newValue); - QSettings().sync(); - Q_EMIT themeChanged(); - } -} - -void OptionsDialog::updateFontFamily(const QString& family) -{ - GUIUtil::setFontFamily(GUIUtil::fromString(family)); - GUIUtil::updateFonts(); -} - -void OptionsDialog::updateFontScale(int nScale) -{ - GUIUtil::setFontScale(nScale); - GUIUtil::updateFonts(); -} - -void OptionsDialog::updateFontWeightNormal(int nValue) -{ - QFont::Weight weight; - assert(GUIUtil::weightFromArg(nValue, weight)); - GUIUtil::setFontWeightNormal(weight); - GUIUtil::updateFonts(); -} - -void OptionsDialog::updateFontWeightBold(int nValue) -{ - QFont::Weight weight; - assert(GUIUtil::weightFromArg(nValue, weight)); - GUIUtil::setFontWeightBold(weight); - GUIUtil::updateFonts(); -} - ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : QValidator(parent) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 4f23c6936785..cc0bfdb00b93 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -9,6 +9,7 @@ #include #include +class AppearanceWidget; class OptionsModel; class QValidatedLineEdit; @@ -60,15 +61,9 @@ private Q_SLOTS: void updateProxyValidationState(); /* query the networks, for which the default proxy is used */ void updateDefaultProxyNets(); - void updateTheme(const QString& toTheme = QString()); - void updateFontFamily(const QString& family); - void updateFontScale(int nScale); - void updateFontWeightNormal(int nValue); - void updateFontWeightBold(int nValue); Q_SIGNALS: void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); - void themeChanged(); private: Ui::OptionsDialog *ui; @@ -76,6 +71,7 @@ private Q_SLOTS: QDataWidgetMapper *mapper; QButtonGroup pageButtons; QString previousTheme; + AppearanceWidget* appearance; }; #endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index a1d0b152ba41..49b0ab74f5d0 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -537,7 +537,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; #endif // ENABLE_WALLET case Theme: - // Set in OptionsDialog::updateTheme slot now + // Set in AppearanceWidget::updateTheme slot now // to allow instant theme changes. break; case FontFamily: diff --git a/src/qt/res/css/dark.css b/src/qt/res/css/dark.css index 0e23b7b3e226..dfe3db60559d 100644 --- a/src/qt/res/css/dark.css +++ b/src/qt/res/css/dark.css @@ -634,6 +634,12 @@ AddressBookPage QTableView { color: #c7c7c7; } +/****************************************************** +AppearanceWidget +******************************************************/ + +/***** No dark.css specific coloring here yet *****/ + /****************************************************** AskPassphraseDialog ******************************************************/ diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index aa8cb22f640b..54a0364b679e 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1059,6 +1059,44 @@ QWidget#AddressBookPage QHeaderView::section { /* Min width for Windows fix */ min-width: 260px; } +/****************************************************** +AppearanceWidget +******************************************************/ + +AppearanceWidget #lblSmaller, +AppearanceWidget #lblBigger, +AppearanceWidget #lblBolderNormal, +AppearanceWidget #lblBolderBold, +AppearanceWidget #lblLighterNormal, +AppearanceWidget #lblLighterBold { + /* Exceptional use of font-size here to + avoid changes of the slider postions */ + font-size: 13px; +} + +AppearanceWidget #lblTheme, +AppearanceWidget #lblFontFamily, +AppearanceWidget #lblFontScale, +AppearanceWidget #lblFontWeightNormal, +AppearanceWidget #lblFontWeightBold, +AppearanceWidget #lblSmaller, +AppearanceWidget #lblBigger, +AppearanceWidget #lblBolderNormal, +AppearanceWidget #lblBolderBold, +AppearanceWidget #lblLighterNormal, +AppearanceWidget #lblLighterBold { + min-height: 40px; +} + +AppearanceWidget #lblTheme, +AppearanceWidget #lblFontFamily, +AppearanceWidget #lblFontScale, +AppearanceWidget #lblFontWeightNormal, +AppearanceWidget #lblFontWeightBold { + min-width: 170px; + max-width: 170px; +} + /****************************************************** AskPassphraseDialog ******************************************************/ @@ -1276,15 +1314,6 @@ QDialog#OptionsDialog QLabel#label_3 { /* Translations Missing? Label */ color: #c79304; } -QDialog#OptionsDialog #lblSmaller, -QDialog#OptionsDialog #lblBigger, -QDialog#OptionsDialog #lblBolderNormal, -QDialog#OptionsDialog #lblBolderBold, -QDialog#OptionsDialog #lblLighterNormal, -QDialog#OptionsDialog #lblLighterBold { - min-width: 60px; -} - QDialog#OptionsDialog #line, QDialog#OptionsDialog #frame { border-top: 1px solid red; diff --git a/src/qt/res/css/light.css b/src/qt/res/css/light.css index f6e0b3db2fa4..87febde9b344 100644 --- a/src/qt/res/css/light.css +++ b/src/qt/res/css/light.css @@ -617,6 +617,12 @@ AddressBookPage QTableView { color: #555; } +/****************************************************** +AppearanceWidget +******************************************************/ + +/***** No light.css specific coloring here yet *****/ + /****************************************************** AskPassphraseDialog ******************************************************/ diff --git a/src/qt/res/css/traditional.css b/src/qt/res/css/traditional.css index 9ed3dacc91d1..f4c3a72c133b 100644 --- a/src/qt/res/css/traditional.css +++ b/src/qt/res/css/traditional.css @@ -156,6 +156,44 @@ QWidget#contentWidget { /* The actual content with the text/buttons/etc... */ border-radius: 6px; } +/****************************************************** +AppearanceWidget +******************************************************/ + +AppearanceWidget #lblSmaller, +AppearanceWidget #lblBigger, +AppearanceWidget #lblBolderNormal, +AppearanceWidget #lblBolderBold, +AppearanceWidget #lblLighterNormal, +AppearanceWidget #lblLighterBold { + /* Exceptional use of font-size here to + avoid changes of the slider postions */ + font-size: 13px; +} + +AppearanceWidget #lblTheme, +AppearanceWidget #lblFontFamily, +AppearanceWidget #lblFontScale, +AppearanceWidget #lblFontWeightNormal, +AppearanceWidget #lblFontWeightBold, +AppearanceWidget #lblSmaller, +AppearanceWidget #lblBigger, +AppearanceWidget #lblBolderNormal, +AppearanceWidget #lblBolderBold, +AppearanceWidget #lblLighterNormal, +AppearanceWidget #lblLighterBold { + min-height: 40px; +} + +AppearanceWidget #lblTheme, +AppearanceWidget #lblFontFamily, +AppearanceWidget #lblFontScale, +AppearanceWidget #lblFontWeightNormal, +AppearanceWidget #lblFontWeightBold { + min-width: 170px; + max-width: 170px; +} + /****************************************************** OverviewPage ******************************************************/ From 6a03c623cda0bff794444347d8076f67182628fc Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 7 Jul 2020 15:27:32 +0200 Subject: [PATCH 07/14] qt: Introduce initial appearance setup dialog This will pop up the first time the user starts the DashCore version with the new UI changes. --- src/qt/dash.cpp | 3 +++ src/qt/guiutil.cpp | 46 ++++++++++++++++++++++++++++++++++ src/qt/guiutil.h | 4 +++ src/qt/res/css/dark.css | 8 ++++++ src/qt/res/css/general.css | 27 ++++++++++++++++++++ src/qt/res/css/light.css | 8 ++++++ src/qt/res/css/traditional.css | 30 ++++++++++++++++++++++ 7 files changed, 126 insertions(+) diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 29d90bb47434..ba2288af174c 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -515,6 +515,9 @@ void BitcoinApplication::initializeResult(bool success) } Q_EMIT splashFinished(window); + // Let the users setup their prefered appearance if there are no settings for it defined yet. + GUIUtil::setupAppearance(window, clientModel->getOptionsModel()); + #ifdef ENABLE_WALLET // Now that initialization/startup is done, process any command-line // dash: URIs or payment requests: diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 034e22ca73c8..211a0d283199 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -5,8 +5,10 @@ #include +#include #include #include +#include #include #include @@ -46,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +61,7 @@ #include #include #include +#include static fs::detail::utf8_codecvt_facet utf8; @@ -260,6 +264,48 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent) widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter); } +void setupAppearance(QWidget* parent, OptionsModel* model) +{ + if (!QSettings().value("fAppearanceSetupDone", false).toBool()) { + // Create the dialog + QDialog dlg(parent); + dlg.setObjectName("AppearanceSetup"); + dlg.setWindowTitle(QObject::tr("Appearance Setup")); + dlg.setWindowIcon(QIcon(":icons/bitcoin")); + // And the widgets we add to it + QLabel lblHeading(QObject::tr("Please choose your prefered settings for the appearance of %1").arg(QObject::tr(PACKAGE_NAME)), &dlg); + lblHeading.setObjectName("lblHeading"); + lblHeading.setWordWrap(true); + QLabel lblSubHeading(QObject::tr("This can also be adjusted later in the \"Appearance\" tab of the preferences."), &dlg); + lblSubHeading.setObjectName("lblSubHeading"); + lblSubHeading.setWordWrap(true); + AppearanceWidget appearance(&dlg); + appearance.setModel(model); + QFrame line(&dlg); + line.setFrameShape(QFrame::HLine); + QDialogButtonBox buttonBox(QDialogButtonBox::Save); + // Put them into a vbox and add the vbox to the dialog + QVBoxLayout layout; + layout.addWidget(&lblHeading); + layout.addWidget(&lblSubHeading); + layout.addWidget(&line); + layout.addWidget(&appearance); + layout.addWidget(&buttonBox); + dlg.setLayout(&layout); + // Adjust the headings + setFont({&lblHeading}, FontWeight::Bold, 16); + setFont({&lblSubHeading}, FontWeight::Normal, 14, true); + // Make sure the dialog closes and accepts the settings if save has been pressed + QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() { + QSettings().setValue("fAppearanceSetupDone", true); + appearance.accept(); + dlg.accept(); + }); + // And fire it! + dlg.exec(); + } +} + bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { // return if URI is not valid or is no dash: URI diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 7bac77364265..e0a9533f1378 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -18,6 +18,7 @@ #include class QValidatedLineEdit; +class OptionsModel; class SendCoinsRecipient; QT_BEGIN_NAMESPACE @@ -95,6 +96,9 @@ namespace GUIUtil void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllowURI = false); void setupAmountWidget(QLineEdit *widget, QWidget *parent); + // Setup appearance settings if not done yet + void setupAppearance(QWidget* parent, OptionsModel* model); + // Parse "dash:" URI into recipient object, return true on successful parsing bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out); bool parseBitcoinURI(QString uri, SendCoinsRecipient *out); diff --git a/src/qt/res/css/dark.css b/src/qt/res/css/dark.css index dfe3db60559d..09ae5929e430 100644 --- a/src/qt/res/css/dark.css +++ b/src/qt/res/css/dark.css @@ -634,6 +634,14 @@ AddressBookPage QTableView { color: #c7c7c7; } +/****************************************************** +AppearanceSetup +******************************************************/ + +QDialog#AppearanceSetup > QFrame { + border-color: #4a4a4b; +} + /****************************************************** AppearanceWidget ******************************************************/ diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index 54a0364b679e..8d8eeda0b960 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1059,6 +1059,33 @@ QWidget#AddressBookPage QHeaderView::section { /* Min width for Windows fix */ min-width: 260px; } +/****************************************************** +AppearanceSetup +******************************************************/ + +QDialog#AppearanceSetup { + min-width: 600px; + min-height: 400px; +} + +QDialog#AppearanceSetup > QFrame { + border-bottom: 1px solid red; +} + +QDialog#AppearanceSetup > QLabel#lblHeading { + max-height: 50px; +} + +QDialog#AppearanceSetup > QLabel#lblSubHeading { + min-height: 30px; + max-height: 50px; +} + +QDialog#AppearanceSetup > AppearanceWidget { + min-height: 250px; + max-height: 250px; +} + /****************************************************** AppearanceWidget ******************************************************/ diff --git a/src/qt/res/css/light.css b/src/qt/res/css/light.css index 87febde9b344..f94fd8e5816c 100644 --- a/src/qt/res/css/light.css +++ b/src/qt/res/css/light.css @@ -617,6 +617,14 @@ AddressBookPage QTableView { color: #555; } +/****************************************************** +AppearanceSetup +******************************************************/ + +QDialog#AppearanceSetup > QFrame { + border-color: #dcdcdc; +} + /****************************************************** AppearanceWidget ******************************************************/ diff --git a/src/qt/res/css/traditional.css b/src/qt/res/css/traditional.css index f4c3a72c133b..a41467a0cece 100644 --- a/src/qt/res/css/traditional.css +++ b/src/qt/res/css/traditional.css @@ -156,6 +156,36 @@ QWidget#contentWidget { /* The actual content with the text/buttons/etc... */ border-radius: 6px; } +/****************************************************** +AppearanceSetup +******************************************************/ + +QDialog#AppearanceSetup { + min-width: 600px; + max-width: 600px; + min-height: 400px; + max-height: 400px; +} + +QDialog#AppearanceSetup > QFrame { + border-bottom: 1px solid red; +} + +QDialog#AppearanceSetup > QLabel#lblHeading { + min-height: 50px; + max-height: 50px; +} + +QDialog#AppearanceSetup > QLabel#lblSubHeading { + min-height: 30px; + max-height: 30px; +} + +QDialog#AppearanceSetup > AppearanceWidget { + min-height: 250px; + max-height: 250px; +} + /****************************************************** AppearanceWidget ******************************************************/ From 90ccaac63ed19203e79b8dc8281dfab37a56134d Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 16 Jun 2020 16:12:25 +0200 Subject: [PATCH 08/14] qt: Load font related settings in GUIUtil::loadFonts --- src/qt/guiutil.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 211a0d283199..c2533ab1bea2 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1362,6 +1362,26 @@ bool loadFonts() } } + // Load font related settings + QSettings settings; + QFont::Weight weight; + + if (!gArgs.IsArgSet("-font-family")) { + fontFamily = fontFamilyFromString(settings.value("fontFamily").toString()); + } + + if (!gArgs.IsArgSet("-font-scale")) { + fontScale = settings.value("fontScale").toInt(); + } + + if (!gArgs.IsArgSet("-font-weight-normal") && weightFromArg(settings.value("fontWeightNormal").toInt(), weight)) { + fontWeightNormal = weight; + } + + if (!gArgs.IsArgSet("-font-weight-bold") && weightFromArg(settings.value("fontWeightBold").toInt(), weight)) { + fontWeightBold = weight; + } + setApplicationFont(); // Initialize supported font weights for all available fonts From aaeabf5a97f351e213569200638c1fc16e7e7f1e Mon Sep 17 00:00:00 2001 From: xdustinface Date: Mon, 20 Jul 2020 23:59:24 +0200 Subject: [PATCH 09/14] qt: Make osDefaultFont global in GUIUtil to fix getFont() Before getFont(FontFamily, ...) wasn't always able to return the correct font without the requested font family beeing set as application font upfront. --- src/qt/guiutil.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index c2533ab1bea2..4cc6dd38c690 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -105,6 +105,8 @@ static const std::map mapStyleToTheme{ {"scrollbars.css", ""} }; +/** loadFonts stores the SystemDefault font in osDefaultFont to be able to reference it later again */ +static std::unique_ptr osDefaultFont; /** Font related default values. */ static const FontFamily defaultFontFamily = FontFamily::SystemDefault; static const int defaultFontSize = 12; @@ -1306,6 +1308,9 @@ double getScaledFontSize(int nSize) bool loadFonts() { + // Before any font changes store the applications default font to use it as SystemDefault. + osDefaultFont = std::make_unique(QApplication::font()); + QString family = fontFamilyToString(FontFamily::Montserrat); QString italic = "Italic"; @@ -1408,20 +1413,14 @@ bool loadFonts() return vecSupported; }; - FontFamily prevFontFamily = fontFamily; - setFontFamily(FontFamily::SystemDefault); mapSupportedWeights.insert(std::make_pair(FontFamily::SystemDefault, supportedWeights(FontFamily::SystemDefault))); - setFontFamily(FontFamily::Montserrat); mapSupportedWeights.insert(std::make_pair(FontFamily::Montserrat, supportedWeights(FontFamily::Montserrat))); - setFontFamily(prevFontFamily); return true; } void setApplicationFont() { - static QFont osDefaultFont = QApplication::font(); - std::unique_ptr font; if (fontFamily == FontFamily::Montserrat) { @@ -1438,7 +1437,7 @@ void setApplicationFont() font->setWeight(getFontWeightNormal()); #endif } else { - font = std::make_unique(osDefaultFont); + font = std::make_unique(*osDefaultFont); } font->setPointSizeF(defaultFontSize); @@ -1583,7 +1582,7 @@ QFont getFont(FontFamily family, QFont::Weight qWeight, bool fItalic, int nPoint font.setStyle(fItalic ? QFont::StyleItalic : QFont::StyleNormal); #endif } else { - font.setFamily(QApplication::font().family()); + font.setFamily(osDefaultFont->family()); font.setWeight(qWeight); font.setStyle(fItalic ? QFont::StyleItalic : QFont::StyleNormal); } From 8089a1300bb05ce82e1d140105af8bdec7554f48 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 21 Jul 2020 00:22:38 +0200 Subject: [PATCH 10/14] qt: Improve supported weight helpers Add conversion helpers. and let all of them depend on the currently selected font. --- src/qt/appearancewidget.cpp | 6 +++--- src/qt/guiutil.cpp | 23 +++++++++++++++++++++-- src/qt/guiutil.h | 7 ++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/qt/appearancewidget.cpp b/src/qt/appearancewidget.cpp index 51a5dc69b8b1..9c0747e72790 100644 --- a/src/qt/appearancewidget.cpp +++ b/src/qt/appearancewidget.cpp @@ -125,7 +125,7 @@ void AppearanceWidget::updateFontWeightNormal(int nValue, bool fForce) } const QSignalBlocker blocker(ui->fontWeightNormalSlider); ui->fontWeightNormalSlider->setValue(nSliderValue); - GUIUtil::setFontWeightNormal(GUIUtil::getSupportedWeights(GUIUtil::getFontFamily())[ui->fontWeightNormalSlider->value()]); + GUIUtil::setFontWeightNormal(GUIUtil::supportedWeightFromArg(ui->fontWeightNormalSlider->value())); } void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce) @@ -136,12 +136,12 @@ void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce) } const QSignalBlocker blocker(ui->fontWeightBoldSlider); ui->fontWeightBoldSlider->setValue(nSliderValue); - GUIUtil::setFontWeightBold(GUIUtil::getSupportedWeights(GUIUtil::getFontFamily())[ui->fontWeightBoldSlider->value()]); + GUIUtil::setFontWeightBold(GUIUtil::supportedWeightFromArg(ui->fontWeightBoldSlider->value())); } void AppearanceWidget::updateWeightSlider() { - int nMaximum = GUIUtil::getSupportedWeights(GUIUtil::getFontFamily()).size() - 1; + int nMaximum = GUIUtil::getSupportedWeights().size() - 1; ui->fontWeightNormalSlider->setMinimum(0); ui->fontWeightNormalSlider->setMaximum(nMaximum); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 4cc6dd38c690..ca81850cfc2c 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1617,9 +1617,28 @@ QFont getFontBold() return getFont(FontWeight::Bold); } -std::vector getSupportedWeights(FontFamily family) +std::vector getSupportedWeights() { - return mapSupportedWeights[family]; + assert(mapSupportedWeights.count(fontFamily)); + return mapSupportedWeights[fontFamily]; +} + +QFont::Weight supportedWeightFromArg(int nValue) +{ + auto vecWeights = getSupportedWeights(); + assert(vecWeights.size() > nValue); + return vecWeights[nValue]; +} + +int supportedWeightToArg(QFont::Weight weight) +{ + auto vecWeights = getSupportedWeights(); + for (int index = 0; index < vecWeights.size(); ++index) { + if (weight == vecWeights[index]) { + return index; + } + } + assert(false); } QString getActiveTheme() diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index e0a9533f1378..9e6e9b9ab930 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -337,7 +337,12 @@ namespace GUIUtil /** Get the default bold QFont */ QFont getFontBold(); - std::vector getSupportedWeights(FontFamily family); + /** Return supported weights for the current font family */ + std::vector getSupportedWeights(); + /** Map arg/setting values to supported weights */ + QFont::Weight supportedWeightFromArg(int nValue); + /** Map supported weights to arg/setting values */ + int supportedWeightToArg(QFont::Weight weight); /** Return the name of the currently active theme.*/ QString getActiveTheme(); From c4c8583c7ec242766cfe398cc09602fca18002ef Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 21 Jul 2020 00:35:08 +0200 Subject: [PATCH 11/14] qt: Default weights based on supported if not all weights are supported For SystemDefault only because Montserrat has all supported weights. --- src/qt/guiutil.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index ca81850cfc2c..31ee49be94c5 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -269,6 +269,13 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent) void setupAppearance(QWidget* parent, OptionsModel* model) { if (!QSettings().value("fAppearanceSetupDone", false).toBool()) { + // First make sure SystemDefault has reasonable default values if it does not support the full range of weights. + if (fontFamily == FontFamily::SystemDefault && getSupportedWeights().size() < 4) { + fontWeightNormal = mapSupportedWeights[FontFamily::SystemDefault].front(); + fontWeightBold = mapSupportedWeights[FontFamily::SystemDefault].back(); + QSettings().setValue("fontWeightNormal", supportedWeightToArg(fontWeightNormal)); + QSettings().setValue("fontWeightBold", supportedWeightToArg(fontWeightBold)); + } // Create the dialog QDialog dlg(parent); dlg.setObjectName("AppearanceSetup"); From ba5269e5887d1161305c2dd982ab97f343be2f29 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 21 Jul 2020 01:15:34 +0200 Subject: [PATCH 12/14] qt/test: Fix GUI tests --- src/qt/test/wallettests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index 693e1f051f49..bb1a4d1895b4 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -110,6 +110,7 @@ QModelIndex FindTx(const QAbstractItemModel& model, const uint256& txid) // src/qt/test/test_dash-qt -platform cocoa # macOS void TestGUI() { + GUIUtil::loadFonts(); // Set up wallet and chain with 105 blocks (5 mature blocks for spending). TestChain100Setup test; for (int i = 0; i < 5; ++i) { From 8f176d24a36f933758d23112717b3a05d9e28208 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 21 Jul 2020 13:21:00 +0300 Subject: [PATCH 13/14] Store normal/bold font GUI settings as "pure" (not "supported") values --- src/qt/guiutil.cpp | 4 ++-- src/qt/optionsmodel.cpp | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 31ee49be94c5..3bbf94033b9a 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -273,8 +273,8 @@ void setupAppearance(QWidget* parent, OptionsModel* model) if (fontFamily == FontFamily::SystemDefault && getSupportedWeights().size() < 4) { fontWeightNormal = mapSupportedWeights[FontFamily::SystemDefault].front(); fontWeightBold = mapSupportedWeights[FontFamily::SystemDefault].back(); - QSettings().setValue("fontWeightNormal", supportedWeightToArg(fontWeightNormal)); - QSettings().setValue("fontWeightBold", supportedWeightToArg(fontWeightBold)); + QSettings().setValue("fontWeightNormal", weightToArg(fontWeightNormal)); + QSettings().setValue("fontWeightBold", weightToArg(fontWeightBold)); } // Create the dialog QDialog dlg(parent); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 49b0ab74f5d0..7e93c7fbee52 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -360,10 +360,16 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return settings.value("fontFamily"); case FontScale: return settings.value("fontScale"); - case FontWeightNormal: - return settings.value("fontWeightNormal"); - case FontWeightBold: - return settings.value("fontWeightBold"); + case FontWeightNormal: { + QFont::Weight weight; + GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight); + return GUIUtil::supportedWeightToArg(weight); + } + case FontWeightBold: { + QFont::Weight weight; + GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight); + return GUIUtil::supportedWeightToArg(weight); + } case Language: return settings.value("language"); #ifdef ENABLE_WALLET @@ -550,16 +556,20 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in settings.setValue("fontScale", value); } break; - case FontWeightNormal: - if (settings.value("fontWeightNormal") != value) { - settings.setValue("fontWeightNormal", value); + case FontWeightNormal: { + int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromArg(value.toInt())); + if (settings.value("fontWeightNormal") != nWeight) { + settings.setValue("fontWeightNormal", nWeight); } break; - case FontWeightBold: - if (settings.value("fontWeightBold") != value) { - settings.setValue("fontWeightBold", value); + } + case FontWeightBold: { + int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromArg(value.toInt())); + if (settings.value("fontWeightBold") != nWeight) { + settings.setValue("fontWeightBold", nWeight); } break; + } case Language: if (settings.value("language") != value) { settings.setValue("language", value); From 5478f7c66d726988b4f9abbe5374a5c715ca02c8 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 21 Jul 2020 13:32:23 +0300 Subject: [PATCH 14/14] Rename supportedWeighti(To/From)Arg to supportedWeight(To/From)Index to better match the logic and avoid confusion with weight(To/From)Arg functions --- src/qt/appearancewidget.cpp | 4 ++-- src/qt/guiutil.cpp | 8 ++++---- src/qt/guiutil.h | 8 ++++---- src/qt/optionsmodel.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/qt/appearancewidget.cpp b/src/qt/appearancewidget.cpp index 9c0747e72790..59c3e782b869 100644 --- a/src/qt/appearancewidget.cpp +++ b/src/qt/appearancewidget.cpp @@ -125,7 +125,7 @@ void AppearanceWidget::updateFontWeightNormal(int nValue, bool fForce) } const QSignalBlocker blocker(ui->fontWeightNormalSlider); ui->fontWeightNormalSlider->setValue(nSliderValue); - GUIUtil::setFontWeightNormal(GUIUtil::supportedWeightFromArg(ui->fontWeightNormalSlider->value())); + GUIUtil::setFontWeightNormal(GUIUtil::supportedWeightFromIndex(ui->fontWeightNormalSlider->value())); } void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce) @@ -136,7 +136,7 @@ void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce) } const QSignalBlocker blocker(ui->fontWeightBoldSlider); ui->fontWeightBoldSlider->setValue(nSliderValue); - GUIUtil::setFontWeightBold(GUIUtil::supportedWeightFromArg(ui->fontWeightBoldSlider->value())); + GUIUtil::setFontWeightBold(GUIUtil::supportedWeightFromIndex(ui->fontWeightBoldSlider->value())); } void AppearanceWidget::updateWeightSlider() diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 3bbf94033b9a..409687b45ac1 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1630,14 +1630,14 @@ std::vector getSupportedWeights() return mapSupportedWeights[fontFamily]; } -QFont::Weight supportedWeightFromArg(int nValue) +QFont::Weight supportedWeightFromIndex(int nIndex) { auto vecWeights = getSupportedWeights(); - assert(vecWeights.size() > nValue); - return vecWeights[nValue]; + assert(vecWeights.size() > nIndex); + return vecWeights[nIndex]; } -int supportedWeightToArg(QFont::Weight weight) +int supportedWeightToIndex(QFont::Weight weight) { auto vecWeights = getSupportedWeights(); for (int index = 0; index < vecWeights.size(); ++index) { diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 9e6e9b9ab930..a21d317ff76a 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -339,10 +339,10 @@ namespace GUIUtil /** Return supported weights for the current font family */ std::vector getSupportedWeights(); - /** Map arg/setting values to supported weights */ - QFont::Weight supportedWeightFromArg(int nValue); - /** Map supported weights to arg/setting values */ - int supportedWeightToArg(QFont::Weight weight); + /** Convert an index to a weight in the supported weights vector */ + QFont::Weight supportedWeightFromIndex(int nIndex); + /** Convert a weight to an index in the supported weights vector */ + int supportedWeightToIndex(QFont::Weight weight); /** Return the name of the currently active theme.*/ QString getActiveTheme(); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 7e93c7fbee52..30afa567235b 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -363,12 +363,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const case FontWeightNormal: { QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight); - return GUIUtil::supportedWeightToArg(weight); + return GUIUtil::supportedWeightToIndex(weight); } case FontWeightBold: { QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight); - return GUIUtil::supportedWeightToArg(weight); + return GUIUtil::supportedWeightToIndex(weight); } case Language: return settings.value("language"); @@ -557,14 +557,14 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in } break; case FontWeightNormal: { - int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromArg(value.toInt())); + int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromIndex(value.toInt())); if (settings.value("fontWeightNormal") != nWeight) { settings.setValue("fontWeightNormal", nWeight); } break; } case FontWeightBold: { - int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromArg(value.toInt())); + int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromIndex(value.toInt())); if (settings.value("fontWeightBold") != nWeight) { settings.setValue("fontWeightBold", nWeight); }