Set font properly

When setting the default font, actually set the default font. When
setting a different font, change the application font.

fixes #801
fixes #232
fixes #224
This commit is contained in:
Nicolas Werner 2022-03-05 03:25:24 +01:00
parent 7238ca3765
commit c76cda0cbe
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -79,7 +79,9 @@ UserSettings::load(std::optional<QString> profile)
sortByImportance_ = settings.value(QStringLiteral("user/sort_by_unread"), true).toBool(); sortByImportance_ = settings.value(QStringLiteral("user/sort_by_unread"), true).toBool();
readReceipts_ = settings.value(QStringLiteral("user/read_receipts"), true).toBool(); readReceipts_ = settings.value(QStringLiteral("user/read_receipts"), true).toBool();
theme_ = settings.value(QStringLiteral("user/theme"), defaultTheme_).toString(); theme_ = settings.value(QStringLiteral("user/theme"), defaultTheme_).toString();
font_ = settings.value(QStringLiteral("user/font_family"), "default").toString();
font_ = settings.value(QStringLiteral("user/font_family"), "").toString();
avatarCircles_ = settings.value(QStringLiteral("user/avatar_circles"), true).toBool(); avatarCircles_ = settings.value(QStringLiteral("user/avatar_circles"), true).toBool();
useIdenticon_ = settings.value(QStringLiteral("user/use_identicon"), true).toBool(); useIdenticon_ = settings.value(QStringLiteral("user/use_identicon"), true).toBool();
decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool(); decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool();
@ -87,7 +89,7 @@ UserSettings::load(std::optional<QString> profile)
privacyScreenTimeout_ = privacyScreenTimeout_ =
settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt(); settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt();
mobileMode_ = settings.value(QStringLiteral("user/mobile_mode"), false).toBool(); mobileMode_ = settings.value(QStringLiteral("user/mobile_mode"), false).toBool();
emojiFont_ = settings.value(QStringLiteral("user/emoji_font_family"), "default").toString(); emojiFont_ = settings.value(QStringLiteral("user/emoji_font_family"), "emoji").toString();
baseFontSize_ = baseFontSize_ =
settings.value(QStringLiteral("user/font_size"), QFont().pointSizeF()).toDouble(); settings.value(QStringLiteral("user/font_size"), QFont().pointSizeF()).toDouble();
auto tempPresence = auto tempPresence =
@ -419,6 +421,12 @@ UserSettings::setFontSize(double size)
if (size == baseFontSize_) if (size == baseFontSize_)
return; return;
baseFontSize_ = size; baseFontSize_ = size;
const static auto defaultFamily = QFont().defaultFamily();
QFont f((font_.isEmpty() || font_ == QStringLiteral("default")) ? defaultFamily : font_);
f.setPointSizeF(fontSize());
QApplication::setFont(f);
emit fontSizeChanged(size); emit fontSizeChanged(size);
save(); save();
} }
@ -429,6 +437,12 @@ UserSettings::setFontFamily(QString family)
if (family == font_) if (family == font_)
return; return;
font_ = family; font_ = family;
const static auto defaultFamily = QFont().defaultFamily();
QFont f((family.isEmpty() || family == QStringLiteral("default")) ? defaultFamily : family);
f.setPointSizeF(fontSize());
QApplication::setFont(f);
emit fontChanged(family); emit fontChanged(family);
save(); save();
} }
@ -440,7 +454,7 @@ UserSettings::setEmojiFontFamily(QString family)
return; return;
if (family == tr("Default")) { if (family == tr("Default")) {
emojiFont_ = QStringLiteral("default"); emojiFont_ = QStringLiteral("emoji");
} else { } else {
emojiFont_ = family; emojiFont_ = family;
} }