info_media_common.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "overview/overview_layout.h"
  9. namespace Storage {
  10. enum class SharedMediaType : signed char;
  11. } // namespace Storage
  12. namespace Info::Media {
  13. using Type = Storage::SharedMediaType;
  14. using BaseLayout = Overview::Layout::ItemBase;
  15. class Memento;
  16. class ListSection;
  17. inline constexpr auto kPreloadIfLessThanScreens = 2;
  18. struct ListItemSelectionData {
  19. explicit ListItemSelectionData(TextSelection text) : text(text) {
  20. }
  21. TextSelection text;
  22. bool canDelete = false;
  23. bool canForward = false;
  24. bool canToggleStoryPin = false;
  25. bool canUnpinStory = false;
  26. friend inline bool operator==(
  27. ListItemSelectionData,
  28. ListItemSelectionData) = default;
  29. };
  30. using ListSelectedMap = base::flat_map<
  31. not_null<const HistoryItem*>,
  32. ListItemSelectionData,
  33. std::less<>>;
  34. enum class ListDragSelectAction {
  35. None,
  36. Selecting,
  37. Deselecting,
  38. };
  39. struct ListContext {
  40. Overview::Layout::PaintContext layoutContext;
  41. not_null<ListSelectedMap*> selected;
  42. not_null<ListSelectedMap*> dragSelected;
  43. ListDragSelectAction dragSelectAction = ListDragSelectAction::None;
  44. };
  45. struct ListScrollTopState {
  46. int64 position = 0; // ListProvider-specific.
  47. HistoryItem *item = nullptr;
  48. int shift = 0;
  49. };
  50. struct ListFoundItem {
  51. not_null<BaseLayout*> layout;
  52. QRect geometry;
  53. bool exact = false;
  54. };
  55. struct CachedItem {
  56. CachedItem(std::unique_ptr<BaseLayout> item) : item(std::move(item)) {
  57. };
  58. CachedItem(CachedItem &&other) = default;
  59. CachedItem &operator=(CachedItem &&other) = default;
  60. ~CachedItem() = default;
  61. std::unique_ptr<BaseLayout> item;
  62. bool stale = false;
  63. };
  64. using UniversalMsgId = MsgId;
  65. [[nodiscard]] UniversalMsgId GetUniversalId(FullMsgId itemId);
  66. [[nodiscard]] UniversalMsgId GetUniversalId(
  67. not_null<const HistoryItem*> item);
  68. [[nodiscard]] UniversalMsgId GetUniversalId(
  69. not_null<const BaseLayout*> layout);
  70. bool ChangeItemSelection(
  71. ListSelectedMap &selected,
  72. not_null<const HistoryItem*> item,
  73. ListItemSelectionData selectionData);
  74. class ListSectionDelegate {
  75. public:
  76. [[nodiscard]] virtual bool sectionHasFloatingHeader() = 0;
  77. [[nodiscard]] virtual QString sectionTitle(
  78. not_null<const BaseLayout*> item) = 0;
  79. [[nodiscard]] virtual bool sectionItemBelongsHere(
  80. not_null<const BaseLayout*> item,
  81. not_null<const BaseLayout*> previous) = 0;
  82. [[nodiscard]] not_null<ListSectionDelegate*> sectionDelegate() {
  83. return this;
  84. }
  85. };
  86. class ListProvider {
  87. public:
  88. [[nodiscard]] virtual Type type() = 0;
  89. [[nodiscard]] virtual bool hasSelectRestriction() = 0;
  90. [[nodiscard]] virtual auto hasSelectRestrictionChanges()
  91. ->rpl::producer<bool> = 0;
  92. [[nodiscard]] virtual bool isPossiblyMyItem(
  93. not_null<const HistoryItem*> item) = 0;
  94. [[nodiscard]] virtual std::optional<int> fullCount() = 0;
  95. virtual void restart() = 0;
  96. virtual void checkPreload(
  97. QSize viewport,
  98. not_null<BaseLayout*> topLayout,
  99. not_null<BaseLayout*> bottomLayout,
  100. bool preloadTop,
  101. bool preloadBottom) = 0;
  102. virtual void refreshViewer() = 0;
  103. [[nodiscard]] virtual rpl::producer<> refreshed() = 0;
  104. [[nodiscard]] virtual std::vector<ListSection> fillSections(
  105. not_null<Overview::Layout::Delegate*> delegate) = 0;
  106. [[nodiscard]] virtual auto layoutRemoved()
  107. -> rpl::producer<not_null<BaseLayout*>> = 0;
  108. [[nodiscard]] virtual BaseLayout *lookupLayout(
  109. const HistoryItem *item) = 0;
  110. [[nodiscard]] virtual bool isMyItem(
  111. not_null<const HistoryItem*> item) = 0;
  112. [[nodiscard]] virtual bool isAfter(
  113. not_null<const HistoryItem*> a,
  114. not_null<const HistoryItem*> b) = 0;
  115. [[nodiscard]] virtual ListItemSelectionData computeSelectionData(
  116. not_null<const HistoryItem*> item,
  117. TextSelection selection) = 0;
  118. virtual void applyDragSelection(
  119. ListSelectedMap &selected,
  120. not_null<const HistoryItem*> fromItem,
  121. bool skipFrom,
  122. not_null<const HistoryItem*> tillItem,
  123. bool skipTill) = 0;
  124. [[nodiscard]] virtual bool allowSaveFileAs(
  125. not_null<const HistoryItem*> item,
  126. not_null<DocumentData*> document) = 0;
  127. [[nodiscard]] virtual QString showInFolderPath(
  128. not_null<const HistoryItem*> item,
  129. not_null<DocumentData*> document) = 0;
  130. virtual void setSearchQuery(QString query) = 0;
  131. [[nodiscard]] virtual int64 scrollTopStatePosition(
  132. not_null<HistoryItem*> item) = 0;
  133. [[nodiscard]] virtual HistoryItem *scrollTopStateItem(
  134. ListScrollTopState state) = 0;
  135. virtual void saveState(
  136. not_null<Memento*> memento,
  137. ListScrollTopState scrollState) = 0;
  138. virtual void restoreState(
  139. not_null<Memento*> memento,
  140. Fn<void(ListScrollTopState)> restoreScrollState) = 0;
  141. virtual ~ListProvider() = default;
  142. };
  143. [[nodiscard]] int MinItemHeight(Type type, int width);
  144. } // namespace Info::Media