#ifndef WPAGEITEM_H
#define WPAGEITEM_H

#include <QDebug>
#include <QListWidgetItem>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QDir>
#include <QFile>
#include <QListWidget>
#include "wdrawingboard.h"
class wPageAttr;
class wPageItemWidget;
class wPageItem : public QObject,  public QListWidgetItem
{
    Q_OBJECT
public:
    explicit wPageItem(const QJsonDocument &json, const QString &path, const QSize &resolution, QListWidget *view = nullptr, int type = Type);
    wPageItem(const wPageItem &other);
    virtual ~wPageItem() override;

private:
    void init();
    void restoreElement(const QJsonObject &json);

public:
    virtual wPageItem*    clone()      const override { return new wPageItem(*this); }
    QString               name()       const          { return m_jRoot["name"].toString(); }
    QGraphicsScene*       scene()      const          { return m_scene; }
    QJsonDocument         jRoot()      const          { return m_jRoot; }
    QString               pRoot()      const          { return m_strProgramItemPath; }
    void setJRoot(const QJsonDocument &json)          { m_jRoot = json; }
    QSizeF                resolution() const          { return m_resolution; }
    QStringList           filesList()  const;
    bool IsChange(const QJsonDocument &OldJsonDocument);

public:
    wPageItemWidget* wPage(bool newOne = true);
    wPageAttr* wAttr(bool newOne = true);
    void save(const QString &pParent);
    void updateJson();
    void setRes(qreal w, qreal h);

public: // Qt::BlockingQueuedConnection
    void playElements();
    void stopElements();
    void disconnectCiTieSignal(wDrawingBoard *drawingboard);
    void connectCiTieSignal(wDrawingBoard *drawingboard);
    void ClearAllContent();
public slots:
    void onAttrUpdated(const QJsonObject &json);

private:
    QGraphicsScene    *m_scene;
    QGraphicsRectItem *m_wBackground;
    wPageItemWidget   *m_wPage;
    wPageAttr         *m_wPageAttr;
    QJsonDocument     m_jRoot;
    QJsonDocument     m_jOldRoot;
    QString           m_strProgramItemPath;
    QSizeF            m_resolution;
};

#endif // WPAGEITEM_H
