calls_panel.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/object_ptr.h"
  11. #include "base/unique_qptr.h"
  12. #include "calls/calls_call.h"
  13. #include "calls/group/ui/desktop_capture_choose_source.h"
  14. #include "ui/effects/animations.h"
  15. #include "ui/gl/gl_window.h"
  16. #include "ui/rp_widget.h"
  17. class Image;
  18. namespace base {
  19. class PowerSaveBlocker;
  20. } // namespace base
  21. namespace Data {
  22. class PhotoMedia;
  23. } // namespace Data
  24. namespace Ui {
  25. class IconButton;
  26. class CallButton;
  27. class LayerManager;
  28. class FlatLabel;
  29. template <typename Widget>
  30. class FadeWrap;
  31. template <typename Widget>
  32. class PaddingWrap;
  33. class RpWindow;
  34. class PopupMenu;
  35. namespace GL {
  36. enum class Backend;
  37. } // namespace GL
  38. namespace Platform {
  39. struct SeparateTitleControls;
  40. } // namespace Platform
  41. } // namespace Ui
  42. namespace style {
  43. struct CallSignalBars;
  44. struct CallBodyLayout;
  45. } // namespace style
  46. namespace Calls {
  47. class Userpic;
  48. class SignalBars;
  49. class VideoBubble;
  50. struct DeviceSelection;
  51. class Panel final : private Group::Ui::DesktopCapture::ChooseSourceDelegate {
  52. public:
  53. Panel(not_null<Call*> call);
  54. ~Panel();
  55. [[nodiscard]] bool isVisible() const;
  56. [[nodiscard]] bool isActive() const;
  57. void showAndActivate();
  58. void minimize();
  59. void toggleFullScreen();
  60. void replaceCall(not_null<Call*> call);
  61. void closeBeforeDestroy();
  62. QWidget *chooseSourceParent() override;
  63. QString chooseSourceActiveDeviceId() override;
  64. bool chooseSourceActiveWithAudio() override;
  65. bool chooseSourceWithAudioSupported() override;
  66. rpl::lifetime &chooseSourceInstanceLifetime() override;
  67. void chooseSourceAccepted(
  68. const QString &deviceId,
  69. bool withAudio) override;
  70. void chooseSourceStop() override;
  71. [[nodiscard]] rpl::producer<bool> startOutgoingRequests() const;
  72. [[nodiscard]] rpl::lifetime &lifetime();
  73. private:
  74. class Incoming;
  75. using State = Call::State;
  76. using Type = Call::Type;
  77. enum class AnswerHangupRedialState : uchar {
  78. Answer,
  79. Hangup,
  80. Redial,
  81. StartCall,
  82. };
  83. [[nodiscard]] not_null<Ui::RpWindow*> window() const;
  84. [[nodiscard]] not_null<Ui::RpWidget*> widget() const;
  85. void paint(QRect clip);
  86. void initWindow();
  87. void initWidget();
  88. void initControls();
  89. void reinitWithCall(Call *call);
  90. void initLayout();
  91. void initMediaDeviceToggles();
  92. void initGeometry();
  93. [[nodiscard]] bool handleClose() const;
  94. void requestControlsHidden(bool hidden);
  95. void controlsShownForce(bool shown);
  96. void updateControlsShown();
  97. void updateControlsGeometry();
  98. void updateHangupGeometry();
  99. void updateStatusGeometry();
  100. void updateOutgoingVideoBubbleGeometry();
  101. void stateChanged(State state);
  102. void showControls();
  103. void updateStatusText(State state);
  104. void startDurationUpdateTimer(crl::time currentDuration);
  105. void setIncomingSize(QSize size);
  106. void refreshIncomingGeometry();
  107. void refreshOutgoingPreviewInBody(State state);
  108. void toggleFullScreen(bool fullscreen);
  109. void createRemoteAudioMute();
  110. void createRemoteLowBattery();
  111. void showRemoteLowBattery();
  112. void refreshAnswerHangupRedialLabel();
  113. void showDevicesMenu(
  114. not_null<QWidget*> button,
  115. std::vector<DeviceSelection> types);
  116. [[nodiscard]] QRect incomingFrameGeometry() const;
  117. [[nodiscard]] QRect outgoingFrameGeometry() const;
  118. Call *_call = nullptr;
  119. not_null<UserData*> _user;
  120. Ui::GL::Window _window;
  121. const std::unique_ptr<Ui::LayerManager> _layerBg;
  122. std::unique_ptr<Incoming> _incoming;
  123. #ifndef Q_OS_MAC
  124. std::unique_ptr<Ui::Platform::SeparateTitleControls> _controls;
  125. #endif // !Q_OS_MAC
  126. std::unique_ptr<base::PowerSaveBlocker> _powerSaveBlocker;
  127. QSize _incomingFrameSize;
  128. rpl::lifetime _callLifetime;
  129. not_null<const style::CallBodyLayout*> _bodySt;
  130. object_ptr<Ui::CallButton> _answerHangupRedial;
  131. object_ptr<Ui::FadeWrap<Ui::CallButton>> _decline;
  132. object_ptr<Ui::FadeWrap<Ui::CallButton>> _cancel;
  133. bool _hangupShown = false;
  134. bool _outgoingPreviewInBody = false;
  135. std::optional<AnswerHangupRedialState> _answerHangupRedialState;
  136. Ui::Animations::Simple _hangupShownProgress;
  137. object_ptr<Ui::FadeWrap<Ui::CallButton>> _screencast;
  138. object_ptr<Ui::CallButton> _camera;
  139. Ui::CallButton *_cameraDeviceToggle = nullptr;
  140. base::unique_qptr<Ui::CallButton> _startVideo;
  141. object_ptr<Ui::FadeWrap<Ui::CallButton>> _mute;
  142. Ui::CallButton *_audioDeviceToggle = nullptr;
  143. object_ptr<Ui::FlatLabel> _name;
  144. object_ptr<Ui::FlatLabel> _status;
  145. object_ptr<Ui::RpWidget> _fingerprint = { nullptr };
  146. object_ptr<Ui::PaddingWrap<Ui::FlatLabel>> _remoteAudioMute = { nullptr };
  147. object_ptr<Ui::PaddingWrap<Ui::FlatLabel>> _remoteLowBattery
  148. = { nullptr };
  149. std::unique_ptr<Userpic> _userpic;
  150. std::unique_ptr<VideoBubble> _outgoingVideoBubble;
  151. QPixmap _bottomShadow;
  152. int _bodyTop = 0;
  153. int _buttonsTopShown = 0;
  154. int _buttonsTop = 0;
  155. base::Timer _hideControlsTimer;
  156. base::Timer _controlsShownForceTimer;
  157. std::unique_ptr<QObject> _hideControlsFilter;
  158. bool _hideControlsRequested = false;
  159. rpl::variable<bool> _fullScreenOrMaximized;
  160. Ui::Animations::Simple _controlsShownAnimation;
  161. bool _controlsShownForce = false;
  162. bool _controlsShown = true;
  163. bool _mouseInside = false;
  164. base::unique_qptr<Ui::PopupMenu> _devicesMenu;
  165. base::Timer _updateDurationTimer;
  166. base::Timer _updateOuterRippleTimer;
  167. rpl::event_stream<bool> _startOutgoingRequests;
  168. };
  169. } // namespace Calls