#ifndef PQWEBENGINEPAGE_H
#define PQWEBENGINEPAGE_H

#include <QtWebEngineWidgets>
#include <QUrl>
#include "pqobject.h"
#include "pqaction.h"

class PQWebEnginePage : public QWebEnginePage
{
    Q_OBJECT
    PQ_OBJECT_EX(QWebEngineView)

    Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor)
    Q_PROPERTY(bool hasSelection READ hasSelection)
    Q_PROPERTY(QString iconUrl READ iconUrl)
    Q_PROPERTY(QString selectedText READ selectedText)
    Q_PROPERTY(QString url READ url WRITE setUrl)
    Q_PROPERTY(double zoomFactor READ zoomFactor WRITE setZoomFactor)

public:
    Q_INVOKABLE explicit PQWebEnginePage(QObject *parent = 0);
    ~PQWebEnginePage() {}

    Q_INVOKABLE QString backgroundColor() const;
    Q_INVOKABLE bool hasSelection() const;
    Q_INVOKABLE QString iconUrl(int options = QUrl::FormattingOptions(QUrl::PrettyDecoded)) const;
    Q_INVOKABLE QString selectedText() const;
    Q_INVOKABLE QString url(int options = QUrl::FormattingOptions(QUrl::PrettyDecoded)) const;
    Q_INVOKABLE double zoomFactor() const;

    Q_INVOKABLE PQAction *action(int action);

    Q_INVOKABLE QVariant runJavaScript(const QString &scriptSource);
    Q_INVOKABLE void setContent(const QByteArray &data, const QString &mimeType = QString(), const QString &baseUrl = QString());
    Q_INVOKABLE void setHtml(const QString &html, const QString &baseUrl = QString());
    Q_INVOKABLE QString toHtml() const;
    Q_INVOKABLE QString toPlainText() const;

public slots:
    Q_INVOKABLE void setBackgroundColor(const QString &backgroundColor);
    Q_INVOKABLE void setUrl(const QString &url);
    Q_INVOKABLE void setZoomFactor(double zoomFactor);

    PQ_ON_SIGNAL_DECL_START {
        PQOBJECT_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END
};

#endif // PQWEBENGINEPAGE_H
