From d5774830d86a022d42e264bc74a06fbc22a32166 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 21 Aug 2024 13:26:35 +0300 Subject: [PATCH] Added ability to provide data to Ui::ExpandablePeerListController. --- .../boxes/moderate_messages_box.cpp | 33 +++++-------------- .../ui/widgets/expandable_peer_list.cpp | 23 ++++++++----- .../ui/widgets/expandable_peer_list.h | 16 ++++++--- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp index 5ea43c0c9..6001b45b0 100644 --- a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp @@ -229,14 +229,9 @@ void CreateModerateMessagesBox( false, st::defaultBoxCheckbox), st::boxRowPadding + buttonPadding); - const auto controller = box->lifetime().make_state(); - Ui::AddExpandablePeerList( - report, - controller, - inner, - participants, - true, - false); + const auto controller = box->lifetime().make_state( + Controller::Data{ .participants = participants }); + Ui::AddExpandablePeerList(report, controller, inner); handleSubmition(report); const auto ids = items.front()->from()->owner().itemsToIds(items); @@ -293,14 +288,9 @@ void CreateModerateMessagesBox( }, title->lifetime()); } - const auto controller = box->lifetime().make_state(); - Ui::AddExpandablePeerList( - deleteAll, - controller, - inner, - participants, - true, - false); + const auto controller = box->lifetime().make_state( + Controller::Data{ .participants = participants }); + Ui::AddExpandablePeerList(deleteAll, controller, inner); handleSubmition(deleteAll); handleConfirmation(deleteAll, controller, [=]( @@ -329,14 +319,9 @@ void CreateModerateMessagesBox( false, st::defaultBoxCheckbox), st::boxRowPadding + buttonPadding); - const auto controller = box->lifetime().make_state(); - Ui::AddExpandablePeerList( - ban, - controller, - inner, - participants, - true, - false); + const auto controller = box->lifetime().make_state( + Controller::Data{ .participants = participants }); + Ui::AddExpandablePeerList(ban, controller, inner); handleSubmition(ban); Ui::AddSkip(inner); diff --git a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp index 13e3e15a8..db09645b6 100644 --- a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp +++ b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer.h" #include "ui/controls/userpic_button.h" #include "ui/rect.h" +#include "ui/text/text_utilities.h" #include "ui/vertical_list.h" #include "ui/widgets/buttons.h" #include "ui/widgets/participants_check_view.h" @@ -69,11 +70,13 @@ void Button::paintEvent(QPaintEvent *event) { void AddExpandablePeerList( not_null checkbox, not_null controller, - not_null inner, - const Participants &participants, - bool handleSingle, - bool hideRightButton) { - const auto isSingle = handleSingle ? (participants.size() == 1) : false; + not_null inner) { + const auto &participants = controller->data.participants; + const auto hideRightButton = controller->data.hideRightButton; + const auto checkTopOnAllInner = controller->data.checkTopOnAllInner; + const auto isSingle = controller->data.skipSingle + ? false + : (participants.size() == 1); if (isSingle) { const auto p = participants.front(); controller->collectRequests = [=] { return Participants{ p }; }; @@ -151,8 +154,10 @@ void AddExpandablePeerList( st); const auto checkbox = Ui::CreateChild( line, - peer->name(), - false, + controller->data.bold + ? Ui::Text::Bold(peer->name()) + : TextWithEntities{ .text = peer->name() }, + ranges::contains(controller->data.checked, peer->id), st::defaultBoxCheckbox); line->widthValue( ) | rpl::start_with_next([=](int width) { @@ -186,7 +191,9 @@ void AddExpandablePeerList( clicks->events( ) | rpl::start_with_next([=] { controller->toggleRequestsFromInner.fire_copy( - ranges::any_of(checkboxes, &Ui::Checkbox::checked)); + checkTopOnAllInner + ? ranges::all_of(checkboxes, &Ui::Checkbox::checked) + : ranges::any_of(checkboxes, &Ui::Checkbox::checked)); }, container->lifetime()); controller->checkAllRequests.events( diff --git a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.h b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.h index 4ac84dae3..3ff7e4ee1 100644 --- a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.h +++ b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.h @@ -17,6 +17,17 @@ class Checkbox; class VerticalLayout; struct ExpandablePeerListController final { + struct Data final { + Participants participants; + std::vector checked; + bool skipSingle = false; + bool hideRightButton = false; + bool checkTopOnAllInner = false; + bool bold = true; + }; + ExpandablePeerListController(Data &&data) : data(std::move(data)) { + } + const Data data; rpl::event_stream toggleRequestsFromTop; rpl::event_stream toggleRequestsFromInner; rpl::event_stream checkAllRequests; @@ -26,9 +37,6 @@ struct ExpandablePeerListController final { void AddExpandablePeerList( not_null checkbox, not_null controller, - not_null inner, - const Participants &participants, - bool handleSingle, - bool hideRightButton); + not_null inner); } // namespace Ui