#ifndef PQWEBENGINEVIEW_H
#define PQWEBENGINEVIEW_H

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

class PQWebEngineView;
class PQWebEngineView : public QWebEngineView
{
    Q_OBJECT
    PQ_WIDGET_EX(QWebEngineView)

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

public:
    Q_INVOKABLE explicit PQWebEngineView(QWidget *parent = 0);
    ~PQWebEngineView();

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

    Q_INVOKABLE void findText(const QString &subString, int options = 0);
    Q_INVOKABLE void load(const QString &url);
    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 PQAction *pageAction(int action) const;

public Q_SLOTS:
    Q_INVOKABLE void setUrl(const QString &url);
    Q_INVOKABLE void setZoomFactor(double zoomFactor);

    Q_INVOKABLE void back();
    Q_INVOKABLE void forward();
    Q_INVOKABLE void reload();
    Q_INVOKABLE void stop();

    void iconUrlChanged_pslot(const QString &url);
    void loadFinished_pslot(bool ok);
    void loadProgress_pslot(int progress);
    void loadStarted_pslot();
    void renderProcessTerminated_pslot(int terminationStatus, int exitCode);
    void selectionChanged_pslot();
    void titleChanged_pslot(const QString &title);
    void urlChanged_pslot(const QString &url);

    PQ_ON_SIGNAL_DECL_START {
        PQWIDGET_ON_SIGNALS();
        PQ_ON_SIGNAL(iconUrlChanged_pslot());
        PQ_ON_SIGNAL(loadFinished_pslot(bool));
        PQ_ON_SIGNAL(loadProgress_pslot(int));
        PQ_ON_SIGNAL(loadStarted_pslot());
        PQ_ON_SIGNAL(renderProcessTerminated_pslot(int,int));
        PQ_ON_SIGNAL(selectionChanged_pslot());
        PQ_ON_SIGNAL(titleChanged_pslot(string));
        PQ_ON_SIGNAL(urlChanged_pslot(string));
    } PQ_ON_SIGNAL_DECL_END

private:
};

#endif // PQWEBENGINEVIEW_H
