69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#ifndef DEVICESTATUSWIDGET_H
|
||
#define DEVICESTATUSWIDGET_H
|
||
|
||
#include <QWidget>
|
||
#include <QLabel>
|
||
#include <QVBoxLayout>
|
||
#include <QGridLayout>
|
||
#include <QMap>
|
||
#include <QString>
|
||
#include <QMouseEvent>
|
||
#include <QPixmap>
|
||
#include "IWheelMeasureStatus.h"
|
||
|
||
// 每行显示的设备数量
|
||
const int DEVICES_PER_ROW = 4;
|
||
|
||
// 设备显示信息结构体(用于UI显示)
|
||
struct WheelDeviceDisplayInfo {
|
||
QString name;
|
||
QString alias;
|
||
QString ip;
|
||
DeviceStatus status;
|
||
bool isNetworkDevice;
|
||
float temperature;
|
||
bool hasTemperature;
|
||
|
||
WheelDeviceDisplayInfo() : status(DeviceStatus::Offline), isNetworkDevice(false), temperature(0.0f), hasTemperature(false) {}
|
||
WheelDeviceDisplayInfo(const QString& n, const QString& a, const QString& i, DeviceStatus s, bool network)
|
||
: name(n), alias(a), ip(i), status(s), isNetworkDevice(network), temperature(0.0f), hasTemperature(false) {}
|
||
};
|
||
|
||
class DeviceStatusWidget : public QWidget {
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit DeviceStatusWidget(QWidget* parent = nullptr);
|
||
~DeviceStatusWidget();
|
||
|
||
void setDevices(const QList<WheelDeviceDisplayInfo>& devices);
|
||
void updateDeviceStatus(const QString& deviceName, DeviceStatus status);
|
||
void updateDeviceTemperature(const QString& deviceName, float temperature);
|
||
int deviceCount() const { return m_deviceLabels.size(); }
|
||
|
||
signals:
|
||
void deviceClicked(const QString& deviceName);
|
||
void deviceStatusChanged(const QString& deviceName, DeviceStatus status);
|
||
|
||
protected:
|
||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||
|
||
private slots:
|
||
void onDeviceLabelClicked();
|
||
|
||
private:
|
||
void createDeviceLabels(int count);
|
||
void removeDeviceLabels();
|
||
void updateDeviceLabel(int index);
|
||
QString getStatusImage(DeviceStatus status) const;
|
||
|
||
QList<WheelDeviceDisplayInfo> m_devices;
|
||
QList<QWidget*> m_deviceLabels;
|
||
QList<QLabel*> m_statusLabels;
|
||
QList<QLabel*> m_nameLabels;
|
||
QList<QLabel*> m_temperatureLabels;
|
||
QGridLayout* m_gridLayout;
|
||
};
|
||
|
||
#endif // DEVICESTATUSWIDGET_H
|