From 1cc8612c27ba126c041784936d380a61e00d1eb7 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Tue, 30 Aug 2022 14:40:20 +0300 Subject: [PATCH] [Option][GUI] Qt scale --- Telegram/Resources/langs/rewrites/en.json | 1 + Telegram/SourceFiles/core/application.cpp | 10 +++++++- Telegram/SourceFiles/core/launcher.cpp | 7 ++++++ Telegram/SourceFiles/core/sandbox.cpp | 13 +++++++++-- .../SourceFiles/kotato/kotato_settings.cpp | 6 +++++ .../kotato/kotato_settings_menu.cpp | 23 +++++++++++++++++++ .../SourceFiles/settings/settings_main.cpp | 5 ++++ 7 files changed, 62 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 665304725..6028ca9da 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -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", diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index a0e19a179..fc7de0bc0 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -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(); 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) { diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 2cb55b814..1e119d643 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -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")); diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 54523d98b..c62730b4f 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -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); diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index 5ebf9426e..ca7597585 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -370,6 +370,12 @@ const std::map> 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; diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index c4140ea49..cb585acc3 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -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); } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 2c4f8b610..d06bb9859 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -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(