#ifndef DEVICEPANEL_H
#define DEVICEPANEL_H

#include "deviceitem.h"
#include <QFile>
#include <QBoxLayout>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QUdpSocket>
#include <QTreeWidgetItem>
#include <QCheckBox>
#include <QComboBox>
#include <QTextEdit>
#include <QSettings>

class DeviceCtrlPanel;
class DevicePanel : public QWidget {
    Q_OBJECT
public:
    explicit DevicePanel(QSettings &, QWidget *parent = nullptr);
    ~DevicePanel();

    void sendGetInfo();

    QLabel *fdCardNumInfo;
    LoQTreeWidget *mDeviceTable;
    QUdpSocket mUdpSocket;
    QTimer mUdpTimer;
    QDialog *specifyIPDlg{0};
    QTextEdit *fdIP{0};
    void addLedCard(LedCard *);
    void clearUdpHeartbeat(LedCard *);
    void parseInfo(const QJsonObject &subObj,const QString &strIp);
    void RestoreLedCardIpByUdpCmd();
    QList<LedCard *> mLedCards;
protected:
    void changeEvent(QEvent *) override;
    void transUi();
public slots:
    void ShowDevicesInfoOrControlWidget(int index);
protected slots:
    void onCheckStateChanged(int f);
    void OnControlSendJson(QJsonObject &json,QString strFanYi);
    void OnControlTcpSend(int iProgramIndex);

    void OnOutputInfo(QString);
signals:
    void sigSelectedDeviceList(QList<LedCard *> *);
private:
    QLabel *label_3, *nDeviceNum;
    QComboBox *bnSpecifyIP;
    QPushButton *btnRefresh;
    QTreeWidgetItem *m_headerItem;
    QHBoxLayout *mHBox{0};
    DeviceCtrlPanel *mDeviceCtrlPanel{0};
    int m_intIndexFlagOfInfoOrControl{0};
    int GetSelectDeviceNum();
    QList<LedCard*> mSelCards;
};

#endif // DEVICEPANEL_H
