media_view_group_thumbs.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "history/history_item_components.h"
  9. #include "ui/effects/animations.h"
  10. #include "base/weak_ptr.h"
  11. class SharedMediaWithLastSlice;
  12. class UserPhotosSlice;
  13. struct WebPageCollage;
  14. namespace Data {
  15. struct Invoice;
  16. } // namespace Data
  17. namespace Main {
  18. class Session;
  19. } // namespace Main
  20. namespace Media {
  21. namespace View {
  22. class GroupThumbs : public base::has_weak_ptr {
  23. public:
  24. struct CollageKey {
  25. int index = 0;
  26. inline bool operator<(const CollageKey &other) const {
  27. return index < other.index;
  28. }
  29. };
  30. struct CollageSlice {
  31. FullMsgId context;
  32. not_null<const WebPageCollage*> data;
  33. int size() const;
  34. };
  35. using Key = std::variant<PhotoId, FullMsgId, CollageKey>;
  36. static void Refresh(
  37. not_null<Main::Session*> session,
  38. std::unique_ptr<GroupThumbs> &instance,
  39. const SharedMediaWithLastSlice &slice,
  40. int index,
  41. int availableWidth);
  42. static void Refresh(
  43. not_null<Main::Session*> session,
  44. std::unique_ptr<GroupThumbs> &instance,
  45. const UserPhotosSlice &slice,
  46. int index,
  47. int availableWidth);
  48. static void Refresh(
  49. not_null<Main::Session*> session,
  50. std::unique_ptr<GroupThumbs> &instance,
  51. const CollageSlice &slice,
  52. int index,
  53. int availableWidth);
  54. void clear();
  55. void resizeToWidth(int newWidth);
  56. int height() const;
  57. bool hiding() const;
  58. bool hidden() const;
  59. void checkForAnimationStart();
  60. void paint(QPainter &p, int x, int y, int outerWidth);
  61. ClickHandlerPtr getState(QPoint point) const;
  62. rpl::producer<QRect> updateRequests() const {
  63. return _updateRequests.events();
  64. }
  65. rpl::producer<Key> activateRequests() const {
  66. return _activateStream.events();
  67. }
  68. rpl::lifetime &lifetime() {
  69. return _lifetime;
  70. }
  71. using Context = std::variant<
  72. v::null_t,
  73. PeerId,
  74. MessageGroupId,
  75. FullMsgId>;
  76. GroupThumbs(not_null<Main::Session*> session, Context context);
  77. ~GroupThumbs();
  78. private:
  79. class Thumb;
  80. template <typename Slice>
  81. static void RefreshFromSlice(
  82. not_null<Main::Session*> session,
  83. std::unique_ptr<GroupThumbs> &instance,
  84. const Slice &slice,
  85. int index,
  86. int availableWidth);
  87. template <typename Slice>
  88. void fillItems(const Slice &slice, int from, int index, int till);
  89. void updateContext(Context context);
  90. void markCacheStale();
  91. not_null<Thumb*> validateCacheEntry(Key key);
  92. std::unique_ptr<Thumb> createThumb(Key key);
  93. std::unique_ptr<Thumb> createThumb(
  94. Key key,
  95. const WebPageCollage &collage,
  96. int index);
  97. std::unique_ptr<Thumb> createThumb(
  98. Key key,
  99. const Data::Invoice &invoice,
  100. int index);
  101. std::unique_ptr<Thumb> createThumb(Key key, not_null<PhotoData*> photo);
  102. std::unique_ptr<Thumb> createThumb(
  103. Key key,
  104. not_null<DocumentData*> document);
  105. std::unique_ptr<Thumb> createThumb(Key key, std::nullptr_t);
  106. void update();
  107. void countUpdatedRect();
  108. void animateAliveItems(int current);
  109. void fillDyingItems(const std::vector<not_null<Thumb*>> &old);
  110. void markAsDying(not_null<Thumb*> thumb);
  111. void markRestAsDying();
  112. void animatePreviouslyAlive(const std::vector<not_null<Thumb*>> &old);
  113. void startDelayedAnimation();
  114. const not_null<Main::Session*> _session;
  115. Context _context;
  116. bool _waitingForAnimationStart = true;
  117. Ui::Animations::Simple _animation;
  118. std::vector<not_null<Thumb*>> _items;
  119. std::vector<not_null<Thumb*>> _dying;
  120. base::flat_map<Key, std::unique_ptr<Thumb>> _cache;
  121. int _width = 0;
  122. QRect _updatedRect;
  123. rpl::event_stream<QRect> _updateRequests;
  124. rpl::event_stream<Key> _activateStream;
  125. rpl::lifetime _lifetime;
  126. };
  127. } // namespace View
  128. } // namespace Media