Falkon Develop
Cross-platform Qt-based web browser
qmltab.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#pragma once
19
20#include <QObject>
21#include <QJSValue>
22#include <QWebEnginePage>
23
24#include "webtab.h"
25#include "../windows/qmlwindow.h"
27
31class QmlTab : public QObject
32{
33 Q_OBJECT
34
38 Q_PROPERTY(QString url READ url CONSTANT)
39
40
43 Q_PROPERTY(QString title READ title CONSTANT)
44
45
50 Q_PROPERTY(int zoomLevel READ zoomLevel CONSTANT)
51
52
55 Q_PROPERTY(int index READ index CONSTANT)
56
57
60 Q_PROPERTY(bool pinned READ pinned CONSTANT)
61
62
65 Q_PROPERTY(bool muted READ muted CONSTANT)
66
67
70 Q_PROPERTY(bool restored READ restored CONSTANT)
71
72
75 Q_PROPERTY(bool current READ current CONSTANT)
76
77
80 Q_PROPERTY(bool playing READ playing CONSTANT)
81
82
85 Q_PROPERTY(QmlWindow* browserWindow READ browserWindow CONSTANT)
86
87
90 Q_PROPERTY(bool loading READ loading CONSTANT)
91
92
95 Q_PROPERTY(int loadingProgress READ loadingProgress CONSTANT)
96
97
100 Q_PROPERTY(bool backgroundActivity READ backgroundActivity CONSTANT)
101
102
105 Q_PROPERTY(bool canGoBack READ canGoBack CONSTANT)
106
107
110 Q_PROPERTY(bool canGoForward READ canGoForward CONSTANT)
111public:
112 explicit QmlTab(WebTab *webTab = nullptr, QObject *parent = nullptr);
113
117 Q_INVOKABLE void detach();
122 Q_INVOKABLE void setZoomLevel(int zoomLevel);
126 Q_INVOKABLE void stop();
130 Q_INVOKABLE void reload();
134 Q_INVOKABLE void unload();
139 Q_INVOKABLE void load(const QString &url);
143 Q_INVOKABLE void zoomIn();
147 Q_INVOKABLE void zoomOut();
151 Q_INVOKABLE void zoomReset();
155 Q_INVOKABLE void undo();
159 Q_INVOKABLE void redo();
163 Q_INVOKABLE void selectAll();
167 Q_INVOKABLE void reloadBypassCache();
171 Q_INVOKABLE void back();
175 Q_INVOKABLE void forward();
179 Q_INVOKABLE void printPage();
183 Q_INVOKABLE void showSource();
187 Q_INVOKABLE void sendPageByMail();
193 Q_INVOKABLE QVariant execJavaScript(const QJSValue &value);
199 Q_INVOKABLE QmlWebHitTestResult *hitTestContent(const QPoint &point);
200
201 void setWebPage(WebPage *webPage);
202
203Q_SIGNALS:
208 void titleChanged(const QString &title);
209
215
221
226 void mutedChanged(bool muted);
227
233
239
245
251
258 void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame);
259
260private:
261 WebTab *m_webTab = nullptr;
262 WebPage *m_webPage = nullptr;
263 QList<QMetaObject::Connection> m_lambdaConnections;
264
265 QString url() const;
266 QString title() const;
267 int zoomLevel() const;
268 int index() const;
269 bool pinned() const;
270 bool muted() const;
271 bool restored() const;
272 bool current() const;
273 bool playing() const;
274 QmlWindow *browserWindow() const;
275 bool loading() const;
276 int loadingProgress() const;
277 bool backgroundActivity() const;
278 bool canGoBack() const;
279 bool canGoForward() const;
280
281 void createConnections();
282 void removeConnections();
283};
The class exposing a browser tab to QML.
Definition: qmltab.h:32
Q_INVOKABLE void detach()
Detaches the tab.
Definition: qmltab.cpp:39
int index
index of the tab
Definition: qmltab.h:55
bool pinned
checks if the tab is pinned
Definition: qmltab.h:60
Q_INVOKABLE void printPage()
Prints the page.
Definition: qmltab.cpp:176
bool restored
checks if the tab is restored
Definition: qmltab.h:70
Q_INVOKABLE void reload()
Reloads webview associated with the tab.
Definition: qmltab.cpp:66
void pinnedChanged(bool pinned)
The signal emitted when pinned state of the tab is changed.
void setWebPage(WebPage *webPage)
Definition: qmltab.cpp:364
bool loading
checks if the tab is loading
Definition: qmltab.h:90
void backgroundActivityChanged(int backgroundActivityChanged)
The signal emitted when background activity of the tab is changed.
int loadingProgress
get the loading progress of the tab
Definition: qmltab.h:95
bool backgroundActivity
checks if the tab has associated background activity
Definition: qmltab.h:100
QString title
title of the tab
Definition: qmltab.h:43
int zoomLevel
zoom level of the tab
Definition: qmltab.h:50
Q_INVOKABLE void showSource()
Shows the page source.
Definition: qmltab.cpp:185
Q_INVOKABLE void stop()
Stops webview associated with the tab.
Definition: qmltab.cpp:57
Q_INVOKABLE void reloadBypassCache()
Reloads the tab by bypassing the cache.
Definition: qmltab.cpp:149
bool current
checks if the tab is the current tab
Definition: qmltab.h:75
void titleChanged(const QString &title)
The signal emitted when the tab title is changed.
QmlTab(WebTab *webTab=nullptr, QObject *parent=nullptr)
Definition: qmltab.cpp:26
Q_INVOKABLE void selectAll()
Performs edit select-all on the tab.
Definition: qmltab.cpp:140
Q_INVOKABLE void setZoomLevel(int zoomLevel)
Set the zoom level of the tab.
Definition: qmltab.cpp:48
void restoredChanged(bool restored)
The signal emitted when restored state of the tab is changed.
bool canGoForward
checks if the tab is can go forward
Definition: qmltab.h:110
Q_INVOKABLE void back()
Loads the previous page.
Definition: qmltab.cpp:158
void zoomLevelChanged(int zoomLevel)
The signal emitted when zoom level of the tab is changed.
void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
The signal emitted when navigation request is accepted.
Q_INVOKABLE void unload()
Unloads the tab.
Definition: qmltab.cpp:75
void playingChanged(bool playing)
The signal emitted when playing state of the tab is changed.
Q_INVOKABLE void forward()
Loads the next page.
Definition: qmltab.cpp:167
Q_INVOKABLE void undo()
Performs edit undo on the tab.
Definition: qmltab.cpp:122
QString url
url of the tab
Definition: qmltab.h:38
void loadingChanged(bool loading)
The signal emitted when loading state of the tab is changed.
Q_INVOKABLE QVariant execJavaScript(const QJSValue &value)
execute JavaScript function in a page
Definition: qmltab.cpp:203
bool muted
checks if the tab is muted
Definition: qmltab.h:65
Q_INVOKABLE void load(const QString &url)
Loads webview associated with the tab.
Definition: qmltab.cpp:84
Q_INVOKABLE void zoomOut()
Increases the zoom level of the tab.
Definition: qmltab.cpp:104
Q_INVOKABLE void zoomReset()
Resets the tab zoom level.
Definition: qmltab.cpp:113
bool playing
checks if the tab is playing
Definition: qmltab.h:80
Q_INVOKABLE void redo()
Performs edit redo on the tab.
Definition: qmltab.cpp:131
void mutedChanged(bool muted)
The signal emitted when muted state of the tab is changed.
Q_INVOKABLE void zoomIn()
Decreases the zoom level of the tab.
Definition: qmltab.cpp:95
Q_INVOKABLE QmlWebHitTestResult * hitTestContent(const QPoint &point)
Gets result of web hit test at a given point.
Definition: qmltab.cpp:215
Q_INVOKABLE void sendPageByMail()
Sends page by mail.
Definition: qmltab.cpp:194
bool canGoBack
checks if the tab is can go back
Definition: qmltab.h:105
QmlWindow * browserWindow
window of the tab
Definition: qmltab.h:85
The class exposing result of WebHitTest to QML.
The class exposing Browser window to QML.
Definition: qmlwindow.h:27
Definition: webtab.h:40
int value(const QColor &c)
Definition: colors.cpp:238