From 81bea04db07b30ccfd1a9484b45c28e088f4a4cd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 11 Nov 2024 09:45:26 +0300 Subject: [PATCH] Moved out peer bubble widget to separated file. --- Telegram/CMakeLists.txt | 2 + .../earn/info_channel_earn_list.cpp | 53 +------------- .../SourceFiles/ui/widgets/peer_bubble.cpp | 72 +++++++++++++++++++ Telegram/SourceFiles/ui/widgets/peer_bubble.h | 26 +++++++ 4 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 Telegram/SourceFiles/ui/widgets/peer_bubble.cpp create mode 100644 Telegram/SourceFiles/ui/widgets/peer_bubble.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index f05dcb98e..bb41134c1 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1551,6 +1551,8 @@ PRIVATE ui/widgets/label_with_custom_emoji.h ui/widgets/chat_filters_tabs_strip.cpp ui/widgets/chat_filters_tabs_strip.h + ui/widgets/peer_bubble.cpp + ui/widgets/peer_bubble.h ui/countryinput.cpp ui/countryinput.h ui/dynamic_thumbnails.cpp diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index 3f98b5f23..3a2250f39 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -52,6 +52,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/vertical_list.h" #include "ui/widgets/fields/input_field.h" #include "ui/widgets/label_with_custom_emoji.h" +#include "ui/widgets/peer_bubble.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/slider_natural_width.h" #include "ui/wrap/slide_wrap.h" @@ -1199,58 +1200,10 @@ void InnerWidget::fill() { AddRecipient(box, recipient); } if (isIn) { - const auto peerBubble = box->addRow( + box->addRow( object_ptr>( box, - object_ptr(box)))->entity(); - peerBubble->setAttribute( - Qt::WA_TransparentForMouseEvents); - const auto left = Ui::CreateChild( - peerBubble, - peer, - st::uploadUserpicButton); - const auto right = Ui::CreateChild( - peerBubble, - Info::Profile::NameValue(peer), - st::channelEarnSemiboldLabel); - rpl::combine( - left->sizeValue(), - right->sizeValue() - ) | rpl::start_with_next([=]( - const QSize &leftSize, - const QSize &rightSize) { - const auto padding = QMargins( - st::chatGiveawayPeerPadding.left() * 2, - st::chatGiveawayPeerPadding.top(), - st::chatGiveawayPeerPadding.right(), - st::chatGiveawayPeerPadding.bottom()); - peerBubble->resize( - leftSize.width() - + rightSize.width() - + rect::m::sum::h(padding), - leftSize.height()); - left->moveToLeft(0, 0); - right->moveToRight( - padding.right(), - padding.top()); - const auto maxRightSize = box->width() - - rect::m::sum::h(st::boxRowPadding) - - rect::m::sum::h(padding) - - leftSize.width(); - if (rightSize.width() > maxRightSize) { - right->resizeToWidth(maxRightSize); - } - }, peerBubble->lifetime()); - peerBubble->paintRequest( - ) | rpl::start_with_next([=] { - auto p = QPainter(peerBubble); - auto hq = PainterHighQualityEnabler(p); - p.setPen(Qt::NoPen); - p.setBrush(st::windowBgOver); - const auto rect = peerBubble->rect(); - const auto radius = rect.height() / 2; - p.drawRoundedRect(rect, radius, radius); - }, peerBubble->lifetime()); + Ui::CreatePeerBubble(box, peer))); } const auto closeBox = [=] { box->closeBox(); }; { diff --git a/Telegram/SourceFiles/ui/widgets/peer_bubble.cpp b/Telegram/SourceFiles/ui/widgets/peer_bubble.cpp new file mode 100644 index 000000000..87ac897d3 --- /dev/null +++ b/Telegram/SourceFiles/ui/widgets/peer_bubble.cpp @@ -0,0 +1,72 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/widgets/peer_bubble.h" + +#include "data/data_peer.h" +#include "info/profile/info_profile_values.h" +#include "ui/controls/userpic_button.h" +#include "ui/painter.h" +#include "ui/rect.h" +#include "ui/widgets/labels.h" +#include "styles/style_boxes.h" +#include "styles/style_channel_earn.h" +#include "styles/style_chat.h" +#include "styles/style_layers.h" + +namespace Ui { + +object_ptr CreatePeerBubble( + not_null parent, + not_null peer) { + auto owned = object_ptr(parent); + const auto peerBubble = owned.data(); + peerBubble->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto left = Ui::CreateChild( + peerBubble, + peer, + st::uploadUserpicButton); + const auto right = Ui::CreateChild( + peerBubble, + Info::Profile::NameValue(peer), + st::channelEarnSemiboldLabel); + const auto padding = st::chatGiveawayPeerPadding + + QMargins(st::chatGiveawayPeerPadding.left(), 0, 0, 0); + rpl::combine( + left->sizeValue(), + right->sizeValue() + ) | rpl::start_with_next([=]( + const QSize &leftSize, + const QSize &rightSize) { + peerBubble->resize( + leftSize.width() + rightSize.width() + rect::m::sum::h(padding), + leftSize.height()); + left->moveToLeft(0, 0); + right->moveToRight(padding.right() + st::lineWidth, padding.top()); + const auto maxRightSize = parent->width() + - rect::m::sum::h(st::boxRowPadding) + - rect::m::sum::h(padding) + - leftSize.width(); + if ((rightSize.width() > maxRightSize) && (maxRightSize > 0)) { + right->resizeToWidth(maxRightSize); + } + }, peerBubble->lifetime()); + peerBubble->paintRequest( + ) | rpl::start_with_next([=] { + auto p = QPainter(peerBubble); + auto hq = PainterHighQualityEnabler(p); + p.setPen(Qt::NoPen); + p.setBrush(st::windowBgOver); + const auto rect = peerBubble->rect(); + const auto radius = rect.height() / 2; + p.drawRoundedRect(rect, radius, radius); + }, peerBubble->lifetime()); + + return owned; +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/peer_bubble.h b/Telegram/SourceFiles/ui/widgets/peer_bubble.h new file mode 100644 index 000000000..9c0b657d9 --- /dev/null +++ b/Telegram/SourceFiles/ui/widgets/peer_bubble.h @@ -0,0 +1,26 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +template +class object_ptr; + +class PeerData; + +namespace Ui { +class RpWidget; +class VerticalLayout; +} // namespace Ui + +namespace Ui { + +[[nodiscard]] object_ptr CreatePeerBubble( + not_null parent, + not_null peer); + +} // namespace Ui