| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- #pragma once
- // Qt Core
- #include <QMutex>
- #include <QStringList>
- #include <QTimer>
- #include <QWaitCondition>
- #include <QWidget>
- #include <QRect>
- #include <QVector>
- #include "qobjectdefs.h"
- // Qt Widgets
- #include <QPushButton>
- #include <QCheckBox>
- // Project includes
- #include "libs/Recorder/export.h"
- #include "widgets/framelessbase.h" // Use TWidget as base
- class QSplitter;
- // 移除:UserProfileWidget 前向声明(不再使用)
- class ChatWindow;
- class RecorderWidget; // forward declaration for standalone recorder
- class AVPlayerWidget; // forward declaration for standalone player
- class PopoverButtonGroup; // 前向声明:在本类中以指针形式使用
- class FunctionButton; // 新增:用于指针成员 m_streamButton 的前向声明
- class TMainWindow; // 新增:用于无边框自定义标题窗口承载弹窗/悬浮工具栏
- // Removed RecorderAudioWidget forward declaration; use QComboBox instead
- class QComboBox;
- class WebSocketClient;
- class StatsWidget;
- class AudioDeviceSelectorIcon;
- class AudioDeviceSelectorIconDecoupled;
- namespace ADS {
- class DockManager;
- class DockWidget;
- }
- /**
- * @brief MainPanel 主面板类
- *
- * MainPanel是应用程序的核心界面组件,负责管理和协调各个功能模块:
- * - 播放器组件的显示和控制
- * - 聊天窗口的嵌入式和独立显示
- * - 录制和推流功能的控制
- * - 音频设备的选择和管理
- * - 用户界面的布局和模式切换
- *
- * 该类支持多种显示模式:
- * - 正常模式:分割器布局,左侧播放器,右侧聊天
- * - 推流模式:隐藏聊天面板,专注于推流控制
- * - 独立窗口模式:各组件可以独立弹出显示
- *
- * @author 开发团队
- * @date 2024
- */
- class MainPanel : public TWidget
- {
- Q_OBJECT
- public:
- // ========== 构造与析构 ==========
- /**
- * @brief 构造函数
- * @param parent 父窗口指针
- */
- explicit MainPanel(QWidget *parent = nullptr);
-
- /**
- * @brief 析构函数
- */
- ~MainPanel();
-
- // ========== 配置接口 ==========
- /**
- * @brief 设置用户角色列表
- * @param roleList 角色列表,用于权限控制
- */
- void setRole(const QStringList &roleList);
-
- /**
- * @brief 设置推流房间ID
- * @param room 房间ID字符串
- */
- void setPushRoomId(const QString &room);
-
- /**
- * @brief 设置播放器组件
- * @param newPlayer 新的播放器组件指针
- */
- void setPlayerWidget(QWidget *newPlayer);
- public slots:
- // ========== 窗口显示控制 ==========
- /**
- * @brief 显示独立的录制窗口
- */
- void showRecorderStandalone();
-
- /**
- * @brief 显示独立的播放器窗口
- */
- void showPlayerStandalone();
-
- /**
- * @brief 显示独立的聊天窗口
- */
- void showChatStandalone();
-
- /**
- * @brief 显示嵌入式聊天窗口
- */
- void showChatEmbedded();
- // ========== 测试功能 ==========
- /**
- * @brief 开始推流拉流测试
- * @param roomId 房间ID,用于推流和拉流的标识
- * @param enableRecording 是否同时启用录制功能
- */
- void startStreamingTest(const QString &roomId = "0198da3f-5900-78e3-8160-2b7a149cc772",
- bool enableRecording = true);
- /**
- * @brief 停止推流拉流测试
- */
- void stopStreamingTest();
- signals:
- // ========== 信号 ==========
- /**
- * @brief 用户点击退出按钮时发出的信号
- */
- void logoutClicked();
- private:
- // ========== 播放控制 ==========
- void handleDebouncedPlay();
-
- // ========== 界面布局控制 ==========
- void showFloatingToolbar();
- void hideFloatingToolbar();
- void applyModeLayout();
- protected:
- void resizeEvent(QResizeEvent* event) override;
- bool eventFilter(QObject *watched, QEvent *event) override;
- private:
- // ========== 核心布局组件 ==========
- QSplitter *splitter = nullptr;
- QWidget *playerContainer = nullptr;
- QWidget *playerWidget = nullptr;
- QWidget *m_rightWidget = nullptr; // 推流时整体隐藏的右侧面板(含聊天容器)
-
- // ========== 聊天相关组件 ==========
- ChatWindow *chatView = nullptr; // 统一的聊天窗口实例
- QWidget *m_chatContainer = nullptr; // 聊天窗口的容器(用于嵌入式显示)
- WebSocketClient *webSocketClient = nullptr;
-
- // ========== 独立窗口组件 ==========
- RecorderWidget *m_recorderStandalone = nullptr;
- AVPlayerWidget *m_avPlayerStandalone = nullptr;
-
- // ========== 窗口框架 ==========
- class TMainWindow *m_recorderFrame = nullptr;
- class TMainWindow *m_playerFrame = nullptr;
- class TMainWindow *m_chatFrame = nullptr;
- class TMainWindow *m_settingsFrame = nullptr;
- TMainWindow *m_compactFrame = nullptr; // 用于承载"悬浮工具栏"的自定义标题窗口
-
- // ========== 功能按钮组件 ==========
- class PopoverButtonGroup *buttonGroup = nullptr;
- QPushButton *m_recordButton = nullptr; // 开始录制按钮
- class FunctionButton *m_streamButton = nullptr; // 开始推流按钮
- class FunctionButton *m_chatButton = nullptr; // 聊天显示/隐藏/弹出/嵌入切换按钮
- QPushButton *m_settingsButton = nullptr; // 设置按钮
- QCheckBox *m_drawCursorCheckBox = nullptr; // 绘制鼠标指针选项
- QCheckBox *m_syncRecordCheckBox = nullptr; // 推流时同步录制选项
-
- // ========== 音频设备相关 ==========
- AudioDeviceSelectorIcon *m_audioDeviceSelector = nullptr;
- AudioDeviceSelectorIconDecoupled *m_audioDeviceSelectorDecoupled = nullptr;
- QComboBox *m_micWidget = nullptr; // 麦克风下拉框
- QComboBox *m_speakerWidget = nullptr; // 扬声器下拉框
- QVector<AMRECORDER_DEVICE> m_micDevices; // 缓存麦克风设备列表
- QVector<AMRECORDER_DEVICE> m_speakerDevices; // 缓存扬声器设备列表
-
- // ========== 视频编码器相关 ==========
- QComboBox *m_encoderWidget = nullptr; // 视频编码器下拉框
- QVector<AMRECORDER_ENCODERS> m_encoderList; // 缓存编码器列表
- int m_selectedEncoderId = -1; // 当前选择的编码器 id
-
- // ========== 播放控制相关 ==========
- bool m_isStartingPlay = false;
- QMutex m_playMutex;
- QWaitCondition m_playCond;
- QTimer *m_debounceTimer = nullptr;
- QString m_pendingRoomId;
-
- // ========== 状态管理 ==========
- bool m_isStreaming = false; // 推流状态跟踪
- bool m_compactMode = false; // 极简模式
- QRect m_savedWindowGeometry; // 窗口几何缓存
-
- // ========== 其他组件 ==========
- StatsWidget *statsWidget = nullptr;
- ADS::DockManager *m_dockManager = nullptr;
-
- private:
- // ========== 初始化函数 ==========
- void initPlaybackControls();
- void initChatComponents();
- void initLayoutComponents();
- void initFunctionButtons();
- void connectSignals();
- void initAudioDeviceSelectors();
-
- private slots:
-
- // 录制控制按钮的槽函数
- void onRecordButtonClicked();
- void onStreamButtonClicked();
- void onChatButtonClicked(); // 聊天弹出/嵌入/显示/隐藏按钮槽
-
- // 聊天窗口关闭处理
- void onChatWindowCloseRequested();
- };
|