From b364c4f23acc54b6e304fcebb73f96efa6710908 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 21 Aug 2024 11:18:09 +0300 Subject: [PATCH] Moved out graphic of button for expandable moderate list to view. --- .../boxes/moderate_messages_box.cpp | 108 +++++------------- .../ui/widgets/participants_check_view.cpp | 95 +++++++++++++++ .../ui/widgets/participants_check_view.h | 39 +++++++ Telegram/cmake/td_ui.cmake | 2 + 4 files changed, 166 insertions(+), 78 deletions(-) create mode 100644 Telegram/SourceFiles/ui/widgets/participants_check_view.cpp create mode 100644 Telegram/SourceFiles/ui/widgets/participants_check_view.h diff --git a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp index 3e1a8bea5..bdd4c53dc 100644 --- a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "base/event_filter.h" #include "base/timer.h" +#include "ui/widgets/participants_check_view.h" #include "boxes/delete_messages_box.h" #include "boxes/peers/edit_peer_permissions_box.h" #include "core/application.h" @@ -114,101 +115,44 @@ class Button final : public Ui::RippleButton { public: Button(not_null parent, int count); - void setChecked(bool checked); - [[nodiscard]] bool checked() const; - - [[nodiscard]] static QSize ComputeSize(int); + [[nodiscard]] not_null checkView() const; private: void paintEvent(QPaintEvent *event) override; QImage prepareRippleMask() const override; QPoint prepareRippleStartPosition() const override; - const int _count; - const QString _text; - bool _checked = false; - - Ui::Animations::Simple _animation; + std::unique_ptr _view; }; Button::Button(not_null parent, int count) -: RippleButton(parent, st::defaultRippleAnimation) -, _count(count) -, _text(QString::number(std::abs(_count))) { +: Ui::RippleButton(parent, st::defaultRippleAnimation) +, _view(std::make_unique( + count, + st::slideWrapDuration, + false, + [=] { update(); })) { } -QSize Button::ComputeSize(int count) { - return QSize( - st::moderateBoxExpandHeight - + st::moderateBoxExpand.width() - + st::moderateBoxExpandInnerSkip * 4 - + st::moderateBoxExpandFont->width( - QString::number(std::abs(count))) - + st::moderateBoxExpandToggleSize, - st::moderateBoxExpandHeight); -} - -void Button::setChecked(bool checked) { - if (_checked == checked) { - return; - } - _checked = checked; - _animation.stop(); - _animation.start( - [=] { update(); }, - checked ? 0 : 1, - checked ? 1 : 0, - st::slideWrapDuration); -} - -bool Button::checked() const { - return _checked; -} - -void Button::paintEvent(QPaintEvent *event) { - auto p = Painter(this); - auto hq = PainterHighQualityEnabler(p); - Ui::RippleButton::paintRipple(p, QPoint()); - const auto radius = height() / 2; - p.setPen(Qt::NoPen); - st::moderateBoxExpand.paint( - p, - radius, - (height() - st::moderateBoxExpand.height()) / 2, - width()); - - const auto innerSkip = st::moderateBoxExpandInnerSkip; - - p.setBrush(Qt::NoBrush); - p.setPen(st::boxTextFg); - p.setFont(st::moderateBoxExpandFont); - p.drawText( - QRect( - innerSkip + radius + st::moderateBoxExpand.width(), - 0, - width(), - height()), - _text, - style::al_left); - - const auto path = Ui::ToggleUpDownArrowPath( - width() - st::moderateBoxExpandToggleSize - radius, - height() / 2, - st::moderateBoxExpandToggleSize, - st::moderateBoxExpandToggleFourStrokes, - _animation.value(_checked ? 1. : 0.)); - p.fillPath(path, st::boxTextFg); +not_null Button::checkView() const { + return _view.get(); } QImage Button::prepareRippleMask() const { - return Ui::RippleAnimation::RoundRectMask(size(), size().height() / 2); + return _view->prepareRippleMask(); } QPoint Button::prepareRippleStartPosition() const { return mapFromGlobal(QCursor::pos()); } +void Button::paintEvent(QPaintEvent *event) { + auto p = QPainter(this); + Ui::RippleButton::paintRipple(p, QPoint()); + _view->paint(p, 0, 0, width()); +} + void CreateParticipantsList( not_null controller, not_null inner, @@ -313,7 +257,7 @@ void AppendList( } const auto count = int(participants.size()); const auto button = Ui::CreateChild