MainPanel.h 7.7 KB

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