mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Add option to specify the scale factor
fixes #357 fixes #335 fixes #230
This commit is contained in:
parent
18695d636d
commit
85e93a88a6
7 changed files with 99 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
#include "Cache.h"
|
|
||||||
#include "CommunitiesList.h"
|
#include "CommunitiesList.h"
|
||||||
|
#include "Cache.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,8 @@ LoginPage::onLoginButtonClicked()
|
||||||
http::client()->login(
|
http::client()->login(
|
||||||
user.localpart(),
|
user.localpart(),
|
||||||
password_input_->text().toStdString(),
|
password_input_->text().toStdString(),
|
||||||
deviceName_->text().isEmpty() ? initialDeviceName() : deviceName_->text().toStdString(),
|
deviceName_->text().trimmed().isEmpty() ? initialDeviceName()
|
||||||
|
: deviceName_->text().toStdString(),
|
||||||
[this](const mtx::responses::Login &res, mtx::http::RequestErr err) {
|
[this](const mtx::responses::Login &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
emit loginError(QString::fromStdString(err->matrix_error.error));
|
emit loginError(QString::fromStdString(err->matrix_error.error));
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "ui/FlatButton.h"
|
#include "ui/FlatButton.h"
|
||||||
#include "ui/ToggleButton.h"
|
#include "ui/ToggleButton.h"
|
||||||
|
|
||||||
|
@ -187,6 +188,24 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
receiptsLayout->addWidget(receiptsLabel);
|
receiptsLayout->addWidget(receiptsLabel);
|
||||||
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignBottom | Qt::AlignRight);
|
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
|
auto scaleFactorOptionLayout = new QHBoxLayout;
|
||||||
|
scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
|
auto scaleFactorLabel = new QLabel(tr("Scale factor (requires restart)"), this);
|
||||||
|
scaleFactorLabel->setFont(font);
|
||||||
|
scaleFactorCombo_ = new QComboBox(this);
|
||||||
|
scaleFactorCombo_->addItem("1");
|
||||||
|
scaleFactorCombo_->addItem("1.25");
|
||||||
|
scaleFactorCombo_->addItem("1.5");
|
||||||
|
scaleFactorCombo_->addItem("1.75");
|
||||||
|
scaleFactorCombo_->addItem("2");
|
||||||
|
scaleFactorCombo_->addItem("2.25");
|
||||||
|
scaleFactorCombo_->addItem("2.5");
|
||||||
|
scaleFactorCombo_->addItem("2.75");
|
||||||
|
scaleFactorCombo_->addItem("3");
|
||||||
|
|
||||||
|
scaleFactorOptionLayout->addWidget(scaleFactorLabel);
|
||||||
|
scaleFactorOptionLayout->addWidget(scaleFactorCombo_, 0, Qt::AlignBottom | 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);
|
||||||
|
@ -219,6 +238,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
mainLayout_->addLayout(typingLayout);
|
mainLayout_->addLayout(typingLayout);
|
||||||
mainLayout_->addLayout(receiptsLayout);
|
mainLayout_->addLayout(receiptsLayout);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
scaleFactorLabel->hide();
|
||||||
|
scaleFactorCombo_->hide();
|
||||||
|
#else
|
||||||
|
mainLayout_->addLayout(scaleFactorOptionLayout);
|
||||||
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
#endif
|
||||||
|
|
||||||
mainLayout_->addLayout(themeOptionLayout_);
|
mainLayout_->addLayout(themeOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
|
||||||
|
@ -241,6 +269,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
connect(themeCombo_,
|
connect(themeCombo_,
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
[this](const QString &text) { settings_->setTheme(text.toLower()); });
|
[this](const QString &text) { settings_->setTheme(text.toLower()); });
|
||||||
|
connect(scaleFactorCombo_,
|
||||||
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
|
[this](const QString &factor) { utils::setScaleFactor(factor.toFloat()); });
|
||||||
|
|
||||||
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||||
settings_->setTray(!isDisabled);
|
settings_->setTray(!isDisabled);
|
||||||
|
@ -282,6 +313,7 @@ void
|
||||||
UserSettingsPage::showEvent(QShowEvent *)
|
UserSettingsPage::showEvent(QShowEvent *)
|
||||||
{
|
{
|
||||||
restoreThemeCombo();
|
restoreThemeCombo();
|
||||||
|
restoreScaleFactor();
|
||||||
|
|
||||||
// FIXME: Toggle treats true as "off"
|
// FIXME: Toggle treats true as "off"
|
||||||
trayToggle_->setState(!settings_->isTrayEnabled());
|
trayToggle_->setState(!settings_->isTrayEnabled());
|
||||||
|
@ -311,6 +343,33 @@ UserSettingsPage::paintEvent(QPaintEvent *)
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
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
|
void
|
||||||
UserSettingsPage::restoreThemeCombo() const
|
UserSettingsPage::restoreThemeCombo() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -126,6 +126,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void restoreThemeCombo() const;
|
void restoreThemeCombo() const;
|
||||||
|
void restoreScaleFactor() const;
|
||||||
|
|
||||||
// Layouts
|
// Layouts
|
||||||
QVBoxLayout *topLayout_;
|
QVBoxLayout *topLayout_;
|
||||||
|
@ -143,6 +144,7 @@ private:
|
||||||
Toggle *readReceipts_;
|
Toggle *readReceipts_;
|
||||||
|
|
||||||
QComboBox *themeCombo_;
|
QComboBox *themeCombo_;
|
||||||
|
QComboBox *scaleFactorCombo_;
|
||||||
|
|
||||||
int sideMargin_ = 0;
|
int sideMargin_ = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,23 @@ utils::localUser()
|
||||||
return settings.value("auth/user_id").toString();
|
return settings.value("auth/user_id").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
utils::setScaleFactor(float factor)
|
||||||
|
{
|
||||||
|
if (factor < 1 || factor > 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
settings.setValue("settings/scale_factor", factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
utils::scaleFactor()
|
||||||
|
{
|
||||||
|
QSettings settings("nheko", "nheko");
|
||||||
|
return settings.value("settings/scale_factor", -1).toFloat();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
utils::respondsToKeyRequests(const std::string &roomId)
|
utils::respondsToKeyRequests(const std::string &roomId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,12 @@ using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||||
QString
|
QString
|
||||||
localUser();
|
localUser();
|
||||||
|
|
||||||
|
float
|
||||||
|
scaleFactor();
|
||||||
|
|
||||||
|
void
|
||||||
|
setScaleFactor(float factor);
|
||||||
|
|
||||||
//! Whether or not we should respond to key requests for the given room.
|
//! Whether or not we should respond to key requests for the given room.
|
||||||
bool
|
bool
|
||||||
respondsToKeyRequests(const QString &roomId);
|
respondsToKeyRequests(const QString &roomId);
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -26,6 +26,7 @@
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "RunGuard.h"
|
#include "RunGuard.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "ui/RaisedButton.h"
|
#include "ui/RaisedButton.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
@ -98,7 +100,6 @@ main(int argc, char *argv[])
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPointSize(15);
|
|
||||||
font.setWeight(60);
|
font.setWeight(60);
|
||||||
|
|
||||||
QWidget widget;
|
QWidget widget;
|
||||||
|
@ -117,7 +118,6 @@ main(int argc, char *argv[])
|
||||||
RaisedButton submitBtn("OK");
|
RaisedButton submitBtn("OK");
|
||||||
submitBtn.setBackgroundColor(pal.color(QPalette::Button));
|
submitBtn.setBackgroundColor(pal.color(QPalette::Button));
|
||||||
submitBtn.setForegroundColor(pal.color(QPalette::ButtonText));
|
submitBtn.setForegroundColor(pal.color(QPalette::ButtonText));
|
||||||
submitBtn.setMinimumSize(120, 35);
|
|
||||||
submitBtn.setFontSize(conf::btn::fontSize);
|
submitBtn.setFontSize(conf::btn::fontSize);
|
||||||
submitBtn.setCornerRadius(conf::btn::cornerRadius);
|
submitBtn.setCornerRadius(conf::btn::cornerRadius);
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ main(int argc, char *argv[])
|
||||||
layout.addWidget(&msg);
|
layout.addWidget(&msg);
|
||||||
layout.addLayout(&btnLayout);
|
layout.addLayout(&btnLayout);
|
||||||
|
|
||||||
widget.setFixedSize(480, 180);
|
widget.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||||
widget.move(screenCenter(widget.width(), widget.height()));
|
widget.move(screenCenter(widget.width(), widget.height()));
|
||||||
widget.show();
|
widget.show();
|
||||||
|
|
||||||
|
@ -136,6 +136,15 @@ main(int argc, char *argv[])
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||||
|
if (qgetenv("QT_SCALE_FACTOR").size() == 0) {
|
||||||
|
float factor = utils::scaleFactor();
|
||||||
|
|
||||||
|
if (factor != -1)
|
||||||
|
qputenv("QT_SCALE_FACTOR", QString::number(factor).toUtf8());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QCoreApplication::setApplicationName("nheko");
|
QCoreApplication::setApplicationName("nheko");
|
||||||
QCoreApplication::setApplicationVersion(nheko::version);
|
QCoreApplication::setApplicationVersion(nheko::version);
|
||||||
|
|
Loading…
Reference in a new issue