#ifndef ETEXT_H
#define ETEXT_H

#include "ebase.h"

class EText : public EBase {
    Q_OBJECT
public:
    enum PlayMode {Flip, Scroll, Static};
    struct Flip {
        int pageDuration{10};
        QString effect{"no"};
        int effectDuration{3};
    };
    struct Scroll {
        int duration{30};
        int effect{0};
        int effectSpeed{50};
        int headTailSpacing{10};
    };
    struct Data {
        QString text;
        Qt::Alignment align;
        QColor backColor{Qt::transparent};
        int playMode{Flip};
        int duration{10};
        struct Flip flip;
        struct Scroll scroll;
    };

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

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

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

public slots:
    void updImg();
signals:
    void updPageCnt();

private:
    void alignV(QImage &, int h=0);
    QImage copy(QImage &img, int x, int y, int w, int h);

    Data m_attr;
    QList<QImage> mImgs;
    int curIdx{0};
};

#endif // ETEXT_H
