qt: Fix default font weight values if selected values aren't supported by the font (#3849)

* qt: Fix default value if not supported values are selected

* qt: Fix comment

* qt: Fix logic of supported weight check

* qt: Inline std::find check

* qt: Rename vecSupportedWeights -> vecWeights
This commit is contained in:
dustinface 2020-12-09 23:25:29 +01:00 committed by GitHub
parent eebd50332d
commit b80ef47ead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,13 +302,23 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent)
void setupAppearance(QWidget* parent, OptionsModel* model) void setupAppearance(QWidget* parent, OptionsModel* model)
{ {
if (!QSettings().value("fAppearanceSetupDone", false).toBool()) { if (!QSettings().value("fAppearanceSetupDone", false).toBool()) {
// First make sure SystemDefault has reasonable default values if it does not support the full range of weights. std::vector<QFont::Weight> vecWeights = getSupportedWeights();
if (fontFamily == FontFamily::SystemDefault && getSupportedWeights().size() < 4) { // See if the default value for normal weight is available
fontWeightNormal = mapSupportedWeights[FontFamily::SystemDefault].front(); if (std::find(vecWeights.begin(), vecWeights.end(), defaultFontWeightNormal) == vecWeights.end()) {
fontWeightBold = mapSupportedWeights[FontFamily::SystemDefault].back(); // If not, use the lightest available weight as normal weight
fontWeightNormal = vecWeights.front();
}
// See if the default value for bold weight is available
if (std::find(vecWeights.begin(), vecWeights.end(), defaultFontWeightBold) == vecWeights.end()) {
// If not, use the second lightest available weight as bold weight default or also the lightest if there is only one
int nBoldOffset = vecWeights.size() > 1 ? 1 : 0;
fontWeightBold = vecWeights[nBoldOffset];
}
QSettings().setValue("fontWeightNormal", weightToArg(fontWeightNormal)); QSettings().setValue("fontWeightNormal", weightToArg(fontWeightNormal));
QSettings().setValue("fontWeightBold", weightToArg(fontWeightBold)); QSettings().setValue("fontWeightBold", weightToArg(fontWeightBold));
}
// Create the dialog // Create the dialog
QDialog dlg(parent); QDialog dlg(parent);
dlg.setObjectName("AppearanceSetup"); dlg.setObjectName("AppearanceSetup");