1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Added methods of webview to qml tab api

This commit is contained in:
Anmol Gautam 2018-06-05 19:32:54 +05:30
parent 4ff62c3d0a
commit 2d3ed28386
2 changed files with 182 additions and 0 deletions

View File

@ -17,6 +17,8 @@
* ============================================================ */
#include "qmltab.h"
#include "loadrequest.h"
#include "tabbedwebview.h"
#include <QWebEngineHistory>
QmlTab::QmlTab(WebTab *webTab, QObject *parent)
: QObject(parent)
@ -57,6 +59,9 @@ QmlTab::QmlTab(WebTab *webTab, QObject *parent)
map.insert(QSL("playing"), playing);
emit playingChanged(map);
});
connect(m_webTab->webView(), &TabbedWebView::zoomLevelChanged, this, &QmlTab::zoomLevelChanged);
connect(m_webTab->webView(), &TabbedWebView::backgroundActivityChanged, this, &QmlTab::backgroundActivityChanged);
}
QString QmlTab::url() const
@ -149,6 +154,51 @@ QmlWindow *QmlTab::browserWindow() const
return new QmlWindow(m_webTab->browserWindow());
}
bool QmlTab::loading() const
{
if (!m_webTab) {
return false;
}
return m_webTab->webView()->isLoading();
}
int QmlTab::loadingProgress() const
{
if (!m_webTab) {
return -1;
}
return m_webTab->webView()->loadingProgress();
}
bool QmlTab::backgroundActivity() const
{
if (!m_webTab) {
return false;
}
return m_webTab->webView()->backgroundActivity();
}
bool QmlTab::canGoBack() const
{
if (!m_webTab) {
return false;
}
return m_webTab->webView()->history()->canGoBack();
}
bool QmlTab::canGoForward() const
{
if (!m_webTab) {
return false;
}
return m_webTab->webView()->history()->canGoForward();
}
void QmlTab::detach()
{
if (!m_webTab) {
@ -216,3 +266,111 @@ void QmlTab::load(const QVariantMap &map)
req.setUrl(QUrl::fromEncoded(url.toUtf8()));
m_webTab->load(req);
}
void QmlTab::zoomIn()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->zoomIn();
}
void QmlTab::zoomOut()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->zoomOut();
}
void QmlTab::zoomReset()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->zoomReset();
}
void QmlTab::undo()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->editUndo();
}
void QmlTab::redo()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->editRedo();
}
void QmlTab::selectAll()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->editSelectAll();
}
void QmlTab::reloadBypassCache()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->reloadBypassCache();
}
void QmlTab::back()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->back();
}
void QmlTab::forward()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->forward();
}
void QmlTab::printPage()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->printPage();
}
void QmlTab::showSource()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->showSource();
}
void QmlTab::sendPageByMail()
{
if (!m_webTab) {
return;
}
m_webTab->webView()->sendPageByMail();
}

View File

@ -34,6 +34,11 @@ class QmlTab : public QObject
Q_PROPERTY(bool current READ current CONSTANT)
Q_PROPERTY(bool playing READ playing CONSTANT)
Q_PROPERTY(QmlWindow* browserWindow READ browserWindow CONSTANT)
Q_PROPERTY(bool loading READ loading CONSTANT)
Q_PROPERTY(int loadingProgress READ loadingProgress CONSTANT)
Q_PROPERTY(bool backgroundActivity READ backgroundActivity CONSTANT)
Q_PROPERTY(bool canGoBack READ canGoBack CONSTANT)
Q_PROPERTY(bool canGoForward READ canGoForward CONSTANT)
public:
explicit QmlTab(WebTab *webTab = 0, QObject *parent = 0);
QString url() const;
@ -46,6 +51,11 @@ public:
bool current() const;
bool playing() const;
QmlWindow *browserWindow() const;
bool loading() const;
int loadingProgress() const;
bool backgroundActivity() const;
bool canGoBack() const;
bool canGoForward() const;
Q_INVOKABLE void detach();
Q_INVOKABLE void setZoomLevel(const QVariantMap &map);
@ -53,6 +63,18 @@ public:
Q_INVOKABLE void reload();
Q_INVOKABLE void unload();
Q_INVOKABLE void load(const QVariantMap &map);
Q_INVOKABLE void zoomIn();
Q_INVOKABLE void zoomOut();
Q_INVOKABLE void zoomReset();
Q_INVOKABLE void undo();
Q_INVOKABLE void redo();
Q_INVOKABLE void selectAll();
Q_INVOKABLE void reloadBypassCache();
Q_INVOKABLE void back();
Q_INVOKABLE void forward();
Q_INVOKABLE void printPage();
Q_INVOKABLE void showSource();
Q_INVOKABLE void sendPageByMail();
Q_SIGNALS:
void titleChanged(const QVariantMap &map);
@ -61,6 +83,8 @@ Q_SIGNALS:
void mutedChanged(const QVariantMap &map);
void restoredChanged(const QVariantMap &map);
void playingChanged(const QVariantMap &map);
void zoomLevelChanged(int zoomLevel);
void backgroundActivityChanged(int backgroundActivityChanged);
private:
WebTab *m_webTab;
};