From 4caedcbf4951e364cecc92edd2c0a2ae1851731e Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 11 Oct 2019 02:39:38 +0300 Subject: [PATCH] Automatic applying of sticker height change --- Telegram/SourceFiles/core/kotato_settings.cpp | 4 ++-- Telegram/SourceFiles/history/history_widget.cpp | 7 +++++++ .../view/media/history_view_media_unwrapped.cpp | 8 +++++++- .../history/view/media/history_view_media_unwrapped.h | 2 ++ .../history/view/media/history_view_sticker.cpp | 4 ++-- Telegram/SourceFiles/settings.cpp | 11 ++++++++++- Telegram/SourceFiles/settings.h | 5 ++++- Telegram/SourceFiles/settings/settings_kotato.cpp | 6 +++--- 8 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/core/kotato_settings.cpp b/Telegram/SourceFiles/core/kotato_settings.cpp index 84bafd46ee..4f972da627 100644 --- a/Telegram/SourceFiles/core/kotato_settings.cpp +++ b/Telegram/SourceFiles/core/kotato_settings.cpp @@ -160,7 +160,7 @@ bool Manager::readCustomFile() { if (settingsStickerHeightIt != settings.constEnd()) { const auto settingsStickerHeight = (*settingsStickerHeightIt).toInt(); if (settingsStickerHeight >= 128 || settingsStickerHeight <= 256) { - cSetStickerHeight(settingsStickerHeight); + SetStickerHeight(settingsStickerHeight); } } @@ -246,7 +246,7 @@ void Manager::writeDefaultFile() { settings.insert(qsl("fonts"), settingsFonts); - settings.insert(qsl("sticker_height"), cStickerHeight()); + settings.insert(qsl("sticker_height"), StickerHeight()); settings.insert(qsl("big_emoji_outline"), BigEmojiOutline()); settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled()); settings.insert(qsl("show_chat_id"), cShowChatId()); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index bc0a7bad09..6c86c284ea 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -511,6 +511,13 @@ HistoryWidget::HistoryWidget( }); }, lifetime()); + StickerHeightChanges( + ) | rpl::start_with_next([=] { + crl::on_main(this, [=] { + updateHistoryGeometry(); + }); + }, lifetime()); + session().data().animationPlayInlineRequest( ) | rpl::start_with_next([=](not_null item) { if (const auto view = item->mainView()) { 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 b7ddf9e3ec..2a46af3f83 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -10,8 +10,10 @@ For license and copyright information please follow this link: #include "history/view/media/history_view_media_common.h" #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" +#include "history/history.h" #include "history/history_item.h" #include "history/history_item_components.h" +#include "data/data_session.h" #include "layout.h" #include "facades.h" #include "app.h" @@ -26,13 +28,17 @@ UnwrappedMedia::UnwrappedMedia( std::unique_ptr content) : Media(parent) , _content(std::move(content)) { + StickerHeightChanges( + ) | rpl::start_with_next([=] { + history()->owner().requestItemViewRefresh(_parent->data()); + }, _lifetime); } QSize UnwrappedMedia::countOptimalSize() { _content->refreshLink(); _contentSize = NonEmptySize(DownscaledSize( _content->size(), - { st::maxStickerSize, cStickerHeight() })); + { st::maxStickerSize, StickerHeight() })); auto maxWidth = _contentSize.width(); const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline; auto minHeight = std::max(_contentSize.height(), minimal); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h index de27f2d0f5..be423cfe9d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h @@ -111,6 +111,8 @@ class UnwrappedMedia final : public Media { std::unique_ptr _content; QSize _contentSize; + rpl::lifetime _lifetime; + }; } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 5e567dc66b..abddf90474 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -60,13 +60,13 @@ QSize Sticker::size() { constexpr auto kIdealStickerSize = 512; const auto zoom = GetEmojiStickerZoom(&_document->session()); const auto convert = [&](int size) { - return int(size * cStickerHeight() * zoom / kIdealStickerSize); + return int(size * StickerHeight() * zoom / kIdealStickerSize); }; _size = QSize(convert(_size.width()), convert(_size.height())); } else { _size = DownscaledSize( _size, - { st::maxStickerSize, cStickerHeight() }); + { st::maxStickerSize, StickerHeight() }); } return _size; } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 354723556b..abb4621259 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -210,7 +210,16 @@ rpl::producer<> UpdatedRecentEmoji() { QString gMainFont, gSemiboldFont, gMonospaceFont; bool gSemiboldFontIsBold = false; -int gStickerHeight = 128; +rpl::variable gStickerHeight = 128; +void SetStickerHeight(int height) { + gStickerHeight = height; +} +int StickerHeight() { + return gStickerHeight.current(); +} +rpl::producer StickerHeightChanges() { + return gStickerHeight.changes(); +} rpl::variable gBigEmojiOutline = false; void SetBigEmojiOutline(bool enabled) { diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 1608299c5a..ae38fb63d0 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -188,7 +188,10 @@ void SetBigEmojiOutline(bool enabled); [[nodiscard]] bool BigEmojiOutline(); [[nodiscard]] rpl::producer BigEmojiOutlineChanges(); -DeclareSetting(int, StickerHeight); +void SetStickerHeight(int height); +[[nodiscard]] int StickerHeight(); +[[nodiscard]] rpl::producer StickerHeightChanges(); + DeclareSetting(bool, AlwaysShowScheduled); DeclareSetting(bool, ShowChatId); diff --git a/Telegram/SourceFiles/settings/settings_kotato.cpp b/Telegram/SourceFiles/settings/settings_kotato.cpp index bcc98e1c74..378abf4dcc 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.cpp +++ b/Telegram/SourceFiles/settings/settings_kotato.cpp @@ -56,15 +56,15 @@ void SetupKotatoChats(not_null container) { }; const auto updateStickerHeight = [=](int value) { updateStickerHeightLabel(value); - cSetStickerHeight(value); + SetStickerHeight(value); }; stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize); stickerHeightSlider->setPseudoDiscrete( 129, [](int val) { return val + 128; }, - cStickerHeight(), + StickerHeight(), updateStickerHeight); - updateStickerHeightLabel(cStickerHeight()); + updateStickerHeightLabel(StickerHeight()); AddButton( container,