MainPanel.h 7.7 KB

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