mainwidget.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 "base/weak_ptr.h"
  9. #include "media/player/media_player_float.h"
  10. #include "mtproto/sender.h"
  11. class HistoryWidget;
  12. class StackItem;
  13. class Image;
  14. namespace Bot {
  15. struct SendCommandRequest;
  16. } // namespace Bot
  17. namespace SendMenu {
  18. struct Details;
  19. } // namespace SendMenu
  20. namespace Main {
  21. class Session;
  22. } // namespace Main
  23. namespace Data {
  24. class Thread;
  25. class WallPaper;
  26. struct ForwardDraft;
  27. class Forum;
  28. struct ReportInput;
  29. } // namespace Data
  30. namespace Dialogs {
  31. struct RowDescriptor;
  32. class Row;
  33. class Key;
  34. class Widget;
  35. } // namespace Dialogs
  36. namespace Media {
  37. namespace Player {
  38. class Widget;
  39. class Panel;
  40. struct TrackState;
  41. } // namespace Player
  42. } // namespace Media
  43. namespace Export {
  44. namespace View {
  45. class TopBar;
  46. class PanelController;
  47. struct Content;
  48. } // namespace View
  49. } // namespace Export
  50. namespace Ui {
  51. class ChatTheme;
  52. class ResizeArea;
  53. class PlainShadow;
  54. template <typename Widget>
  55. class SlideWrap;
  56. } // namespace Ui
  57. namespace Window {
  58. class SessionController;
  59. template <typename Inner>
  60. class TopBarWrapWidget;
  61. class SectionMemento;
  62. class SectionWidget;
  63. class SlideAnimation;
  64. class ConnectionState;
  65. struct SectionSlideParams;
  66. struct SectionShow;
  67. enum class Column;
  68. class HistoryHider;
  69. struct SeparateId;
  70. } // namespace Window
  71. namespace Calls {
  72. class Call;
  73. class GroupCall;
  74. class TopBar;
  75. } // namespace Calls
  76. namespace Core {
  77. class Changelogs;
  78. } // namespace Core
  79. class MainWidget final
  80. : public Ui::RpWidget
  81. , private Media::Player::FloatDelegate {
  82. public:
  83. using SectionShow = Window::SectionShow;
  84. MainWidget(
  85. QWidget *parent,
  86. not_null<Window::SessionController*> controller);
  87. ~MainWidget();
  88. [[nodiscard]] Main::Session &session() const;
  89. [[nodiscard]] not_null<Window::SessionController*> controller() const;
  90. [[nodiscard]] Window::SeparateId windowId() const;
  91. [[nodiscard]] bool isPrimary() const;
  92. [[nodiscard]] bool isMainSectionShown() const;
  93. [[nodiscard]] bool isThirdSectionShown() const;
  94. [[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
  95. Dialogs::RowDescriptor from) const;
  96. [[nodiscard]] Dialogs::RowDescriptor resolveChatPrevious(
  97. Dialogs::RowDescriptor from) const;
  98. void returnTabbedSelector();
  99. void showAnimated(QPixmap oldContentCache, bool back = false);
  100. void activate();
  101. void windowShown();
  102. void dialogsToUp();
  103. void checkActivation();
  104. [[nodiscard]] PeerData *peer() const;
  105. [[nodiscard]] Ui::ChatTheme *customChatTheme() const;
  106. int backgroundFromY() const;
  107. void showSection(
  108. std::shared_ptr<Window::SectionMemento> memento,
  109. const SectionShow &params);
  110. void updateColumnLayout();
  111. bool stackIsEmpty() const;
  112. bool showBackFromStack(const SectionShow &params);
  113. void orderWidgets();
  114. QPixmap grabForShowAnimation(const Window::SectionSlideParams &params);
  115. void checkMainSectionToLayer();
  116. [[nodiscard]] SendMenu::Details sendMenuDetails() const;
  117. [[nodiscard]] bool animatingShow() const;
  118. void showDragForwardInfo();
  119. void hideDragForwardInfo();
  120. bool setForwardDraft(
  121. not_null<Data::Thread*> thread,
  122. Data::ForwardDraft &&draft);
  123. bool sendPaths(
  124. not_null<Data::Thread*> thread,
  125. const QStringList &paths);
  126. bool shareUrl(
  127. not_null<Data::Thread*> thread,
  128. const QString &url,
  129. const QString &text) const;
  130. bool filesOrForwardDrop(
  131. not_null<Data::Thread*> thread,
  132. not_null<const QMimeData*> data);
  133. void sendBotCommand(Bot::SendCommandRequest request);
  134. void hideSingleUseKeyboard(FullMsgId replyToId);
  135. void searchMessages(
  136. const QString &query,
  137. Dialogs::Key inChat,
  138. PeerData *searchFrom = nullptr);
  139. void setChatBackground(
  140. const Data::WallPaper &background,
  141. QImage &&image = QImage());
  142. bool chatBackgroundLoading();
  143. float64 chatBackgroundProgress() const;
  144. void checkChatBackground();
  145. Image *newBackgroundThumb();
  146. void setInnerFocus();
  147. bool contentOverlapped(const QRect &globalRect);
  148. void showChooseReportMessages(
  149. not_null<PeerData*> peer,
  150. Data::ReportInput reportInput,
  151. Fn<void(std::vector<MsgId>)> done);
  152. void clearChooseReportMessages();
  153. void toggleChooseChatTheme(
  154. not_null<PeerData*> peer,
  155. std::optional<bool> show);
  156. void showHistory(
  157. PeerId peer,
  158. const SectionShow &params,
  159. MsgId msgId);
  160. void showMessage(
  161. not_null<const HistoryItem*> item,
  162. const SectionShow &params);
  163. void showForum(not_null<Data::Forum*> forum, const SectionShow &params);
  164. bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
  165. using FloatDelegate::floatPlayerAreaUpdated;
  166. void stopAndClosePlayer();
  167. bool preventsCloseSection(Fn<void()> callback) const;
  168. bool preventsCloseSection(
  169. Fn<void()> callback,
  170. const SectionShow &params) const;
  171. void showNonPremiumLimitToast(bool download);
  172. void dialogsCancelled();
  173. void toggleFiltersMenu(bool value) const;
  174. private:
  175. void paintEvent(QPaintEvent *e) override;
  176. void resizeEvent(QResizeEvent *e) override;
  177. bool eventFilter(QObject *o, QEvent *e) override;
  178. [[nodiscard]] bool relevantForDialogsFocus(
  179. not_null<QWidget*> widget) const;
  180. void showFinished();
  181. void handleAdaptiveLayoutUpdate();
  182. void updateWindowAdaptiveLayout();
  183. void handleAudioUpdate(const Media::Player::TrackState &state);
  184. void updateMediaPlaylistPosition(int x);
  185. void updateControlsGeometry();
  186. void updateMainSectionShown();
  187. void updateDialogsWidthAnimated();
  188. void updateThirdColumnToCurrentChat(
  189. Dialogs::Key key,
  190. bool canWrite);
  191. [[nodiscard]] bool saveThirdSectionToStackBack() const;
  192. [[nodiscard]] auto thirdSectionForCurrentMainSection(Dialogs::Key key)
  193. -> std::shared_ptr<Window::SectionMemento>;
  194. void setupConnectingWidget();
  195. void createPlayer();
  196. void playerHeightUpdated();
  197. void setCurrentCall(Calls::Call *call);
  198. void setCurrentGroupCall(Calls::GroupCall *call);
  199. void createCallTopBar();
  200. void destroyCallTopBar();
  201. void callTopBarHeightUpdated(int callTopBarHeight);
  202. void setCurrentExportView(Export::View::PanelController *view);
  203. void createExportTopBar(Export::View::Content &&data);
  204. void destroyExportTopBar();
  205. void exportTopBarHeightUpdated();
  206. Window::SectionSlideParams prepareShowAnimation(
  207. bool willHaveTopBarShadow);
  208. void showNewSection(
  209. std::shared_ptr<Window::SectionMemento> memento,
  210. const SectionShow &params);
  211. void destroyThirdSection();
  212. Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);
  213. // All this methods use the prepareShowAnimation().
  214. Window::SectionSlideParams prepareMainSectionAnimation(Window::SectionWidget *section);
  215. Window::SectionSlideParams prepareHistoryAnimation(PeerId historyPeerId);
  216. Window::SectionSlideParams prepareDialogsAnimation();
  217. bool saveSectionInStack(
  218. const SectionShow &params,
  219. Window::SectionWidget *newMainSection = nullptr);
  220. int getMainSectionTop() const;
  221. int getThirdSectionTop() const;
  222. void hideAll();
  223. void showAll();
  224. void hiderLayer(base::unique_qptr<Window::HistoryHider> h);
  225. void clearHider(not_null<Window::HistoryHider*> instance);
  226. void closeBothPlayers();
  227. [[nodiscard]] auto floatPlayerDelegate()
  228. -> not_null<Media::Player::FloatDelegate*>;
  229. not_null<Ui::RpWidget*> floatPlayerWidget() override;
  230. void floatPlayerToggleGifsPaused(bool paused) override;
  231. not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
  232. Window::Column column) override;
  233. void floatPlayerEnumerateSections(Fn<void(
  234. not_null<Media::Player::FloatSectionDelegate*> widget,
  235. Window::Column widgetColumn)> callback) override;
  236. bool floatPlayerIsVisible(not_null<HistoryItem*> item) override;
  237. void floatPlayerClosed(FullMsgId itemId);
  238. void floatPlayerDoubleClickEvent(
  239. not_null<const HistoryItem*> item) override;
  240. void refreshResizeAreas();
  241. template <typename MoveCallback, typename FinishCallback>
  242. void createResizeArea(
  243. object_ptr<Ui::ResizeArea> &area,
  244. MoveCallback &&moveCallback,
  245. FinishCallback &&finishCallback);
  246. void ensureFirstColumnResizeAreaCreated();
  247. void ensureThirdColumnResizeAreaCreated();
  248. bool isReadyChatBackground(
  249. const Data::WallPaper &background,
  250. const QImage &image) const;
  251. void setReadyChatBackground(
  252. const Data::WallPaper &background,
  253. QImage &&image);
  254. void handleHistoryBack();
  255. bool showHistoryInDifferentWindow(
  256. PeerId peerId,
  257. const SectionShow &params,
  258. MsgId showAtMsgId);
  259. bool isOneColumn() const;
  260. bool isNormalColumn() const;
  261. bool isThreeColumn() const;
  262. const not_null<Window::SessionController*> _controller;
  263. std::unique_ptr<Window::SlideAnimation> _showAnimation;
  264. int _dialogsWidth = 0;
  265. int _thirdColumnWidth = 0;
  266. Ui::Animations::Simple _a_dialogsWidth;
  267. const base::unique_qptr<Dialogs::Widget> _dialogs;
  268. const base::unique_qptr<HistoryWidget> _history;
  269. object_ptr<Window::SectionWidget> _mainSection = { nullptr };
  270. object_ptr<Window::SectionWidget> _thirdSection = { nullptr };
  271. std::shared_ptr<Window::SectionMemento> _thirdSectionFromStack;
  272. std::unique_ptr<Window::ConnectionState> _connecting;
  273. const base::unique_qptr<Ui::PlainShadow> _sideShadow;
  274. object_ptr<Ui::PlainShadow> _thirdShadow = { nullptr };
  275. object_ptr<Ui::ResizeArea> _firstColumnResizeArea = { nullptr };
  276. object_ptr<Ui::ResizeArea> _thirdColumnResizeArea = { nullptr };
  277. base::weak_ptr<Calls::Call> _currentCall;
  278. base::weak_ptr<Calls::GroupCall> _currentGroupCall;
  279. rpl::lifetime _currentCallLifetime;
  280. object_ptr<Ui::SlideWrap<Calls::TopBar>> _callTopBar = { nullptr };
  281. Export::View::PanelController *_currentExportView = nullptr;
  282. object_ptr<Window::TopBarWrapWidget<Export::View::TopBar>> _exportTopBar
  283. = { nullptr };
  284. rpl::lifetime _exportViewLifetime;
  285. object_ptr<Window::TopBarWrapWidget<Media::Player::Widget>> _player
  286. = { nullptr };
  287. object_ptr<Media::Player::Panel> _playerPlaylist;
  288. base::unique_qptr<Window::HistoryHider> _hider;
  289. std::vector<std::unique_ptr<StackItem>> _stack;
  290. int _playerHeight = 0;
  291. int _callTopBarHeight = 0;
  292. int _exportTopBarHeight = 0;
  293. int _contentScrollAddToY = 0;
  294. struct SettingBackground;
  295. std::unique_ptr<SettingBackground> _background;
  296. // _changelogs depends on _data, subscribes on chats loading event.
  297. const std::unique_ptr<Core::Changelogs> _changelogs;
  298. };