dusky
2025-07-25 3627f08c2ab1fd73bd3495eef14ee49c01a3226a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#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