calls_group_panel.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 "base/timer.h"
  10. #include "base/flags.h"
  11. #include "base/object_ptr.h"
  12. #include "base/unique_qptr.h"
  13. #include "calls/group/calls_group_call.h"
  14. #include "calls/group/calls_group_common.h"
  15. #include "calls/group/calls_choose_join_as.h"
  16. #include "calls/group/ui/desktop_capture_choose_source.h"
  17. #include "ui/effects/animations.h"
  18. #include "ui/gl/gl_window.h"
  19. #include "ui/layers/show.h"
  20. #include "ui/rp_widget.h"
  21. class Image;
  22. namespace base {
  23. class PowerSaveBlocker;
  24. } // namespace base
  25. namespace Data {
  26. class PhotoMedia;
  27. class GroupCall;
  28. } // namespace Data
  29. namespace Ui {
  30. class BoxContent;
  31. class LayerWidget;
  32. enum class LayerOption;
  33. using LayerOptions = base::flags<LayerOption>;
  34. class AbstractButton;
  35. class ImportantTooltip;
  36. class DropdownMenu;
  37. class CallButton;
  38. class CallMuteButton;
  39. class IconButton;
  40. class FlatLabel;
  41. class RpWidget;
  42. template <typename Widget>
  43. class FadeWrap;
  44. template <typename Widget>
  45. class PaddingWrap;
  46. class ScrollArea;
  47. class GenericBox;
  48. class LayerManager;
  49. class GroupCallScheduledLeft;
  50. } // namespace Ui
  51. namespace Ui::Toast {
  52. class Instance;
  53. struct Config;
  54. } // namespace Ui::Toast
  55. namespace Ui::Platform {
  56. struct SeparateTitleControls;
  57. } // namespace Ui::Platform
  58. namespace Main {
  59. class SessionShow;
  60. } // namespace Main
  61. namespace style {
  62. struct CallSignalBars;
  63. struct CallBodyLayout;
  64. } // namespace style
  65. namespace Calls::Group {
  66. class Toasts;
  67. class Members;
  68. class Viewport;
  69. enum class PanelMode;
  70. enum class StickedTooltip;
  71. class MicLevelTester;
  72. class Panel final
  73. : public base::has_weak_ptr
  74. , private Ui::DesktopCapture::ChooseSourceDelegate {
  75. public:
  76. Panel(not_null<GroupCall*> call);
  77. ~Panel();
  78. [[nodiscard]] not_null<Ui::RpWidget*> widget() const;
  79. [[nodiscard]] not_null<GroupCall*> call() const;
  80. [[nodiscard]] bool isVisible() const;
  81. [[nodiscard]] bool isActive() const;
  82. base::weak_ptr<Ui::Toast::Instance> showToast(
  83. const QString &text,
  84. crl::time duration = 0);
  85. base::weak_ptr<Ui::Toast::Instance> showToast(
  86. TextWithEntities &&text,
  87. crl::time duration = 0);
  88. base::weak_ptr<Ui::Toast::Instance> showToast(
  89. Ui::Toast::Config &&config);
  90. void showBox(object_ptr<Ui::BoxContent> box);
  91. void showBox(
  92. object_ptr<Ui::BoxContent> box,
  93. Ui::LayerOptions options,
  94. anim::type animated = anim::type::normal);
  95. void showLayer(
  96. std::unique_ptr<Ui::LayerWidget> layer,
  97. Ui::LayerOptions options,
  98. anim::type animated = anim::type::normal);
  99. void hideLayer(anim::type animated = anim::type::normal);
  100. [[nodiscard]] bool isLayerShown() const;
  101. void minimize();
  102. void toggleFullScreen();
  103. void close();
  104. void showAndActivate();
  105. void closeBeforeDestroy();
  106. [[nodiscard]] std::shared_ptr<Main::SessionShow> uiShow();
  107. rpl::lifetime &lifetime();
  108. private:
  109. using State = GroupCall::State;
  110. struct ControlsBackgroundNarrow;
  111. enum class NiceTooltipType {
  112. Normal,
  113. Sticked,
  114. };
  115. enum class StickedTooltipHide {
  116. Unavailable,
  117. Activated,
  118. Discarded,
  119. };
  120. [[nodiscard]] not_null<Ui::RpWindow*> window() const;
  121. [[nodiscard]] PanelMode mode() const;
  122. void paint(QRect clip);
  123. void initWindow();
  124. void initWidget();
  125. void initControls();
  126. void initShareAction();
  127. void initLayout();
  128. void initGeometry();
  129. void setupScheduledLabels(rpl::producer<TimeId> date);
  130. void setupMembers();
  131. void setupVideo(not_null<Viewport*> viewport);
  132. void setupRealMuteButtonState(not_null<Data::GroupCall*> real);
  133. bool handleClose();
  134. void startScheduledNow();
  135. void trackControls(bool track, bool force = false);
  136. void raiseControls();
  137. void enlargeVideo();
  138. void trackControl(Ui::RpWidget *widget, rpl::lifetime &lifetime);
  139. void trackControlOver(not_null<Ui::RpWidget*> control, bool over);
  140. void showNiceTooltip(
  141. not_null<Ui::RpWidget*> control,
  142. NiceTooltipType type = NiceTooltipType::Normal);
  143. void showStickedTooltip();
  144. void hideStickedTooltip(StickedTooltipHide hide);
  145. void hideStickedTooltip(StickedTooltip type, StickedTooltipHide hide);
  146. void hideNiceTooltip();
  147. bool updateMode();
  148. void updateControlsGeometry();
  149. void updateButtonsGeometry();
  150. void updateTooltipGeometry();
  151. void updateButtonsStyles();
  152. void updateMembersGeometry();
  153. void refreshControlsBackground();
  154. void refreshTitleBackground();
  155. void setupControlsBackgroundWide();
  156. void setupControlsBackgroundNarrow();
  157. void showControls();
  158. void refreshLeftButton();
  159. void refreshVideoButtons(
  160. std::optional<bool> overrideWideMode = std::nullopt);
  161. void refreshTopButton();
  162. void createPinOnTop();
  163. void setupEmptyRtmp();
  164. void toggleWideControls(bool shown);
  165. void updateWideControlsVisibility();
  166. [[nodiscard]] bool videoButtonInNarrowMode() const;
  167. void endCall();
  168. void showMainMenu();
  169. void chooseJoinAs();
  170. void chooseShareScreenSource();
  171. void screenSharingPrivacyRequest();
  172. void addMembers();
  173. void kickParticipant(not_null<PeerData*> participantPeer);
  174. void kickParticipantSure(not_null<PeerData*> participantPeer);
  175. [[nodiscard]] QRect computeTitleRect() const;
  176. void refreshTitle();
  177. void refreshTitleGeometry();
  178. void refreshTitleColors();
  179. void setupRealCallViewers();
  180. void subscribeToChanges(not_null<Data::GroupCall*> real);
  181. void migrate(not_null<ChannelData*> channel);
  182. void subscribeToPeerChanges();
  183. QWidget *chooseSourceParent() override;
  184. QString chooseSourceActiveDeviceId() override;
  185. bool chooseSourceActiveWithAudio() override;
  186. bool chooseSourceWithAudioSupported() override;
  187. rpl::lifetime &chooseSourceInstanceLifetime() override;
  188. void chooseSourceAccepted(
  189. const QString &deviceId,
  190. bool withAudio) override;
  191. void chooseSourceStop() override;
  192. const not_null<GroupCall*> _call;
  193. not_null<PeerData*> _peer;
  194. Ui::GL::Window _window;
  195. const std::unique_ptr<Ui::LayerManager> _layerBg;
  196. rpl::variable<PanelMode> _mode;
  197. rpl::variable<bool> _fullScreenOrMaximized = false;
  198. bool _unpinnedMaximized = false;
  199. #ifndef Q_OS_MAC
  200. rpl::variable<int> _controlsTop = 0;
  201. const std::unique_ptr<Ui::Platform::SeparateTitleControls> _controls;
  202. #endif // !Q_OS_MAC
  203. const std::unique_ptr<base::PowerSaveBlocker> _powerSaveBlocker;
  204. rpl::lifetime _callLifetime;
  205. object_ptr<Ui::RpWidget> _titleBackground = { nullptr };
  206. object_ptr<Ui::FlatLabel> _title = { nullptr };
  207. object_ptr<Ui::FlatLabel> _titleSeparator = { nullptr };
  208. object_ptr<Ui::FlatLabel> _viewers = { nullptr };
  209. object_ptr<Ui::FlatLabel> _subtitle = { nullptr };
  210. object_ptr<Ui::AbstractButton> _recordingMark = { nullptr };
  211. object_ptr<Ui::IconButton> _menuToggle = { nullptr };
  212. object_ptr<Ui::IconButton> _pinOnTop = { nullptr };
  213. object_ptr<Ui::DropdownMenu> _menu = { nullptr };
  214. rpl::variable<bool> _wideMenuShown = false;
  215. object_ptr<Ui::AbstractButton> _joinAsToggle = { nullptr };
  216. object_ptr<Members> _members = { nullptr };
  217. std::unique_ptr<Viewport> _viewport;
  218. rpl::lifetime _trackControlsOverStateLifetime;
  219. rpl::lifetime _trackControlsMenuLifetime;
  220. object_ptr<Ui::FlatLabel> _startsIn = { nullptr };
  221. object_ptr<Ui::RpWidget> _countdown = { nullptr };
  222. std::shared_ptr<Ui::GroupCallScheduledLeft> _countdownData;
  223. object_ptr<Ui::FlatLabel> _startsWhen = { nullptr };
  224. object_ptr<Ui::RpWidget> _emptyRtmp = { nullptr };
  225. ChooseJoinAsProcess _joinAsProcess;
  226. std::optional<QRect> _lastSmallGeometry;
  227. std::optional<QRect> _lastLargeGeometry;
  228. bool _lastLargeMaximized = false;
  229. bool _showWideControls = false;
  230. bool _trackControls = false;
  231. bool _wideControlsShown = false;
  232. Ui::Animations::Simple _wideControlsAnimation;
  233. object_ptr<Ui::RpWidget> _controlsBackgroundWide = { nullptr };
  234. std::unique_ptr<ControlsBackgroundNarrow> _controlsBackgroundNarrow;
  235. object_ptr<Ui::CallButton> _settings = { nullptr };
  236. object_ptr<Ui::CallButton> _wideMenu = { nullptr };
  237. object_ptr<Ui::CallButton> _callShare = { nullptr };
  238. object_ptr<Ui::CallButton> _video = { nullptr };
  239. object_ptr<Ui::CallButton> _screenShare = { nullptr };
  240. std::unique_ptr<Ui::CallMuteButton> _mute;
  241. object_ptr<Ui::CallButton> _hangup;
  242. object_ptr<Ui::ImportantTooltip> _niceTooltip = { nullptr };
  243. QPointer<Ui::IconButton> _stickedTooltipClose;
  244. QPointer<Ui::RpWidget> _niceTooltipControl;
  245. StickedTooltips _stickedTooltipsShown;
  246. Fn<void()> _callShareLinkCallback;
  247. const std::unique_ptr<Toasts> _toasts;
  248. std::unique_ptr<MicLevelTester> _micLevelTester;
  249. style::complex_color _controlsBackgroundColor;
  250. base::Timer _hideControlsTimer;
  251. rpl::lifetime _hideControlsTimerLifetime;
  252. rpl::lifetime _peerLifetime;
  253. };
  254. } // namespace Calls::Group