Moved out peer bubble widget to separated file.

This commit is contained in:
23rd 2024-11-11 09:45:26 +03:00 committed by John Preston
parent 9211e338e7
commit 81bea04db0
4 changed files with 103 additions and 50 deletions

View file

@ -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

View file

@ -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<Ui::CenterWrap<>>(
box,
object_ptr<Ui::RpWidget>(box)))->entity();
peerBubble->setAttribute(
Qt::WA_TransparentForMouseEvents);
const auto left = Ui::CreateChild<Ui::UserpicButton>(
peerBubble,
peer,
st::uploadUserpicButton);
const auto right = Ui::CreateChild<Ui::FlatLabel>(
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(); };
{

View file

@ -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<Ui::RpWidget> CreatePeerBubble(
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer) {
auto owned = object_ptr<Ui::RpWidget>(parent);
const auto peerBubble = owned.data();
peerBubble->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto left = Ui::CreateChild<Ui::UserpicButton>(
peerBubble,
peer,
st::uploadUserpicButton);
const auto right = Ui::CreateChild<Ui::FlatLabel>(
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

View file

@ -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 <typename Object>
class object_ptr;
class PeerData;
namespace Ui {
class RpWidget;
class VerticalLayout;
} // namespace Ui
namespace Ui {
[[nodiscard]] object_ptr<Ui::RpWidget> CreatePeerBubble(
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer);
} // namespace Ui