MainPanel.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #pragma once
  2. // Qt Core
  3. #include <QMutex>
  4. #include <QStringList>
  5. #include <QTimer>
  6. #include <QWaitCondition>
  7. #include <QWidget>
  8. #include <QRect>
  9. #include <QVector>
  10. #include "qobjectdefs.h"
  11. // Qt Widgets
  12. #include <QPushButton>
  13. #include <QCheckBox>
  14. // Project includes
  15. #include "libs/Recorder/export.h"
  16. #include "widgets/framelessbase.h" // Use TWidget as base
  17. class QSplitter;
  18. // 移除:UserProfileWidget 前向声明(不再使用)
  19. class ChatWindow;
  20. class RecorderWidget; // forward declaration for standalone recorder
  21. class AVPlayerWidget; // forward declaration for standalone player
  22. class PopoverButtonGroup; // 前向声明:在本类中以指针形式使用
  23. class FunctionButton; // 新增:用于指针成员 m_streamButton 的前向声明
  24. class TMainWindow; // 新增:用于无边框自定义标题窗口承载弹窗/悬浮工具栏
  25. // Removed RecorderAudioWidget forward declaration; use QComboBox instead
  26. class QComboBox;
  27. class WebSocketClient;
  28. class StatsWidget;
  29. class AudioDeviceSelectorIcon;
  30. class AudioDeviceSelectorIconDecoupled;
  31. namespace ADS {
  32. class DockManager;
  33. class DockWidget;
  34. }
  35. /**
  36. * @brief MainPanel 主面板类
  37. *
  38. * MainPanel是应用程序的核心界面组件,负责管理和协调各个功能模块:
  39. * - 播放器组件的显示和控制
  40. * - 聊天窗口的嵌入式和独立显示
  41. * - 录制和推流功能的控制
  42. * - 音频设备的选择和管理
  43. * - 用户界面的布局和模式切换
  44. *
  45. * 该类支持多种显示模式:
  46. * - 正常模式:分割器布局,左侧播放器,右侧聊天
  47. * - 推流模式:隐藏聊天面板,专注于推流控制
  48. * - 独立窗口模式:各组件可以独立弹出显示
  49. *
  50. * @author 开发团队
  51. * @date 2024
  52. */
  53. class MainPanel : public TWidget
  54. {
  55. Q_OBJECT
  56. public:
  57. // ========== 构造与析构 ==========
  58. /**
  59. * @brief 构造函数
  60. * @param parent 父窗口指针
  61. */
  62. explicit MainPanel(QWidget *parent = nullptr);
  63. /**
  64. * @brief 析构函数
  65. */
  66. ~MainPanel();
  67. // ========== 配置接口 ==========
  68. /**
  69. * @brief 设置用户角色列表
  70. * @param roleList 角色列表,用于权限控制
  71. */
  72. void setRole(const QStringList &roleList);
  73. /**
  74. * @brief 设置推流房间ID
  75. * @param room 房间ID字符串
  76. */
  77. void setPushRoomId(const QString &room);
  78. /**
  79. * @brief 设置播放器组件
  80. * @param newPlayer 新的播放器组件指针
  81. */
  82. void setPlayerWidget(QWidget *newPlayer);
  83. public slots:
  84. // ========== 窗口显示控制 ==========
  85. /**
  86. * @brief 显示独立的录制窗口
  87. */
  88. void showRecorderStandalone();
  89. /**
  90. * @brief 显示独立的播放器窗口
  91. */
  92. void showPlayerStandalone();
  93. /**
  94. * @brief 显示独立的聊天窗口
  95. */
  96. void showChatStandalone();
  97. /**
  98. * @brief 将聊天窗口嵌入到主面板中
  99. */
  100. void showChatEmbedded();
  101. signals:
  102. // ========== 信号 ==========
  103. /**
  104. * @brief 用户点击退出按钮时发出的信号
  105. */
  106. void logoutClicked();
  107. private:
  108. // ========== 播放控制 ==========
  109. void handleDebouncedPlay();
  110. // ========== 界面布局控制 ==========
  111. void showFloatingToolbar();
  112. void hideFloatingToolbar();
  113. void applyModeLayout();
  114. protected:
  115. void resizeEvent(QResizeEvent* event) override;
  116. bool eventFilter(QObject *watched, QEvent *event) override;
  117. private:
  118. // ========== 核心布局组件 ==========
  119. QSplitter *splitter = nullptr;
  120. QWidget *playerContainer = nullptr;
  121. QWidget *playerWidget = nullptr;
  122. QWidget *m_rightWidget = nullptr; // 推流时整体隐藏的右侧面板(含聊天容器)
  123. // ========== 聊天相关组件 ==========
  124. ChatWindow *chatView = nullptr; // 统一的聊天窗口实例
  125. QWidget *m_chatContainer = nullptr; // 聊天窗口的容器(用于嵌入式显示)
  126. WebSocketClient *webSocketClient = nullptr;
  127. // ========== 独立窗口组件 ==========
  128. RecorderWidget *m_recorderStandalone = nullptr;
  129. AVPlayerWidget *m_avPlayerStandalone = nullptr;
  130. // ========== 窗口框架 ==========
  131. class TMainWindow *m_recorderFrame = nullptr;
  132. class TMainWindow *m_playerFrame = nullptr;
  133. class TMainWindow *m_chatFrame = nullptr;
  134. class TMainWindow *m_settingsFrame = nullptr;
  135. TMainWindow *m_compactFrame = nullptr; // 用于承载"悬浮工具栏"的自定义标题窗口
  136. // ========== 功能按钮组件 ==========
  137. class PopoverButtonGroup *buttonGroup = nullptr;
  138. QPushButton *m_recordButton = nullptr; // 开始录制按钮
  139. class FunctionButton *m_streamButton = nullptr; // 开始推流按钮
  140. class FunctionButton *m_chatButton = nullptr; // 聊天显示/隐藏/弹出/嵌入切换按钮
  141. QPushButton *m_settingsButton = nullptr; // 设置按钮
  142. QCheckBox *m_drawCursorCheckBox = nullptr; // 绘制鼠标指针选项
  143. QCheckBox *m_syncRecordCheckBox = nullptr; // 推流时同步录制选项
  144. // ========== 音频设备相关 ==========
  145. AudioDeviceSelectorIcon *m_audioDeviceSelector = nullptr;
  146. AudioDeviceSelectorIconDecoupled *m_audioDeviceSelectorDecoupled = nullptr;
  147. QComboBox *m_micWidget = nullptr; // 麦克风下拉框
  148. QComboBox *m_speakerWidget = nullptr; // 扬声器下拉框
  149. QVector<AMRECORDER_DEVICE> m_micDevices; // 缓存麦克风设备列表
  150. QVector<AMRECORDER_DEVICE> m_speakerDevices; // 缓存扬声器设备列表
  151. // ========== 视频编码器相关 ==========
  152. QComboBox *m_encoderWidget = nullptr; // 视频编码器下拉框
  153. QVector<AMRECORDER_ENCODERS> m_encoderList; // 缓存编码器列表
  154. int m_selectedEncoderId = -1; // 当前选择的编码器 id
  155. // ========== 播放控制相关 ==========
  156. bool m_isStartingPlay = false;
  157. QMutex m_playMutex;
  158. QWaitCondition m_playCond;
  159. QTimer *m_debounceTimer = nullptr;
  160. QString m_pendingRoomId;
  161. // ========== 状态管理 ==========
  162. bool m_isStreaming = false; // 推流状态跟踪
  163. bool m_compactMode = false; // 极简模式
  164. QRect m_savedWindowGeometry; // 窗口几何缓存
  165. // ========== 其他组件 ==========
  166. StatsWidget *statsWidget = nullptr;
  167. ADS::DockManager *m_dockManager = nullptr;
  168. private:
  169. // ========== 初始化函数 ==========
  170. void initPlaybackControls();
  171. void initChatComponents();
  172. void initLayoutComponents();
  173. void initFunctionButtons();
  174. void connectSignals();
  175. void initAudioDeviceSelectors();
  176. private slots:
  177. // 录制控制按钮的槽函数
  178. void onRecordButtonClicked();
  179. void onStreamButtonClicked();
  180. void onChatButtonClicked(); // 聊天弹出/嵌入/显示/隐藏按钮槽
  181. // 聊天窗口关闭处理
  182. void onChatWindowCloseRequested();
  183. };