Add User Font Setting

User can now select a font from the installed fonts on their system

This font currently will only be applied when nheko is restarted
(similar to how font size and scaling currently work).  This will
be addressed in a future commit.  Additionally, the dropdown
does not correctly select the previously-chosen user font, and
instead defaults to the first font available on the system
(alphabetically).  This is similar to the issue with the 'Theme'
combo defaulting to 'Light' even when another theme is selected.
remotes/origin/HEAD
redsky17 6 years ago
parent 50e382f554
commit 654b652db4
  1. 29
      src/UserSettingsPage.cpp
  2. 4
      src/UserSettingsPage.h
  3. 4
      src/main.cpp

@ -49,7 +49,7 @@ UserSettings::load()
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
theme_ = settings.value("user/theme", "light").toString();
font_ = settings.value("user/font_family", "default").toString();
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
applyTheme();
@ -62,6 +62,13 @@ UserSettings::setFontSize(double size)
save();
}
void
UserSettings::setFontFamily(QString family)
{
font_ = family;
save();
}
void
UserSettings::setTheme(QString theme)
{
@ -106,6 +113,7 @@ UserSettings::save()
settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("desktop_notifications", hasDesktopNotifications_);
settings.setValue("theme", theme());
settings.setValue("font_family", font_);
settings.endGroup();
}
@ -220,6 +228,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
fontSizeOptionLayout->addWidget(fontSizeLabel);
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
auto fontFamilyOptionLayout = new QHBoxLayout;
fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto fontFamilyLabel = new QLabel(tr("Font Family"), this);
fontFamilyLabel->setFont(font);
fontSelectionCombo_ = new QComboBox(this);
QFontDatabase fontDb;
auto fontFamilies = fontDb.families();
for (const auto &family : fontFamilies) {
fontSelectionCombo_->addItem(family);
}
fontFamilyOptionLayout->addWidget(fontFamilyLabel);
fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight);
auto themeOptionLayout_ = new QHBoxLayout;
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto themeLabel_ = new QLabel(tr("Theme"), this);
@ -319,6 +341,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addLayout(scaleFactorOptionLayout);
mainLayout_->addLayout(fontSizeOptionLayout);
mainLayout_->addLayout(fontFamilyOptionLayout);
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(themeOptionLayout_);
mainLayout_->addWidget(new HorizontalLine(this));
@ -355,7 +378,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
connect(fontSizeCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
[this](const QString &size) { settings_->setFontSize(size.trimmed().toDouble()); });
connect(fontSelectionCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
[this](const QString &family) { settings_->setFontFamily(family.trimmed()); });
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setTray(!isDisabled);
if (isDisabled) {

@ -18,6 +18,7 @@
#pragma once
#include <QComboBox>
#include <QFontDatabase>
#include <QFrame>
#include <QLabel>
#include <QLayout>
@ -54,6 +55,7 @@ public:
}
void setFontSize(double size);
void setFontFamily(QString family);
void setGroupView(bool state)
{
@ -103,6 +105,7 @@ private:
bool isReadReceiptsEnabled_;
bool hasDesktopNotifications_;
double baseFontSize_;
QString font_;
};
class HorizontalLine : public QFrame
@ -154,6 +157,7 @@ private:
QComboBox *themeCombo_;
QComboBox *scaleFactorCombo_;
QComboBox *fontSizeCombo_;
QComboBox *fontSelectionCombo_;
int sideMargin_ = 0;
};

@ -147,6 +147,10 @@ main(int argc, char *argv[])
QSettings settings;
QFont font;
QString userFontFamily = settings.value("user/font_family", "").toString();
if (!userFontFamily.isEmpty()) {
font.setFamily(userFontFamily);
}
font.setPointSizeF(settings.value("user/font_size", font.pointSizeF()).toDouble());
app.setFont(font);

Loading…
Cancel
Save