2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "settings/settings_scale_widget.h"
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
#include "styles/style_settings.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
#include "lang.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "localstorage.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "boxes/confirmbox.h"
|
|
|
|
#include "application.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "ui/widgets/discrete_sliders.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
2016-08-22 17:16:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString scaleLabel(DBIScale scale) {
|
|
|
|
switch (scale) {
|
|
|
|
case dbisOne: return qsl("100%");
|
|
|
|
case dbisOneAndQuarter: return qsl("125%");
|
|
|
|
case dbisOneAndHalf: return qsl("150%");
|
|
|
|
case dbisTwo: return qsl("200%");
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
ScaleWidget::ScaleWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_scale)) {
|
2016-08-22 17:16:21 +00:00
|
|
|
createControls();
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void ScaleWidget::createControls() {
|
|
|
|
style::margins margin(0, 0, 0, st::settingsSmallSkip);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
addChildRow(_auto, margin, lng_settings_scale_auto(lt_cur, scaleLabel(cScreenScale())), SLOT(onAutoChanged()), (cConfigScale() == dbisAuto));
|
2016-08-22 17:16:21 +00:00
|
|
|
addChildRow(_scale, style::margins(0, 0, 0, 0));
|
|
|
|
|
|
|
|
_scale->addSection(scaleLabel(dbisOne));
|
|
|
|
_scale->addSection(scaleLabel(dbisOneAndQuarter));
|
|
|
|
_scale->addSection(scaleLabel(dbisOneAndHalf));
|
|
|
|
_scale->addSection(scaleLabel(dbisTwo));
|
|
|
|
_scale->setActiveSectionFast(cEvalScale(cConfigScale()) - 1);
|
2016-10-06 16:41:09 +00:00
|
|
|
_scale->setSectionActivatedCallback([this] { scaleChanged(); });
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void ScaleWidget::onAutoChanged() {
|
2016-08-22 17:16:21 +00:00
|
|
|
auto newScale = _auto->checked() ? dbisAuto : cEvalScale(cConfigScale());
|
|
|
|
if (newScale == cScreenScale()) {
|
|
|
|
if (newScale != cScale()) {
|
|
|
|
newScale = cScale();
|
|
|
|
} else {
|
|
|
|
switch (newScale) {
|
|
|
|
case dbisOne: newScale = dbisOneAndQuarter; break;
|
|
|
|
case dbisOneAndQuarter: newScale = dbisOne; break;
|
|
|
|
case dbisOneAndHalf: newScale = dbisOneAndQuarter; break;
|
|
|
|
case dbisTwo: newScale = dbisOneAndHalf; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setScale(newScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScaleWidget::setScale(DBIScale newScale) {
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_inSetScale) return;
|
|
|
|
_inSetScale = true;
|
|
|
|
auto guard = base::scope_guard([this] { _inSetScale = false; });
|
|
|
|
|
|
|
|
if (newScale == cScreenScale()) newScale = dbisAuto;
|
2016-08-22 17:16:21 +00:00
|
|
|
if (newScale == dbisAuto && !_auto->checked()) {
|
|
|
|
_auto->setChecked(true);
|
|
|
|
} else if (newScale != dbisAuto && _auto->checked()) {
|
|
|
|
_auto->setChecked(false);
|
|
|
|
}
|
2016-11-10 18:10:31 +00:00
|
|
|
_newScale = newScale;
|
2016-08-22 17:16:21 +00:00
|
|
|
if (newScale == dbisAuto) newScale = cScreenScale();
|
|
|
|
if (_scale->activeSection() != newScale - 1) {
|
|
|
|
_scale->setActiveSection(newScale - 1);
|
|
|
|
}
|
2016-11-07 16:08:24 +00:00
|
|
|
|
|
|
|
if (cEvalScale(newScale) != cEvalScale(cRealScale())) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(lang(lng_settings_need_restart), lang(lng_settings_restart_now), base::lambda_guarded(this, [this] {
|
|
|
|
cSetConfigScale(_newScale);
|
|
|
|
Local::writeSettings();
|
|
|
|
App::restart();
|
|
|
|
}), base::lambda_guarded(this, [this] {
|
|
|
|
App::CallDelayed(st::boxDuration, this, [this] {
|
|
|
|
setScale(cRealScale());
|
|
|
|
});
|
|
|
|
})));
|
2016-11-07 16:08:24 +00:00
|
|
|
} else {
|
|
|
|
cSetConfigScale(newScale);
|
|
|
|
Local::writeSettings();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void ScaleWidget::scaleChanged() {
|
2016-08-22 17:16:21 +00:00
|
|
|
auto newScale = dbisAuto;
|
|
|
|
switch (_scale->activeSection()) {
|
|
|
|
case 0: newScale = dbisOne; break;
|
|
|
|
case 1: newScale = dbisOneAndQuarter; break;
|
|
|
|
case 2: newScale = dbisOneAndHalf; break;
|
|
|
|
case 3: newScale = dbisTwo; break;
|
|
|
|
}
|
|
|
|
setScale(newScale);
|
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
} // namespace Settings
|