diff --git a/Telegram/SourceFiles/window/window_main_menu_helpers.cpp b/Telegram/SourceFiles/window/window_main_menu_helpers.cpp index bf15aacba..baf22753d 100644 --- a/Telegram/SourceFiles/window/window_main_menu_helpers.cpp +++ b/Telegram/SourceFiles/window/window_main_menu_helpers.cpp @@ -165,43 +165,42 @@ not_null AddMyChannelsBox( st->photoSize = st::defaultPeerListItem.photoSize; st->size = QSize(st->photoSize, st->photoSize); - class Button final : public Ui::SettingsButton { - public: - using Ui::SettingsButton::SettingsButton; - - void setPeer(not_null p) { - const auto c = p->asChannel(); - const auto g = p->asChat(); - _text.setText( - st::defaultPeerListItem.nameStyle, - ((c && c->isMegagroup()) ? u"[s] "_q : QString()) - + p->name()); - const auto count = c ? c->membersCount() : g->count; - _status.setText( - st::defaultTextStyle, - (g && !g->amIn()) - ? tr::lng_chat_status_unaccessible(tr::now) - : !p->username().isEmpty() - ? ('@' + p->username()) - : (count > 0) - ? ((c && !c->isMegagroup()) - ? tr::lng_chat_status_subscribers - : tr::lng_chat_status_members)( - tr::now, - lt_count, - count) - : QString()); - } - - int resizeGetHeight(int) override { - return st::defaultPeerListItem.height; - } - - void paintEvent(QPaintEvent *e) override { - Ui::SettingsButton::paintEvent(e); - auto p = Painter(this); + const auto megagroupMark = u"[s] "_q; + const auto add = [&]( + not_null peer, + not_null container) { + const auto row = container->add( + object_ptr::fromRaw( + Ui::CreateSimpleSettingsButton( + container, + st::defaultRippleAnimation, + st::defaultSettingsButton.textBgOver))); + row->resize(row->width(), st::defaultPeerListItem.height); + const auto c = peer->asChannel(); + const auto g = peer->asChat(); + const auto count = c ? c->membersCount() : g->count; + const auto text = std::make_shared( + st::defaultPeerListItem.nameStyle, + ((c && c->isMegagroup()) ? megagroupMark : QString()) + + peer->name()); + const auto status = std::make_shared( + st::defaultTextStyle, + (g && !g->amIn()) + ? tr::lng_chat_status_unaccessible(tr::now) + : !peer->username().isEmpty() + ? ('@' + peer->username()) + : (count > 0) + ? ((c && !c->isMegagroup()) + ? tr::lng_chat_status_subscribers + : tr::lng_chat_status_members)( + tr::now, + lt_count, + count) + : QString()); + row->paintRequest() | rpl::start_with_next([=] { + auto p = QPainter(row); const auto &st = st::defaultPeerListItem; - const auto availableWidth = width() + const auto availableWidth = row->width() - st::boxRowPadding.right() - st.namePosition.x(); p.setPen(st.nameFg); @@ -211,24 +210,11 @@ not_null AddMyChannelsBox( .availableWidth = availableWidth, .elisionLines = 1, }; - _text.draw(p, context); + text->draw(p, context); p.setPen(st.statusFg); context.position = st.statusPosition; - _status.draw(p, context); - } - - private: - Ui::Text::String _text; - Ui::Text::String _status; - - }; - - const auto add = [&]( - not_null peer, - not_null container) { - const auto row = container->add( - object_ptr