From b2ef34c5d429dd584fc8897734af8eedc4da1d08 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Wed, 6 May 2020 02:27:04 +0300 Subject: [PATCH] Added "Apply to sticker width" option --- Telegram/Resources/langs/lang.strings | 3 +++ Telegram/Resources/langs/rewrites/ru.json | 2 ++ .../SourceFiles/history/history_widget.cpp | 7 +++++++ .../media/history_view_media_unwrapped.cpp | 5 +++++ .../view/media/history_view_sticker.cpp | 3 ++- Telegram/SourceFiles/kotato/json_settings.cpp | 5 +++++ Telegram/SourceFiles/kotato/settings.cpp | 11 +++++++++++ Telegram/SourceFiles/kotato/settings.h | 4 ++++ Telegram/SourceFiles/kotato/settings_menu.cpp | 19 +++++++++++++++++++ 9 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 932b0af90..62c9823f4 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2398,6 +2398,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_chats" = "Chats"; "ktg_settings_sticker_height" = "Sticker height: {pixels}px"; +"ktg_settings_sticker_scale_both" = "Apply to sticker width"; +"ktg_settings_sticker_scale_both_about" = "When enabled, sticker maximum width will be changed along with sticker height."; + "ktg_settings_emoji_outline" = "Big emoji outline"; "ktg_settings_disable_up_edit" = "Disable edit by Up key"; diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 333c4b47c..f0c78e924 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -41,6 +41,8 @@ "ktg_pinned_message_hide": "Скрыть закреплённое сообщение", "ktg_settings_chats": "Чаты", "ktg_settings_sticker_height": "Высота стикеров: {pixels} пикс.", + "ktg_settings_sticker_scale_both": "Применять к ширине стикера", + "ktg_settings_sticker_scale_both_about": "При включении максимальная ширина стикера будет изменяться вместе с высотой.", "ktg_settings_emoji_outline": "Обводка у больших эмодзи", "ktg_settings_disable_up_edit": "Отключить редактирование по «Вверх»", "ktg_settings_always_show_scheduled": "Всегда показывать отложенные", diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 972aa505a..b3360f631 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -522,6 +522,13 @@ HistoryWidget::HistoryWidget( }); }, lifetime()); + StickerScaleBothChanges( + ) | rpl::start_with_next([=] { + crl::on_main(this, [=] { + updateHistoryGeometry(); + }); + }, lifetime()); + AdaptiveBubblesChanges( ) | rpl::start_with_next([=] { crl::on_main(this, [=] { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index 306f3281c..a8a94d0e8 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -37,6 +37,11 @@ UnwrappedMedia::UnwrappedMedia( ) | rpl::start_with_next([=] { history()->owner().requestItemViewRefresh(_parent->data()); }, _lifetime); + + StickerScaleBothChanges( + ) | rpl::start_with_next([=] { + history()->owner().requestItemViewRefresh(_parent->data()); + }, _lifetime); } QSize UnwrappedMedia::countOptimalSize() { diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 880a3d6a1..afa1c4f0e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -74,13 +74,14 @@ bool Sticker::isEmojiSticker() const { void Sticker::initSize() { _size = _document->dimensions; const auto maxHeight = int(st::maxStickerSize / 256.0 * StickerHeight()); + const auto maxWidth = StickerScaleBoth() ? maxHeight : st::maxStickerSize; if (isEmojiSticker() || _diceIndex >= 0) { _size = GetAnimatedEmojiSize(&_document->session(), _size); [[maybe_unused]] bool result = readyToDrawLottie(); } else { _size = DownscaledSize( _size, - { st::maxStickerSize, maxHeight }); + { maxWidth, maxHeight }); } } diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp index 518d52bde..15734174a 100644 --- a/Telegram/SourceFiles/kotato/json_settings.cpp +++ b/Telegram/SourceFiles/kotato/json_settings.cpp @@ -176,6 +176,7 @@ QByteArray GenerateSettingsJson(bool areDefault = false) { } settings.insert(qsl("sticker_height"), StickerHeight()); + settings.insert(qsl("sticker_scale_both"), StickerScaleBoth()); settings.insert(qsl("adaptive_bubbles"), AdaptiveBubbles()); settings.insert(qsl("big_emoji_outline"), BigEmojiOutline()); settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled()); @@ -296,6 +297,10 @@ bool Manager::readCustomFile() { } }); + ReadBoolOption(settings, "sticker_scale_both", [&](auto v) { + SetStickerScaleBoth(v); + }); + auto isAdaptiveBubblesSet = ReadBoolOption(settings, "adaptive_bubbles", [&](auto v) { SetAdaptiveBubbles(v); }); diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index c478e8f91..7492240f7 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -31,6 +31,17 @@ rpl::producer StickerHeightChanges() { return gStickerHeight.changes(); } +rpl::variable gStickerScaleBoth = true; +void SetStickerScaleBoth(bool scale) { + gStickerScaleBoth = scale; +} +bool StickerScaleBoth() { + return gStickerScaleBoth.current(); +} +rpl::producer StickerScaleBothChanges() { + return gStickerScaleBoth.changes(); +} + rpl::variable gBigEmojiOutline = true; void SetBigEmojiOutline(bool enabled) { gBigEmojiOutline = enabled; diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index 06b88372e..c76b8347b 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -39,6 +39,10 @@ void SetStickerHeight(int height); [[nodiscard]] int StickerHeight(); [[nodiscard]] rpl::producer StickerHeightChanges(); +void SetStickerScaleBoth(bool scale); +[[nodiscard]] bool StickerScaleBoth(); +[[nodiscard]] rpl::producer StickerScaleBothChanges(); + void SetAdaptiveBubbles(bool enabled); [[nodiscard]] bool AdaptiveBubbles(); [[nodiscard]] rpl::producer AdaptiveBubblesChanges(); diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index 3c78a9132..622252577 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -292,6 +292,25 @@ void SetupKotatoMessages(not_null container) { updateStickerHeight); updateStickerHeightLabel(StickerHeight()); + container->add( + object_ptr( + container, + tr::ktg_settings_sticker_scale_both(tr::now), + StickerScaleBoth(), + st::settingsCheckbox), + st::settingsCheckboxPadding + )->checkedChanges( + ) | rpl::filter([](bool checked) { + return (checked != StickerScaleBoth()); + }) | rpl::start_with_next([](bool checked) { + SetStickerScaleBoth(checked); + ::Kotato::JsonSettings::Write(); + }, container->lifetime()); + + AddSkip(container); + AddDividerText(container, tr::ktg_settings_sticker_scale_both_about()); + AddSkip(container); + SettingsMenuSwitch(ktg_settings_adaptive_bubbles, AdaptiveBubbles); SettingsMenuSwitch(ktg_settings_emoji_outline, BigEmojiOutline);