dialogs_row.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "ui/effects/animations.h"
  9. #include "ui/text/text.h"
  10. #include "ui/unread_badge.h"
  11. #include "ui/userpic_view.h"
  12. #include "dialogs/dialogs_key.h"
  13. #include "dialogs/ui/dialogs_message_view.h"
  14. class History;
  15. class HistoryItem;
  16. namespace style {
  17. struct DialogRow;
  18. } // namespace style
  19. namespace Ui {
  20. class RippleAnimation;
  21. } // namespace Ui
  22. namespace Dialogs::Ui {
  23. using namespace ::Ui;
  24. class RowPainter;
  25. class VideoUserpic;
  26. struct PaintContext;
  27. struct TopicJumpCache;
  28. } // namespace Dialogs::Ui
  29. namespace Dialogs {
  30. class Entry;
  31. enum class SortMode;
  32. [[nodiscard]] QRect CornerBadgeTTLRect(int photoSize);
  33. [[nodiscard]] QImage BlurredDarkenedPart(QImage image, QRect part);
  34. class BasicRow {
  35. public:
  36. BasicRow();
  37. virtual ~BasicRow();
  38. virtual void paintUserpic(
  39. Painter &p,
  40. not_null<Entry*> entry,
  41. PeerData *peer,
  42. Ui::VideoUserpic *videoUserpic,
  43. const Ui::PaintContext &context,
  44. bool hasUnreadBadgesAbove) const;
  45. void addRipple(QPoint origin, QSize size, Fn<void()> updateCallback);
  46. virtual void stopLastRipple();
  47. virtual void clearRipple();
  48. void addRippleWithMask(
  49. QPoint origin,
  50. QImage mask,
  51. Fn<void()> updateCallback);
  52. void paintRipple(
  53. QPainter &p,
  54. int x,
  55. int y,
  56. int outerWidth,
  57. const QColor *colorOverride = nullptr) const;
  58. [[nodiscard]] Ui::PeerUserpicView &userpicView() const {
  59. return _userpic;
  60. }
  61. private:
  62. mutable Ui::PeerUserpicView _userpic;
  63. mutable std::unique_ptr<Ui::RippleAnimation> _ripple;
  64. };
  65. class List;
  66. class Row final : public BasicRow {
  67. public:
  68. explicit Row(std::nullptr_t) {
  69. }
  70. Row(Key key, int index, int top);
  71. ~Row();
  72. [[nodiscard]] int top() const {
  73. return _top;
  74. }
  75. [[nodiscard]] int height() const {
  76. Expects(_height != 0);
  77. return _height;
  78. }
  79. void recountHeight(float64 narrowRatio, FilterId filterId);
  80. void updateCornerBadgeShown(
  81. not_null<PeerData*> peer,
  82. Fn<void()> updateCallback = nullptr,
  83. bool hasUnreadBadgesAbove = false) const;
  84. void paintUserpic(
  85. Painter &p,
  86. not_null<Entry*> entry,
  87. PeerData *peer,
  88. Ui::VideoUserpic *videoUserpic,
  89. const Ui::PaintContext &context,
  90. bool hasUnreadBadgesAbove) const final override;
  91. [[nodiscard]] bool lookupIsInTopicJump(int x, int y) const;
  92. void stopLastRipple() override;
  93. void clearRipple() override;
  94. void addTopicJumpRipple(
  95. QPoint origin,
  96. not_null<Ui::TopicJumpCache*> topicJumpCache,
  97. Fn<void()> updateCallback);
  98. void clearTopicJumpRipple();
  99. [[nodiscard]] bool topicJumpRipple() const;
  100. [[nodiscard]] Key key() const {
  101. return _id;
  102. }
  103. [[nodiscard]] History *history() const {
  104. return _id.history();
  105. }
  106. [[nodiscard]] Data::Folder *folder() const {
  107. return _id.folder();
  108. }
  109. [[nodiscard]] Data::ForumTopic *topic() const {
  110. return _id.topic();
  111. }
  112. [[nodiscard]] Data::Thread *thread() const {
  113. return _id.thread();
  114. }
  115. [[nodiscard]] Data::SavedSublist *sublist() const {
  116. return _id.sublist();
  117. }
  118. [[nodiscard]] not_null<Entry*> entry() const {
  119. return _id.entry();
  120. }
  121. [[nodiscard]] int index() const {
  122. return _index;
  123. }
  124. [[nodiscard]] uint64 sortKey(FilterId filterId) const;
  125. // for any attached data, for example View in contacts list
  126. void *attached = nullptr;
  127. private:
  128. friend class List;
  129. class CornerLayersManager {
  130. public:
  131. using Layer = int;
  132. CornerLayersManager();
  133. [[nodiscard]] bool isSameLayer(Layer layer) const;
  134. [[nodiscard]] bool isDisplayedNone() const;
  135. [[nodiscard]] float64 progressForLayer(Layer layer) const;
  136. [[nodiscard]] float64 progress() const;
  137. [[nodiscard]] bool isFinished() const;
  138. void setLayer(Layer layer, Fn<void()> updateCallback);
  139. void markFrameShown();
  140. private:
  141. bool _lastFrameShown = false;
  142. Layer _prevLayer = 0;
  143. Layer _nextLayer = 0;
  144. Ui::Animations::Simple _animation;
  145. };
  146. struct CornerBadgeUserpic {
  147. InMemoryKey key;
  148. CornerLayersManager layersManager;
  149. QImage frame;
  150. QImage cacheTTL;
  151. int frameIndex = -1;
  152. uint32 paletteVersion : 17 = 0;
  153. uint32 storiesCount : 7 = 0;
  154. uint32 storiesUnreadCount : 7 = 0;
  155. uint32 active : 1 = 0;
  156. };
  157. void setCornerBadgeShown(
  158. CornerLayersManager::Layer nextLayer,
  159. Fn<void()> updateCallback) const;
  160. void ensureCornerBadgeUserpic() const;
  161. static void PaintCornerBadgeFrame(
  162. not_null<CornerBadgeUserpic*> data,
  163. int framePadding,
  164. not_null<Entry*> entry,
  165. PeerData *peer,
  166. Ui::VideoUserpic *videoUserpic,
  167. Ui::PeerUserpicView &view,
  168. const Ui::PaintContext &context,
  169. bool subscribed);
  170. Key _id;
  171. mutable std::unique_ptr<CornerBadgeUserpic> _cornerBadgeUserpic;
  172. int _top = 0;
  173. int _height = 0;
  174. uint32 _index : 30 = 0;
  175. uint32 _cornerBadgeShown : 1 = 0;
  176. uint32 _topicJumpRipple : 1 = 0;
  177. };
  178. class FakeRow final : public BasicRow, public base::has_weak_ptr {
  179. public:
  180. FakeRow(
  181. Key searchInChat,
  182. not_null<HistoryItem*> item,
  183. Fn<void()> repaint);
  184. [[nodiscard]] Key searchInChat() const {
  185. return _searchInChat;
  186. }
  187. [[nodiscard]] Data::ForumTopic *topic() const {
  188. return _topic;
  189. }
  190. [[nodiscard]] not_null<HistoryItem*> item() const {
  191. return _item;
  192. }
  193. [[nodiscard]] Ui::MessageView &itemView() const {
  194. return _itemView;
  195. }
  196. [[nodiscard]] Fn<void()> repaint() const {
  197. return _repaint;
  198. }
  199. [[nodiscard]] Ui::PeerBadge &badge() const {
  200. return _badge;
  201. }
  202. [[nodiscard]] const Ui::Text::String &name() const;
  203. void invalidateTopic();
  204. private:
  205. friend class Ui::RowPainter;
  206. const Key _searchInChat;
  207. const not_null<HistoryItem*> _item;
  208. Data::ForumTopic *_topic = nullptr;
  209. const Fn<void()> _repaint;
  210. mutable Ui::MessageView _itemView;
  211. mutable Ui::PeerBadge _badge;
  212. mutable Ui::Text::String _name;
  213. };
  214. } // namespace Dialogs