#ifndef ERICHEDIT_H
#define ERICHEDIT_H

#include <QGraphicsProxyWidget>
#include "eobject.h"
#include "QTextEdit"
class eTextAttr;
class eRichEdit : public eObject
{
    Q_OBJECT
public:
    enum PlayStyle {
        Turning = 0,
        Rolling,
        Static
    };

    enum RollingStyle {
        Left2Right = 0,
        Right2Left,
        Top2Bottom,
        Bottom2Top
    };
    struct Data {
        // Widget
        QString     text;
        QFont       font;
        QTextOption opt;
        QColor      cText;
        QColor      cTextShadow;
        QColor      cBackground;
        int         lineSpacing;
        // Play
        int  playStyle;
        bool headTailConnected;
        int  headTailSpacing;
        int  rollingSpeed;
        int  rollingStyle;
        int  playDuration=10;
    };

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

private:
    void init();

public:
    static void setElement(const QJsonObject &json, Data &attr);

public:
    virtual int type() const override { return eObject::Gif; }
    virtual QWidget* wAttr() override;
    virtual QWidget* wAttrElement() override;
    virtual QJsonObject elementJson() const override;

signals:

public slots:
    virtual void playElectment() override;
    virtual void stopElectment() override;
    void onAttrChanged(const eRichEdit::Data &data);
    void onAdjustMovieRect();


private:
    eTextAttr  *m_wAttr;
    QTextEdit         *m_textEdit;
    QGraphicsProxyWidget *m_vWidget;
    Data                 m_attr;
};

#endif // ERICHEDIT_H
