peer_bubble.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "ui/widgets/peer_bubble.h"
  8. #include "data/data_peer.h"
  9. #include "info/profile/info_profile_values.h"
  10. #include "ui/controls/userpic_button.h"
  11. #include "ui/painter.h"
  12. #include "ui/rect.h"
  13. #include "ui/widgets/labels.h"
  14. #include "styles/style_boxes.h"
  15. #include "styles/style_channel_earn.h"
  16. #include "styles/style_chat.h"
  17. #include "styles/style_layers.h"
  18. namespace Ui {
  19. object_ptr<Ui::RpWidget> CreatePeerBubble(
  20. not_null<Ui::RpWidget*> parent,
  21. not_null<PeerData*> peer) {
  22. auto owned = object_ptr<Ui::RpWidget>(parent);
  23. const auto peerBubble = owned.data();
  24. peerBubble->setAttribute(Qt::WA_TransparentForMouseEvents);
  25. const auto left = Ui::CreateChild<Ui::UserpicButton>(
  26. peerBubble,
  27. peer,
  28. st::uploadUserpicButton);
  29. const auto right = Ui::CreateChild<Ui::FlatLabel>(
  30. peerBubble,
  31. Info::Profile::NameValue(peer),
  32. st::channelEarnSemiboldLabel);
  33. const auto padding = st::chatGiveawayPeerPadding
  34. + QMargins(st::chatGiveawayPeerPadding.left(), 0, 0, 0);
  35. rpl::combine(
  36. left->sizeValue(),
  37. right->sizeValue()
  38. ) | rpl::start_with_next([=](
  39. const QSize &leftSize,
  40. const QSize &rightSize) {
  41. peerBubble->resize(
  42. leftSize.width() + rightSize.width() + rect::m::sum::h(padding),
  43. leftSize.height());
  44. left->moveToLeft(0, 0);
  45. right->moveToRight(padding.right() + st::lineWidth, padding.top());
  46. const auto maxRightSize = parent->width()
  47. - rect::m::sum::h(st::boxRowPadding)
  48. - rect::m::sum::h(padding)
  49. - leftSize.width();
  50. if ((rightSize.width() > maxRightSize) && (maxRightSize > 0)) {
  51. right->resizeToWidth(maxRightSize);
  52. }
  53. }, peerBubble->lifetime());
  54. peerBubble->paintRequest(
  55. ) | rpl::start_with_next([=] {
  56. auto p = QPainter(peerBubble);
  57. auto hq = PainterHighQualityEnabler(p);
  58. p.setPen(Qt::NoPen);
  59. p.setBrush(st::windowBgOver);
  60. const auto rect = peerBubble->rect();
  61. const auto radius = rect.height() / 2;
  62. p.drawRoundedRect(rect, radius, radius);
  63. }, peerBubble->lifetime());
  64. return owned;
  65. }
  66. } // namespace Ui