mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
parent
4b1b062388
commit
3a57d1018e
6 changed files with 68 additions and 56 deletions
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <QTimer>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Config.h"
|
||||
#include "MainWindow.h"
|
||||
#include "UserInfoWidget.h"
|
||||
|
@ -28,26 +30,31 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
|
|||
: QWidget(parent)
|
||||
, display_name_("User")
|
||||
, user_id_("@user:homeserver.org")
|
||||
, logoutButtonSize_{20}
|
||||
{
|
||||
setFixedHeight(56);
|
||||
const int fontHeight = QFontMetrics(font()).height();
|
||||
const int widgetMargin = fontHeight / 3;
|
||||
const int contentHeight = fontHeight * 3;
|
||||
|
||||
logoutButtonSize_ = fontHeight + (fontHeight / 4);
|
||||
|
||||
setFixedHeight(contentHeight + widgetMargin * 2);
|
||||
|
||||
topLayout_ = new QHBoxLayout(this);
|
||||
topLayout_->setSpacing(0);
|
||||
topLayout_->setMargin(5);
|
||||
topLayout_->setMargin(widgetMargin);
|
||||
|
||||
avatarLayout_ = new QHBoxLayout();
|
||||
textLayout_ = new QVBoxLayout();
|
||||
textLayout_->setSpacing(2);
|
||||
textLayout_->setContentsMargins(10, 5, 10, 5);
|
||||
textLayout_->setSpacing(0);
|
||||
textLayout_->setContentsMargins(
|
||||
widgetMargin * 2, widgetMargin, widgetMargin * 2, widgetMargin);
|
||||
|
||||
userAvatar_ = new Avatar(this);
|
||||
userAvatar_->setObjectName("userAvatar");
|
||||
userAvatar_->setLetter(QChar('?'));
|
||||
userAvatar_->setSize(45);
|
||||
userAvatar_->setSize(fontHeight * 2.5);
|
||||
|
||||
QFont nameFont;
|
||||
nameFont.setPointSizeF(nameFont.pointSizeF() * 1.2);
|
||||
nameFont.setWeight(QFont::Medium);
|
||||
|
||||
displayNameLabel_ = new QLabel(this);
|
||||
|
|
|
@ -51,6 +51,8 @@ UserSettings::load()
|
|||
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
||||
theme_ = settings.value("user/theme", "light").toString();
|
||||
|
||||
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
||||
|
||||
applyTheme();
|
||||
}
|
||||
|
||||
|
@ -92,6 +94,7 @@ UserSettings::save()
|
|||
settings.setValue("start_in_tray", isStartInTrayEnabled_);
|
||||
settings.endGroup();
|
||||
|
||||
settings.setValue("font_size", baseFontSize_);
|
||||
settings.setValue("room_ordering", isOrderingEnabled_);
|
||||
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
|
||||
settings.setValue("read_receipts", isReadReceiptsEnabled_);
|
||||
|
@ -214,8 +217,16 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
scaleFactorCombo_->addItem("2.75");
|
||||
scaleFactorCombo_->addItem("3");
|
||||
|
||||
scaleFactorOptionLayout->addWidget(scaleFactorLabel);
|
||||
scaleFactorOptionLayout->addWidget(scaleFactorCombo_, 0, Qt::AlignRight);
|
||||
auto fontSizeOptionLayout = new QHBoxLayout;
|
||||
fontSizeOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||
auto fontSizeLabel = new QLabel(tr("Font size"), this);
|
||||
fontSizeLabel->setFont(font);
|
||||
fontSizeCombo_ = new QComboBox(this);
|
||||
for (double option = 10; option < 17; option += 0.5)
|
||||
fontSizeCombo_->addItem(QString("%1 ").arg(QString::number(option)));
|
||||
|
||||
fontSizeOptionLayout->addWidget(fontSizeLabel);
|
||||
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
||||
|
||||
auto themeOptionLayout_ = new QHBoxLayout;
|
||||
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||
|
@ -316,9 +327,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
scaleFactorCombo_->hide();
|
||||
#else
|
||||
mainLayout_->addLayout(scaleFactorOptionLayout);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
#endif
|
||||
|
||||
mainLayout_->addLayout(fontSizeOptionLayout);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addLayout(themeOptionLayout_);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
|
||||
|
@ -351,6 +363,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
connect(scaleFactorCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||
[](const QString &factor) { utils::setScaleFactor(factor.toFloat()); });
|
||||
connect(fontSizeCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||
[this](const QString &size) { settings_->setFontSize(size.trimmed().toDouble()); });
|
||||
|
||||
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setTray(!isDisabled);
|
||||
|
@ -395,8 +410,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
void
|
||||
UserSettingsPage::showEvent(QShowEvent *)
|
||||
{
|
||||
restoreThemeCombo();
|
||||
restoreScaleFactor();
|
||||
// FIXME macOS doesn't show the full option unless a space is added.
|
||||
utils::restoreCombobox(fontSizeCombo_, QString::number(settings_->fontSize()) + " ");
|
||||
utils::restoreCombobox(scaleFactorCombo_, QString::number(utils::scaleFactor()));
|
||||
utils::restoreCombobox(themeCombo_, settings_->theme());
|
||||
|
||||
// FIXME: Toggle treats true as "off"
|
||||
trayToggle_->setState(!settings_->isTrayEnabled());
|
||||
|
@ -431,44 +448,6 @@ UserSettingsPage::paintEvent(QPaintEvent *)
|
|||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
}
|
||||
|
||||
void
|
||||
UserSettingsPage::restoreScaleFactor() const
|
||||
{
|
||||
auto factor = utils::scaleFactor();
|
||||
|
||||
if (factor == 1)
|
||||
scaleFactorCombo_->setCurrentIndex(0);
|
||||
else if (factor == 1.25)
|
||||
scaleFactorCombo_->setCurrentIndex(1);
|
||||
else if (factor == 1.5)
|
||||
scaleFactorCombo_->setCurrentIndex(2);
|
||||
else if (factor == 1.75)
|
||||
scaleFactorCombo_->setCurrentIndex(3);
|
||||
else if (factor == 2)
|
||||
scaleFactorCombo_->setCurrentIndex(4);
|
||||
else if (factor == 2.25)
|
||||
scaleFactorCombo_->setCurrentIndex(5);
|
||||
else if (factor == 2.5)
|
||||
scaleFactorCombo_->setCurrentIndex(6);
|
||||
else if (factor == 2.75)
|
||||
scaleFactorCombo_->setCurrentIndex(7);
|
||||
else if (factor == 3)
|
||||
scaleFactorCombo_->setCurrentIndex(7);
|
||||
else
|
||||
scaleFactorCombo_->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void
|
||||
UserSettingsPage::restoreThemeCombo() const
|
||||
{
|
||||
if (settings_->theme() == "light")
|
||||
themeCombo_->setCurrentIndex(0);
|
||||
else if (settings_->theme() == "dark")
|
||||
themeCombo_->setCurrentIndex(1);
|
||||
else
|
||||
themeCombo_->setCurrentIndex(2);
|
||||
}
|
||||
|
||||
void
|
||||
UserSettingsPage::importSessionKeys()
|
||||
{
|
||||
|
|
|
@ -53,6 +53,12 @@ public:
|
|||
save();
|
||||
}
|
||||
|
||||
void setFontSize(double size)
|
||||
{
|
||||
baseFontSize_ = size;
|
||||
save();
|
||||
}
|
||||
|
||||
void setRoomOrdering(bool state)
|
||||
{
|
||||
isOrderingEnabled_ = state;
|
||||
|
@ -94,6 +100,7 @@ public:
|
|||
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
|
||||
bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; }
|
||||
bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
|
||||
double fontSize() const { return baseFontSize_; }
|
||||
|
||||
signals:
|
||||
void groupViewStateChanged(bool state);
|
||||
|
@ -107,6 +114,7 @@ private:
|
|||
bool isTypingNotificationsEnabled_;
|
||||
bool isReadReceiptsEnabled_;
|
||||
bool hasDesktopNotifications_;
|
||||
double baseFontSize_;
|
||||
};
|
||||
|
||||
class HorizontalLine : public QFrame
|
||||
|
@ -138,9 +146,6 @@ private slots:
|
|||
void exportSessionKeys();
|
||||
|
||||
private:
|
||||
void restoreThemeCombo() const;
|
||||
void restoreScaleFactor() const;
|
||||
|
||||
// Layouts
|
||||
QVBoxLayout *topLayout_;
|
||||
QVBoxLayout *mainLayout_;
|
||||
|
@ -161,6 +166,7 @@ private:
|
|||
|
||||
QComboBox *themeCombo_;
|
||||
QComboBox *scaleFactorCombo_;
|
||||
QComboBox *fontSizeCombo_;
|
||||
|
||||
int sideMargin_ = 0;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Utils.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDesktopWidget>
|
||||
#include <QSettings>
|
||||
#include <QTextDocument>
|
||||
|
@ -400,3 +401,14 @@ utils::centerWidget(QWidget *widget, QWidget *parent)
|
|||
|
||||
widget->move(findCenter(QApplication::desktop()->screenGeometry()));
|
||||
}
|
||||
|
||||
void
|
||||
utils::restoreCombobox(QComboBox *combo, const QString &value)
|
||||
{
|
||||
for (auto i = 0; i < combo->count(); ++i) {
|
||||
if (value == combo->itemText(i)) {
|
||||
combo->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <mtx/events/collections.hpp>
|
||||
#include <mtx/events/common.hpp>
|
||||
|
||||
class QComboBox;
|
||||
|
||||
namespace utils {
|
||||
|
||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||
|
@ -228,4 +230,7 @@ linkColor();
|
|||
//! Center a widget in relation to another widget.
|
||||
void
|
||||
centerWidget(QWidget *widget, QWidget *parent);
|
||||
|
||||
void
|
||||
restoreCombobox(QComboBox *combo, const QString &value);
|
||||
}
|
||||
|
|
|
@ -150,7 +150,12 @@ main(int argc, char *argv[])
|
|||
std::exit(1);
|
||||
}
|
||||
|
||||
app.setFont(QFont("Open Sans"));
|
||||
QSettings settings;
|
||||
|
||||
QFont font("Open Sans");
|
||||
font.setPointSizeF(settings.value("user/font_size", font.pointSizeF()).toDouble());
|
||||
|
||||
app.setFont(font);
|
||||
|
||||
QString lang = QLocale::system().name();
|
||||
|
||||
|
@ -167,8 +172,6 @@ main(int argc, char *argv[])
|
|||
// Move the MainWindow to the center
|
||||
w.move(screenCenter(w.width(), w.height()));
|
||||
|
||||
QSettings settings;
|
||||
|
||||
if (!settings.value("user/window/start_in_tray", false).toBool() ||
|
||||
!settings.value("user/window/tray", true).toBool())
|
||||
w.show();
|
||||
|
|
Loading…
Reference in a new issue