#ifndef REALTIMEPLAYER_H
|
#define REALTIMEPLAYER_H
|
|
#include <QMainWindow>
|
//#include <QWidget>
|
#include <QTcpSocket>
|
#include <QTimer>
|
#include <QGridLayout>
|
#include <QLabel>
|
#include <QPushButton>
|
#include <QList>
|
#include <QDateTime>
|
#include <QDebug>
|
#include "realtimeplayer_types.h"
|
|
namespace Ui {
|
class RealTimePlayer;
|
}
|
|
|
// 🎯 在文件开头添加,类声明之前
|
class ClickableLabel : public QLabel
|
{
|
Q_OBJECT
|
|
public:
|
explicit ClickableLabel(QWidget* parent = nullptr) : QLabel(parent) {}
|
|
signals:
|
void clicked();
|
|
protected:
|
void mousePressEvent(QMouseEvent* event) override {
|
if (event->button() == Qt::LeftButton) {
|
emit clicked();
|
}
|
QLabel::mousePressEvent(event);
|
}
|
};
|
|
|
|
class RealTimePlayer : public QMainWindow
|
{
|
Q_OBJECT
|
|
public:
|
explicit RealTimePlayer(QWidget *parent = 0);
|
~RealTimePlayer();
|
|
private slots:
|
// 界面按钮槽函数
|
void onBtn1x1Clicked(); // 1画面布局
|
void onBtn2x2Clicked(); // 4画面布局
|
void onBtn3x3Clicked(); // 9画面布局
|
void onBtn4x4Clicked(); // 16画面布局
|
void onBtnPlayAllClicked(); // 全部播放
|
void onBtnStopAllClicked(); // 全部停止
|
|
// 视频窗口点击处理
|
void onVideoWindowClicked(int windowIndex);
|
|
// 网络相关槽函数
|
void onConnected(); // TCP连接成功
|
void onDisconnected(); // TCP连接断开
|
void onSocketError(QAbstractSocket::SocketError error); // TCP连接错误
|
void onDataReceived(); // 接收到数据
|
|
// 定时器槽函数
|
void updateCurrentTime(); // 更新当前时间显示
|
void sendHeartbeat(); // 发送心跳包
|
void onHeartbeatTimeout(); // 心跳超时处理
|
|
private:
|
// 初始化函数
|
void initializeUI(); // 初始化界面
|
void initializeNetwork(); // 初始化网络
|
void initializeTimers(); // 初始化定时器
|
void setupConnections(); // 设置信号槽连接
|
|
// 界面相关函数
|
void setLayout(LayoutType layoutType); // 设置视频布局
|
void clearVideoLayout(); // 清空视频布局
|
void updateStatusBar(); // 更新状态栏
|
void updateConnectionStatus(ConnectionStatus status); // 更新连接状态
|
|
// 网络相关函数
|
void connectToServer(); // 连接到服务器
|
void disconnectFromServer(); // 断开服务器连接
|
void requestCameraList(); // 请求摄像头列表
|
void processReceivedData(); // 处理接收到的数据
|
|
// 视频相关函数
|
void startPlayCamera(const QString& cameraId, int windowIndex); // 开始播放摄像头
|
void stopPlayCamera(int windowIndex); // 停止播放摄像头
|
void playAllCameras(); // 播放所有摄像头
|
void stopAllCameras(); // 停止所有摄像头
|
|
private:
|
Ui::RealTimePlayer *ui; // 界面指针
|
|
// 网络相关成员变量
|
QTcpSocket* m_tcpSocket; // TCP套接字
|
QString m_serverHost; // 服务器地址
|
quint16 m_serverPort; // 服务器端口
|
ConnectionStatus m_connectionStatus; // 连接状态
|
QByteArray m_receiveBuffer; // 接收数据缓冲区
|
|
// 定时器
|
QTimer* m_timeTimer; // 时间更新定时器
|
QTimer* m_heartbeatTimer; // 心跳发送定时器
|
QTimer* m_heartbeatTimeoutTimer; // 心跳超时定时器
|
|
// 界面相关成员变量
|
LayoutType m_currentLayout; // 当前布局类型
|
QGridLayout* m_videoGridLayout; // 视频网格布局
|
QList<QWidget*> m_videoWidgets; // 视频显示组件列表
|
|
// 数据相关成员变量
|
QList<CameraInfo> m_cameraList; // 摄像头列表
|
QList<QString> m_playingCameras; // 正在播放的摄像头ID列表
|
|
// 心跳相关
|
int m_heartbeatRetryCount; // 心跳重试次数
|
static const int MAX_HEARTBEAT_RETRY = 3; // 最大心跳重试次数
|
|
// 服务器配置
|
static const QString DEFAULT_SERVER_HOST; // 默认服务器地址
|
static const quint16 DEFAULT_SERVER_PORT; // 默认服务器端口
|
|
};
|
|
#endif // REALTIMEPLAYER_H
|