#ifndef EACLOCK_H
#define EACLOCK_H

#include <QTimer>
#include "eobject.h"

class eAClock : public eObject
{
    Q_OBJECT
public:
    struct Data {
        QByteArray timeZoneId;
        int        hourMark;//时针
        int        hourMarkSize;//时针大小
        QColor     hourMarkColor;//时针颜色
        int        minMark;//分针
        int        minMarkSize;//分针大小
        QColor     minMarkColor;//分针颜色
        QColor     hourHandColor;//秒针
        QColor     minHandColor;//秒针大小
        QColor     secHandColor;//秒针颜色
        bool       date;//是否显示日期
        QString    dateFontFamily;//字体
        int        dateFontSize;//字体大小
        bool       dateFontBold;//字体粗体
        bool       dateFontItalics;//字体斜体
        bool       dateFontUnderline;//字体下划线
        QColor     dateColor;//日期颜色
        QString    text;//标题
        QString    textFontFamily;//标题字体
        int        textFontSize;//标题字体大小
        bool       textFontBold;//标题字体粗体
        bool       textFontItalics;//标题字体斜体
        bool       textFontUnderline;//标题字体下划线
        QColor     textColor;//标题字体颜色
        int        playDuration=10;//
        bool       bCustomDial;
        QString    path="";
        QString    name="";
        QString    selfCreateDialName="";
    };

public:
    explicit eAClock(QRectF rectInit,InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
    explicit eAClock(const QJsonObject &json, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);

private:
    void init();

public:
    static void setElement(const QJsonObject &json, Data &attr);
public:
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    virtual int type() const override { return eObject::AClock; }
    virtual QWidget* wAttr() override;
    virtual QWidget* wAttrElement() override;
    virtual QJsonObject save(const QString &pRoot) override;// { Q_UNUSED(pRoot); return elementJson(); }
    virtual QJsonObject elementJson() const override;

protected:
    void drawMarkCircular (QPainter *painter, const QPointF &pos, const QColor &color, qreal diameter);
    void drawMarkRectangle(QPainter *painter, const QPointF &pos, const QColor &color, qreal len, qreal rotate);
    void drawMarkNumber   (QPainter *painter, const QPointF &pos, const QColor &color, qreal len, int num);
    void drawHand         (QPainter *painter, qreal angle, const QColor &color, qreal len, qreal base);
    void paintDial(QPainter *painter);
    void paintDate(QPainter *painter);
    void paintText(QPainter *painter);
    void paintHand(QPainter *painter);

protected:
    qreal radiusHour() const;
    qreal radiusMin() const;
    qreal radius() const { return radiusHour() < radiusMin() ? radiusHour() : radiusMin(); }
    QPointF center() const { return QPointF(rect().width() / 2, rect().height() / 2); }

signals:

public slots:
    void onAttrChanged(const eAClock::Data &data);

private:
    Data   m_attr;
    QImage *m_pBiaoPanImage=nullptr;
};

#endif // EACLOCK_H
