From 5e20c15c20eac46c497e3d7cc8541fe60fb5329e Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 29 Nov 2022 20:21:08 +0400 Subject: [PATCH] Adapt edit topic box to General. --- .../boxes/peers/edit_forum_topic_box.cpp | 92 +++++++++++++------ 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index 02702daa2..18212fea4 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -194,6 +194,39 @@ bool DefaultIconEmoji::readyInDefaultState() { return result; } +[[nodiscard]] not_null GeneralIconPreview( + not_null parent) { + using namespace Info::Profile; + struct State { + QImage frame; + }; + const auto tag = Data::CustomEmojiManager::SizeTag::Large; + const auto size = EditIconSize(); + const auto result = Ui::CreateChild(parent.get()); + result->show(); + result->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto state = result->lifetime().make_state(); + + rpl::single(rpl::empty) | rpl::then( + style::PaletteChanged() + ) | rpl::start_with_next([=] { + state->frame = Data::ForumTopicGeneralIconFrame( + st::largeForumTopicIcon.size, + st::windowSubTextFg); + result->update(); + }, result->lifetime()); + + result->resize(size, size); + result->paintRequest( + ) | rpl::start_with_next([=](QRect clip) { + auto p = QPainter(result); + const auto skip = (size - st::largeForumTopicIcon.size) / 2; + p.drawImage(skip, skip, state->frame); + }, result->lifetime()); + + return result; +} + struct IconSelector { Fn)> paintIconFrame; rpl::producer iconIdValue; @@ -404,14 +437,16 @@ void EditForumTopicBox( }); const auto paintIconFrame = [=](not_null widget) { - return state->paintIconFrame(widget); + return state->paintIconFrame && state->paintIconFrame(widget); }; - const auto icon = EditIconButton( - title->parentWidget(), - controller, - state->defaultIcon.value(), - state->iconId.value(), - paintIconFrame); + const auto icon = (topic && topic->isGeneral()) + ? GeneralIconPreview(title->parentWidget()) + : EditIconButton( + title->parentWidget(), + controller, + state->defaultIcon.value(), + state->iconId.value(), + paintIconFrame); title->geometryValue( ) | rpl::start_with_next([=](QRect geometry) { @@ -444,27 +479,29 @@ void EditForumTopicBox( }; }, box->lifetime()); - Settings::AddDividerText( - top, - tr::lng_forum_choose_title_and_icon()); + if (!topic || !topic->isGeneral()) { + Settings::AddDividerText( + top, + tr::lng_forum_choose_title_and_icon()); - box->setScrollStyle(st::reactPanelScroll); + box->setScrollStyle(st::reactPanelScroll); - auto selector = AddIconSelector( - box, - icon, - controller, - state->defaultIcon.value(), - top->heightValue(), - state->iconId.current(), - [&](object_ptr footer) { - top->add(std::move(footer)); }); - state->paintIconFrame = std::move(selector.paintIconFrame); - std::move( - selector.iconIdValue - ) | rpl::start_with_next([=](DocumentId iconId) { - state->iconId = (iconId != kDefaultIconId) ? iconId : 0; - }, box->lifetime()); + auto selector = AddIconSelector( + box, + icon, + controller, + state->defaultIcon.value(), + top->heightValue(), + state->iconId.current(), + [&](object_ptr footer) { + top->add(std::move(footer)); }); + state->paintIconFrame = std::move(selector.paintIconFrame); + std::move( + selector.iconIdValue + ) | rpl::start_with_next([=](DocumentId iconId) { + state->iconId = (iconId != kDefaultIconId) ? iconId : 0; + }, box->lifetime()); + } const auto create = [=] { const auto channel = forum->peer->asChannel(); @@ -508,7 +545,8 @@ void EditForumTopicBox( const auto api = &forum->session().api(); const auto weak = Ui::MakeWeak(box.get()); state->requestId = api->request(MTPchannels_EditForumTopic( - MTP_flags(Flag::f_title | Flag::f_icon_emoji_id), + MTP_flags(Flag::f_title + | (topic->isGeneral() ? Flag() : Flag::f_icon_emoji_id)), topic->channel()->inputChannel, MTP_int(rootId), MTP_string(title->getLastText().trimmed()),