[Option][GUI] Qt scale

This commit is contained in:
Eric Kotato 2022-08-30 14:40:20 +03:00 committed by Eric Kotato
parent 457b4d5312
commit 1cc8612c27
7 changed files with 62 additions and 3 deletions

View file

@ -55,6 +55,7 @@
"ktg_net_speed_boost_medium": "Medium",
"ktg_net_speed_boost_big": "Big",
"ktg_settings_system": "System",
"ktg_settings_qt_scale": "Qt scaling engine",
"ktg_settings_other": "Other",
"ktg_profile_copy_id": "Copy ID",
"ktg_profile_bot_id": "Bot ID",

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "kotato/kotato_lang.h"
#include "kotato/kotato_settings.h"
#include "data/data_abstract_structure.h"
#include "data/data_photo.h"
#include "data/data_document.h"
@ -230,9 +231,16 @@ void Application::run() {
_notifications = std::make_unique<Window::Notifications::System>();
startLocalStorage();
ValidateScale();
Kotato::Lang::Load(Lang::GetInstance().baseId(), Lang::GetInstance().id());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (!::Kotato::JsonSettings::GetBool("qt_scale")) {
#endif
ValidateScale();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
}
#endif
refreshGlobalProxy(); // Depends on app settings being read.
if (Local::oldSettingsVersion() < AppVersion) {

View file

@ -337,6 +337,13 @@ int Launcher::exec() {
base::options::init(cWorkingDir() + "tdata/experimental_options.json");
Kotato::JsonSettings::Load();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (::Kotato::JsonSettings::GetBool("qt_scale")) {
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, false);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
}
#endif
if (Logs::DebugEnabled()) {
const auto openalLogPath = QDir::toNativeSeparators(
cWorkingDir() + qsl("DebugLogs/last_openal_log.txt"));

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/sandbox.h"
#include "kotato/kotato_settings.h"
#include "base/platform/base_platform_info.h"
#include "platform/platform_specific.h"
#include "mainwidget.h"
@ -235,7 +236,11 @@ void Sandbox::setupScreenScale() {
}
const auto ratio = devicePixelRatio();
if (ratio > 1.) {
if (ratio > 1.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|| ::Kotato::JsonSettings::GetBool("qt_scale")
#endif
) {
if (!Platform::IsMac() || (ratio != 2.)) {
LOG(("Found non-trivial Device Pixel Ratio: %1").arg(ratio));
LOG(("Environmental variables: QT_DEVICE_PIXEL_RATIO='%1'").arg(qEnvironmentVariable("QT_DEVICE_PIXEL_RATIO")));
@ -244,7 +249,11 @@ void Sandbox::setupScreenScale() {
LOG(("Environmental variables: QT_SCREEN_SCALE_FACTORS='%1'").arg(qEnvironmentVariable("QT_SCREEN_SCALE_FACTORS")));
}
style::SetDevicePixelRatio(int(ratio));
if (Platform::IsMac() && ratio == 2.) {
if (Platform::IsMac() && ratio == 2.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
&& !::Kotato::JsonSettings::GetBool("qt_scale")
#endif
) {
cSetScreenScale(110); // 110% for Retina screens by default.
} else {
cSetScreenScale(style::kScaleDefault);

View file

@ -370,6 +370,12 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
{ "always_show_top_userpic", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
{ "qt_scale", {
.storage = SettingStorage::None,
.type = SettingType::BoolSetting,
.defaultValue = false, }},
#endif
};
using OldOptionKey = QString;

View file

@ -395,6 +395,29 @@ void SetupKotatoSystem(
AddSkip(container);
AddSubsectionTitle(container, rktr("ktg_settings_system"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
AddButton(
container,
rktr("ktg_settings_qt_scale"),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(::Kotato::JsonSettings::GetBoolWithPending("qt_scale"))
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != ::Kotato::JsonSettings::GetBoolWithPending("qt_scale"));
}) | rpl::start_with_next([=](bool enabled) {
::Kotato::JsonSettings::SetAfterRestart("qt_scale", enabled);
::Kotato::JsonSettings::Write();
Ui::show(Ui::MakeConfirmBox({
.text = tr::lng_settings_need_restart(),
.confirmed = [] { Core::Restart(); },
.confirmText = tr::lng_settings_restart_now(),
.cancelText = tr::lng_settings_restart_later(),
}));
}, container->lifetime());
#endif // Qt < 6.0.0
AddSkip(container);
}

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_main.h"
#include "kotato/kotato_lang.h"
#include "kotato/kotato_settings.h"
#include "kotato/kotato_settings_menu.h"
#include "settings/settings_common.h"
#include "settings/settings_codes.h"
@ -402,7 +403,11 @@ void SetupSections(
}
bool HasInterfaceScale() {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return !::Kotato::JsonSettings::GetBool("qt_scale");
#else
return true;
#endif
}
void SetupInterfaceScale(