#ifndef EVIDEO_H
#define EVIDEO_H

#include "ebase.h"
#include "pagelistitem.h"
extern "C"{
#include <libavcodec/avcodec.h>
}
class ProgItem;
class EVideo : public EBase {
    Q_OBJECT
public:
    static QString filters() {
        static const QString filters = tr("Video")+"(*.mp4 *.mkv *.ts *.m2ts *.tp *.rm *.rmvb *.avi *.wmv *.mov);;"+tr("Flash")+"(*.flv *.swf)";
        return filters;
    }
    static const QImage &mask() {
        static const QImage mask = QImage(":/res/video-pre.png");
        return mask;
    }
    static QString transcoding(QString rawFile, QString rawName, QString dir, int rawW, int rawH, AVCodecID codec_id);
    static EVideo *create(const QString &file, PageListItem *pageItem, EBase *multiWin = nullptr);
    static EVideo *create(const QJsonObject &, PageListItem *pageItem, EBase *multiWin = nullptr);
    static QJsonObject genProg(const QJsonObject &, const QString &, ProgItem *mProgItem);

    explicit EVideo(const QString &, const QString &, const QString &, const QString &, QImage &img, int dur, PageListItem *pageItem, EBase *multiWin = nullptr);

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

    QString mDir;
    QString mName;
    QString mRawDir;
    QString mRawName;
    QImage mCoverImg;
protected:
    int aspectRatioMode = Qt::IgnoreAspectRatio;
    int playDuration = 10;
    int playTimes = 1;
    PageListItem *mPageItem;
};

#endif // EVIDEO_H
