info_media_widget.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/info_content_widget.h"
  9. #include "storage/storage_shared_media.h"
  10. #include "data/data_search_controller.h"
  11. namespace Data {
  12. class ForumTopic;
  13. } // namespace Data
  14. namespace Info::Media {
  15. using Type = Storage::SharedMediaType;
  16. std::optional<int> TypeToTabIndex(Type type);
  17. Type TabIndexToType(int index);
  18. class InnerWidget;
  19. class Memento final : public ContentMemento {
  20. public:
  21. explicit Memento(not_null<Controller*> controller);
  22. Memento(not_null<PeerData*> peer, PeerId migratedPeerId, Type type);
  23. Memento(not_null<Data::ForumTopic*> topic, Type type);
  24. using SearchState = Api::DelayedSearchController::SavedState;
  25. object_ptr<ContentWidget> createWidget(
  26. QWidget *parent,
  27. not_null<Controller*> controller,
  28. const QRect &geometry) override;
  29. [[nodiscard]] Section section() const override;
  30. [[nodiscard]] Type type() const {
  31. return _type;
  32. }
  33. // Only for media, not for downloads.
  34. void setAroundId(FullMsgId aroundId) {
  35. _aroundId = aroundId;
  36. }
  37. [[nodiscard]] FullMsgId aroundId() const {
  38. return _aroundId;
  39. }
  40. void setIdsLimit(int limit) {
  41. _idsLimit = limit;
  42. }
  43. [[nodiscard]] int idsLimit() const {
  44. return _idsLimit;
  45. }
  46. void setScrollTopItem(GlobalMsgId item) {
  47. _scrollTopItem = item;
  48. }
  49. [[nodiscard]] GlobalMsgId scrollTopItem() const {
  50. return _scrollTopItem;
  51. }
  52. void setScrollTopItemPosition(int64 position) {
  53. _scrollTopItemPosition = position;
  54. }
  55. [[nodiscard]] int64 scrollTopItemPosition() const {
  56. return _scrollTopItemPosition;
  57. }
  58. void setScrollTopShift(int shift) {
  59. _scrollTopShift = shift;
  60. }
  61. [[nodiscard]] int scrollTopShift() const {
  62. return _scrollTopShift;
  63. }
  64. void setSearchState(SearchState &&state) {
  65. _searchState = std::move(state);
  66. }
  67. [[nodiscard]] SearchState searchState() {
  68. return std::move(_searchState);
  69. }
  70. private:
  71. Memento(
  72. not_null<PeerData*> peer,
  73. Data::ForumTopic *topic,
  74. PeerId migratedPeerId,
  75. Type type);
  76. Type _type = Type::Photo;
  77. FullMsgId _aroundId;
  78. int _idsLimit = 0;
  79. int64 _scrollTopItemPosition = 0;
  80. GlobalMsgId _scrollTopItem;
  81. int _scrollTopShift = 0;
  82. SearchState _searchState;
  83. };
  84. class Widget final : public ContentWidget {
  85. public:
  86. Widget(
  87. QWidget *parent,
  88. not_null<Controller*> controller);
  89. void setIsStackBottom(bool isStackBottom) override;
  90. bool showInternal(
  91. not_null<ContentMemento*> memento) override;
  92. void setInternalState(
  93. const QRect &geometry,
  94. not_null<Memento*> memento);
  95. rpl::producer<SelectedItems> selectedListValue() const override;
  96. void selectionAction(SelectionAction action) override;
  97. rpl::producer<QString> title() override;
  98. private:
  99. void saveState(not_null<Memento*> memento);
  100. void restoreState(not_null<Memento*> memento);
  101. std::shared_ptr<ContentMemento> doCreateMemento() override;
  102. InnerWidget *_inner = nullptr;
  103. };
  104. } // namespace Info::Media