dialogs_topics_view.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. class Painter;
  9. namespace style {
  10. struct DialogRow;
  11. } // namespace style
  12. namespace Data {
  13. class Forum;
  14. class ForumTopic;
  15. } // namespace Data
  16. namespace Ui {
  17. class RippleAnimation;
  18. } // namespace Ui
  19. namespace Dialogs::Ui {
  20. using namespace ::Ui;
  21. struct PaintContext;
  22. struct TopicJumpCache;
  23. struct TopicJumpCorners;
  24. struct JumpToLastBg {
  25. not_null<const style::DialogRow*> st;
  26. not_null<TopicJumpCorners*> corners;
  27. QRect geometry;
  28. const style::color &bg;
  29. int width1 = 0;
  30. int width2 = 0;
  31. };
  32. struct JumpToLastGeometry {
  33. int rightCut = 0;
  34. QRect area1;
  35. QRect area2;
  36. friend inline bool operator==(
  37. const JumpToLastGeometry&,
  38. const JumpToLastGeometry&) = default;
  39. };
  40. JumpToLastGeometry FillJumpToLastBg(QPainter &p, JumpToLastBg context);
  41. struct JumpToLastPrepared {
  42. not_null<const style::DialogRow*> st;
  43. not_null<TopicJumpCorners*> corners;
  44. const style::color &bg;
  45. const JumpToLastGeometry &prepared;
  46. };
  47. void FillJumpToLastPrepared(QPainter &p, JumpToLastPrepared context);
  48. class TopicsView final {
  49. public:
  50. explicit TopicsView(not_null<Data::Forum*> forum);
  51. ~TopicsView();
  52. [[nodiscard]] not_null<Data::Forum*> forum() const {
  53. return _forum;
  54. }
  55. [[nodiscard]] bool prepared() const;
  56. void prepare(MsgId frontRootId, Fn<void()> customEmojiRepaint);
  57. [[nodiscard]] int jumpToTopicWidth() const;
  58. void paint(
  59. Painter &p,
  60. const QRect &geometry,
  61. const PaintContext &context) const;
  62. bool changeTopicJumpGeometry(JumpToLastGeometry geometry);
  63. void clearTopicJumpGeometry();
  64. [[nodiscard]] bool isInTopicJumpArea(int x, int y) const;
  65. void addTopicJumpRipple(
  66. QPoint origin,
  67. not_null<TopicJumpCache*> topicJumpCache,
  68. Fn<void()> updateCallback);
  69. void paintRipple(
  70. QPainter &p,
  71. int x,
  72. int y,
  73. int outerWidth,
  74. const QColor *colorOverride) const;
  75. void stopLastRipple();
  76. void clearRipple();
  77. [[nodiscard]] rpl::lifetime &lifetime() {
  78. return _lifetime;
  79. }
  80. private:
  81. struct Title {
  82. Text::String title;
  83. MsgId topicRootId = 0;
  84. int version = -1;
  85. bool unread = false;
  86. };
  87. [[nodiscard]] QImage topicJumpRippleMask(
  88. not_null<TopicJumpCache*> topicJumpCache) const;
  89. const not_null<Data::Forum*> _forum;
  90. mutable std::vector<Title> _titles;
  91. mutable std::unique_ptr<RippleAnimation> _ripple;
  92. JumpToLastGeometry _lastTopicJumpGeometry;
  93. int _version = -1;
  94. bool _jumpToTopic = false;
  95. rpl::lifetime _lifetime;
  96. };
  97. } // namespace Dialogs::Ui