#ifndef EENVIRON_H
#define EENVIRON_H
#include "ebase.h"
#include "gutil/qgui.h"

class EEnviron : public EBase {
    Q_OBJECT
public:
    struct Data {
        QString title;
        QString labelTemp;
        QString labelHum;
        QString labelNoise;
        QString labelWindSpeed;
        QString labelWindDirectiton;
        QString labelPm25;
        QString labelPm10;
        int tempType = 0;
        int compensation = 0;

        QFont font = qfont("Arial", 12);
        QColor textColor = Qt::red;
        QColor backColor = Qt::transparent;
        int align = 0;
        int playRefresh = 1;
        int playDuration = 10;
        int scrollSpeed = 33;
        bool isSingleLine = false;
        bool hasTemp = true;
        bool hasHum = true;
        bool hasNoise = true;
        bool hasWindSpeed = true;
        bool hasWindDirection = true;
        bool hasPM25 = true;
        bool hasPM10 = true;
    };

    static QJsonObject genProg(const QJsonObject &, const QString &, const QString &);

    explicit EEnviron(EBase *multiWin = nullptr);
    explicit EEnviron(const QJsonObject &json, EBase *multiWin = nullptr);

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    void timerEvent(QTimerEvent *) override;
    int type() const override { return EBase::Environ; }
    QWidget* attrWgt() override;
    bool save(const QString &pRoot) override;
    QJsonObject attrJson() const override;

private:
    void init();
    void drawText(QPainter*, QRectF&);
    void calAttr();
    Data m_attr;
    int scroll_width;
    QString scroll_txt;
    int item_cnt = 0;
    int timer_id = 0;
    int scroll_off = 0;

};

#endif // EENVIRON_H