stickers_box.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/layers/box_content.h"
  9. #include "base/timer.h"
  10. #include "mtproto/sender.h"
  11. #include "data/stickers/data_stickers_set.h"
  12. #include "ui/effects/animations.h"
  13. namespace style {
  14. struct RippleAnimation;
  15. struct PeerListItem;
  16. } // namespace style
  17. namespace Ui {
  18. class PlainShadow;
  19. class RippleAnimation;
  20. class SettingsSlider;
  21. class SlideAnimation;
  22. class CrossButton;
  23. class BoxContentDivider;
  24. } // namespace Ui
  25. namespace ChatHelpers {
  26. class Show;
  27. } // namespace ChatHelpers
  28. namespace Main {
  29. class Session;
  30. } // namespace Main
  31. namespace Data {
  32. class DocumentMedia;
  33. enum class StickersType : uchar;
  34. } // namespace Data
  35. namespace Lottie {
  36. class SinglePlayer;
  37. } // namespace Lottie
  38. namespace Stickers {
  39. class Set;
  40. } // namespace Stickers
  41. class StickersBox final : public Ui::BoxContent {
  42. public:
  43. enum class Section {
  44. Installed,
  45. Featured,
  46. Archived,
  47. Attached,
  48. Masks,
  49. };
  50. StickersBox(
  51. QWidget*,
  52. std::shared_ptr<ChatHelpers::Show> show,
  53. Section section,
  54. bool masks = false);
  55. StickersBox(
  56. QWidget*,
  57. std::shared_ptr<ChatHelpers::Show> show,
  58. not_null<ChannelData*> megagroup,
  59. bool isEmoji);
  60. StickersBox(
  61. QWidget*,
  62. std::shared_ptr<ChatHelpers::Show> show,
  63. const QVector<MTPStickerSetCovered> &attachedSets);
  64. StickersBox(
  65. QWidget*,
  66. std::shared_ptr<ChatHelpers::Show> show,
  67. const std::vector<StickerSetIdentifier> &emojiSets);
  68. ~StickersBox();
  69. [[nodiscard]] Main::Session &session() const;
  70. void setInnerFocus() override;
  71. protected:
  72. void prepare() override;
  73. void resizeEvent(QResizeEvent *e) override;
  74. void paintEvent(QPaintEvent *e) override;
  75. private:
  76. class Inner;
  77. class Tab {
  78. public:
  79. Tab() = default;
  80. template <typename ...Args>
  81. Tab(int index, Args&&... args);
  82. object_ptr<Inner> takeWidget();
  83. void returnWidget(object_ptr<Inner> widget);
  84. [[nodiscard]] Inner *widget() const;
  85. [[nodiscard]] int index() const;
  86. void saveScrollTop();
  87. int scrollTop() const {
  88. return _scrollTop;
  89. }
  90. private:
  91. const int _index = 0;
  92. object_ptr<Inner> _widget = { nullptr };
  93. QPointer<Inner> _weak;
  94. int _scrollTop = 0;
  95. };
  96. void handleStickersUpdated();
  97. void refreshTabs();
  98. void rebuildList(Tab *tab = nullptr);
  99. void updateTabsGeometry();
  100. void switchTab();
  101. void installSet(uint64 setId);
  102. int topSkip() const;
  103. void saveChanges();
  104. QPixmap grabContentCache();
  105. void installDone(const MTPmessages_StickerSetInstallResult &result) const;
  106. void installFail(const MTP::Error &error, uint64 setId);
  107. void preloadArchivedSets();
  108. void requestArchivedSets();
  109. void loadMoreArchived();
  110. void getArchivedDone(
  111. const MTPmessages_ArchivedStickers &result,
  112. uint64 offsetId);
  113. void showAttachedStickers();
  114. const Data::StickersSetsOrder &archivedSetsOrder() const;
  115. Data::StickersSetsOrder &archivedSetsOrderRef() const;
  116. std::array<Inner*, 5> widgets() const;
  117. const style::PeerListItem &_st;
  118. const std::shared_ptr<ChatHelpers::Show> _show;
  119. const not_null<Main::Session*> _session;
  120. MTP::Sender _api;
  121. object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
  122. QList<Section> _tabIndices;
  123. bool _ignoreTabActivation = false;
  124. class CounterWidget;
  125. object_ptr<CounterWidget> _unreadBadge = { nullptr };
  126. Section _section;
  127. const bool _isMasks;
  128. const bool _isEmoji;
  129. Tab _installed;
  130. Tab _masks;
  131. Tab _featured;
  132. Tab _archived;
  133. Tab _attached;
  134. Tab *_tab = nullptr;
  135. const Data::StickersType _attachedType = {};
  136. const QVector<MTPStickerSetCovered> _attachedSets;
  137. const std::vector<StickerSetIdentifier> _emojiSets;
  138. ChannelData *_megagroupSet = nullptr;
  139. std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
  140. object_ptr<Ui::PlainShadow> _titleShadow = { nullptr };
  141. mtpRequestId _archivedRequestId = 0;
  142. bool _archivedLoaded = false;
  143. bool _allArchivedLoaded = false;
  144. bool _someArchivedLoaded = false;
  145. Data::StickersSetsOrder _localOrder;
  146. Data::StickersSetsOrder _localRemoved;
  147. };