info_profile_cover.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #pragma once
  8. #include "info/profile/info_profile_badge.h"
  9. #include "ui/wrap/padding_wrap.h"
  10. #include "ui/abstract_button.h"
  11. #include "base/timer.h"
  12. namespace Window {
  13. class SessionController;
  14. } // namespace Window
  15. namespace Ui {
  16. class UserpicButton;
  17. class FlatLabel;
  18. template <typename Widget>
  19. class SlideWrap;
  20. class RoundButton;
  21. } // namespace Ui
  22. namespace HistoryView {
  23. class StickerPlayer;
  24. } // namespace HistoryView
  25. namespace Data {
  26. class ForumTopic;
  27. } // namespace Data
  28. namespace Info {
  29. class Controller;
  30. class Section;
  31. } // namespace Info
  32. namespace style {
  33. struct InfoProfileCover;
  34. } // namespace style
  35. namespace Info::Profile {
  36. class EmojiStatusPanel;
  37. class Badge;
  38. class TopicIconView final {
  39. public:
  40. TopicIconView(
  41. not_null<Data::ForumTopic*> topic,
  42. Fn<bool()> paused,
  43. Fn<void()> update);
  44. TopicIconView(
  45. not_null<Data::ForumTopic*> topic,
  46. Fn<bool()> paused,
  47. Fn<void()> update,
  48. const style::color &generalIconFg);
  49. void paintInRect(QPainter &p, QRect rect);
  50. private:
  51. using StickerPlayer = HistoryView::StickerPlayer;
  52. void setup(not_null<Data::ForumTopic*> topic);
  53. void setupPlayer(not_null<Data::ForumTopic*> topic);
  54. void setupImage(not_null<Data::ForumTopic*> topic);
  55. const not_null<Data::ForumTopic*> _topic;
  56. const style::color &_generalIconFg;
  57. Fn<bool()> _paused;
  58. Fn<void()> _update;
  59. std::shared_ptr<StickerPlayer> _player;
  60. bool _playerUsesTextColor = false;
  61. QImage _image;
  62. rpl::lifetime _lifetime;
  63. };
  64. class TopicIconButton final : public Ui::AbstractButton {
  65. public:
  66. TopicIconButton(
  67. QWidget *parent,
  68. not_null<Window::SessionController*> controller,
  69. not_null<Data::ForumTopic*> topic);
  70. TopicIconButton(
  71. QWidget *parent,
  72. not_null<Data::ForumTopic*> topic,
  73. Fn<bool()> paused);
  74. private:
  75. TopicIconView _view;
  76. };
  77. class Cover final : public Ui::FixedHeightWidget {
  78. public:
  79. enum class Role {
  80. Info,
  81. EditContact,
  82. };
  83. Cover(
  84. QWidget *parent,
  85. not_null<Window::SessionController*> controller,
  86. not_null<PeerData*> peer,
  87. Fn<not_null<QWidget*>()> parentForTooltip = nullptr);
  88. Cover(
  89. QWidget *parent,
  90. not_null<Window::SessionController*> controller,
  91. not_null<Data::ForumTopic*> topic);
  92. Cover(
  93. QWidget *parent,
  94. not_null<Window::SessionController*> controller,
  95. not_null<PeerData*> peer,
  96. Role role,
  97. rpl::producer<QString> title);
  98. ~Cover();
  99. Cover *setOnlineCount(rpl::producer<int> &&count);
  100. [[nodiscard]] rpl::producer<Section> showSection() const {
  101. return _showSection.events();
  102. }
  103. [[nodiscard]] std::optional<QImage> updatedPersonalPhoto() const;
  104. private:
  105. class BadgeTooltip;
  106. Cover(
  107. QWidget *parent,
  108. not_null<Window::SessionController*> controller,
  109. not_null<PeerData*> peer,
  110. Data::ForumTopic *topic,
  111. Role role,
  112. rpl::producer<QString> title,
  113. Fn<not_null<QWidget*>()> parentForTooltip);
  114. void setupShowLastSeen();
  115. void setupChildGeometry();
  116. void initViewers(rpl::producer<QString> title);
  117. void refreshStatusText();
  118. void refreshNameGeometry(int newWidth);
  119. void refreshStatusGeometry(int newWidth);
  120. void refreshUploadPhotoOverlay();
  121. void setupUniqueBadgeTooltip();
  122. void setupChangePersonal();
  123. void hideBadgeTooltip();
  124. const style::InfoProfileCover &_st;
  125. const Role _role = Role::Info;
  126. const not_null<Window::SessionController*> _controller;
  127. const not_null<PeerData*> _peer;
  128. const std::unique_ptr<EmojiStatusPanel> _emojiStatusPanel;
  129. const std::unique_ptr<Badge> _botVerify;
  130. rpl::variable<Badge::Content> _badgeContent;
  131. const std::unique_ptr<Badge> _badge;
  132. const std::unique_ptr<Badge> _verified;
  133. rpl::variable<int> _onlineCount;
  134. const Fn<not_null<QWidget*>()> _parentForTooltip;
  135. std::unique_ptr<BadgeTooltip> _badgeTooltip;
  136. std::vector<std::unique_ptr<BadgeTooltip>> _badgeOldTooltips;
  137. base::Timer _badgeTooltipHide;
  138. uint64 _badgeCollectibleId = 0;
  139. const object_ptr<Ui::UserpicButton> _userpic;
  140. Ui::UserpicButton *_changePersonal = nullptr;
  141. std::optional<QImage> _personalChosen;
  142. object_ptr<TopicIconButton> _iconButton;
  143. object_ptr<Ui::FlatLabel> _name = { nullptr };
  144. object_ptr<Ui::FlatLabel> _status = { nullptr };
  145. object_ptr<Ui::RoundButton> _showLastSeen = { nullptr };
  146. //object_ptr<CoverDropArea> _dropArea = { nullptr };
  147. base::Timer _refreshStatusTimer;
  148. rpl::event_stream<Section> _showSection;
  149. };
  150. } // namespace Info::Profile