Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Add option to specify the scale factor
Browse files Browse the repository at this point in the history
fixes #357
fixes #335
fixes #230
  • Loading branch information
mujx committed Jul 22, 2018
1 parent 18695d6 commit 85e93a8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/CommunitiesList.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Cache.h"
#include "CommunitiesList.h"
#include "Cache.h"
#include "Logging.h"
#include "MatrixClient.h"

Expand Down
3 changes: 2 additions & 1 deletion src/LoginPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ LoginPage::onLoginButtonClicked()
http::client()->login(
user.localpart(),
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) {
if (err) {
emit loginError(QString::fromStdString(err->matrix_error.error));
Expand Down
59 changes: 59 additions & 0 deletions src/UserSettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "Config.h"
#include "UserSettingsPage.h"
#include "Utils.h"
#include "ui/FlatButton.h"
#include "ui/ToggleButton.h"

Expand Down Expand Up @@ -187,6 +188,24 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
receiptsLayout->addWidget(receiptsLabel);
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;
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto themeLabel_ = new QLabel(tr("Theme"), this);
Expand Down Expand Up @@ -219,6 +238,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addLayout(typingLayout);
mainLayout_->addLayout(receiptsLayout);
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_->addWidget(new HorizontalLine(this));

Expand All @@ -241,6 +269,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
connect(themeCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
[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) {
settings_->setTray(!isDisabled);
Expand Down Expand Up @@ -282,6 +313,7 @@ void
UserSettingsPage::showEvent(QShowEvent *)
{
restoreThemeCombo();
restoreScaleFactor();

// FIXME: Toggle treats true as "off"
trayToggle_->setState(!settings_->isTrayEnabled());
Expand Down Expand Up @@ -311,6 +343,33 @@ 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
{
Expand Down
2 changes: 2 additions & 0 deletions src/UserSettingsPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class UserSettingsPage : public QWidget

private:
void restoreThemeCombo() const;
void restoreScaleFactor() const;

// Layouts
QVBoxLayout *topLayout_;
Expand All @@ -143,6 +144,7 @@ class UserSettingsPage : public QWidget
Toggle *readReceipts_;

QComboBox *themeCombo_;
QComboBox *scaleFactorCombo_;

int sideMargin_ = 0;
};
17 changes: 17 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ utils::localUser()
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
utils::respondsToKeyRequests(const std::string &roomId)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ using TimelineEvent = mtx::events::collections::TimelineEvents;
QString
localUser();

float
scaleFactor();

void
setScaleFactor(float factor);

//! Whether or not we should respond to key requests for the given room.
bool
respondsToKeyRequests(const QString &roomId);
Expand Down
15 changes: 12 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QLibraryInfo>
#include <QPalette>
#include <QPoint>
#include <QProcessEnvironment>
#include <QPushButton>
#include <QSettings>
#include <QStandardPaths>
Expand All @@ -36,6 +37,7 @@
#include "MainWindow.h"
#include "MatrixClient.h"
#include "RunGuard.h"
#include "Utils.h"
#include "ui/RaisedButton.h"
#include "version.h"

Expand Down Expand Up @@ -98,7 +100,6 @@ main(int argc, char *argv[])
QApplication a(argc, argv);

QFont font;
font.setPointSize(15);
font.setWeight(60);

QWidget widget;
Expand All @@ -117,7 +118,6 @@ main(int argc, char *argv[])
RaisedButton submitBtn("OK");
submitBtn.setBackgroundColor(pal.color(QPalette::Button));
submitBtn.setForegroundColor(pal.color(QPalette::ButtonText));
submitBtn.setMinimumSize(120, 35);
submitBtn.setFontSize(conf::btn::fontSize);
submitBtn.setCornerRadius(conf::btn::cornerRadius);

Expand All @@ -127,7 +127,7 @@ main(int argc, char *argv[])
layout.addWidget(&msg);
layout.addLayout(&btnLayout);

widget.setFixedSize(480, 180);
widget.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
widget.move(screenCenter(widget.width(), widget.height()));
widget.show();

Expand All @@ -136,6 +136,15 @@ main(int argc, char *argv[])
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);
QCoreApplication::setApplicationName("nheko");
QCoreApplication::setApplicationVersion(nheko::version);
Expand Down

0 comments on commit 85e93a8

Please sign in to comment.