mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
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.
This commit is contained in:
parent
50e382f554
commit
654b652db4
3 changed files with 35 additions and 2 deletions
|
@ -49,7 +49,7 @@ UserSettings::load()
|
||||||
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
||||||
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
||||||
theme_ = settings.value("user/theme", "light").toString();
|
theme_ = settings.value("user/theme", "light").toString();
|
||||||
|
font_ = settings.value("user/font_family", "default").toString();
|
||||||
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
@ -62,6 +62,13 @@ UserSettings::setFontSize(double size)
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserSettings::setFontFamily(QString family)
|
||||||
|
{
|
||||||
|
font_ = family;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserSettings::setTheme(QString theme)
|
UserSettings::setTheme(QString theme)
|
||||||
{
|
{
|
||||||
|
@ -106,6 +113,7 @@ UserSettings::save()
|
||||||
settings.setValue("group_view", isGroupViewEnabled_);
|
settings.setValue("group_view", isGroupViewEnabled_);
|
||||||
settings.setValue("desktop_notifications", hasDesktopNotifications_);
|
settings.setValue("desktop_notifications", hasDesktopNotifications_);
|
||||||
settings.setValue("theme", theme());
|
settings.setValue("theme", theme());
|
||||||
|
settings.setValue("font_family", font_);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +228,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
fontSizeOptionLayout->addWidget(fontSizeLabel);
|
fontSizeOptionLayout->addWidget(fontSizeLabel);
|
||||||
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
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;
|
auto themeOptionLayout_ = new QHBoxLayout;
|
||||||
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
||||||
|
@ -319,6 +341,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
|
|
||||||
mainLayout_->addLayout(scaleFactorOptionLayout);
|
mainLayout_->addLayout(scaleFactorOptionLayout);
|
||||||
mainLayout_->addLayout(fontSizeOptionLayout);
|
mainLayout_->addLayout(fontSizeOptionLayout);
|
||||||
|
mainLayout_->addLayout(fontFamilyOptionLayout);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(themeOptionLayout_);
|
mainLayout_->addLayout(themeOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
@ -355,7 +378,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
connect(fontSizeCombo_,
|
connect(fontSizeCombo_,
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
[this](const QString &size) { settings_->setFontSize(size.trimmed().toDouble()); });
|
[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) {
|
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||||
settings_->setTray(!isDisabled);
|
settings_->setTray(!isDisabled);
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QFontDatabase>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
|
@ -54,6 +55,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFontSize(double size);
|
void setFontSize(double size);
|
||||||
|
void setFontFamily(QString family);
|
||||||
|
|
||||||
void setGroupView(bool state)
|
void setGroupView(bool state)
|
||||||
{
|
{
|
||||||
|
@ -103,6 +105,7 @@ private:
|
||||||
bool isReadReceiptsEnabled_;
|
bool isReadReceiptsEnabled_;
|
||||||
bool hasDesktopNotifications_;
|
bool hasDesktopNotifications_;
|
||||||
double baseFontSize_;
|
double baseFontSize_;
|
||||||
|
QString font_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalLine : public QFrame
|
class HorizontalLine : public QFrame
|
||||||
|
@ -154,6 +157,7 @@ private:
|
||||||
QComboBox *themeCombo_;
|
QComboBox *themeCombo_;
|
||||||
QComboBox *scaleFactorCombo_;
|
QComboBox *scaleFactorCombo_;
|
||||||
QComboBox *fontSizeCombo_;
|
QComboBox *fontSizeCombo_;
|
||||||
|
QComboBox *fontSelectionCombo_;
|
||||||
|
|
||||||
int sideMargin_ = 0;
|
int sideMargin_ = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -147,6 +147,10 @@ main(int argc, char *argv[])
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
QFont font;
|
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());
|
font.setPointSizeF(settings.value("user/font_size", font.pointSizeF()).toDouble());
|
||||||
|
|
||||||
app.setFont(font);
|
app.setFont(font);
|
||||||
|
|
Loading…
Reference in a new issue