File indexing completed on 2024-12-22 04:41:14
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #pragma once 0019 0020 #include <QObject> 0021 #include <QJSValue> 0022 #include <QWebEnginePage> 0023 0024 #include "webtab.h" 0025 #include "../windows/qmlwindow.h" 0026 #include "qml/api/menus/qmlwebhittestresult.h" 0027 0028 /** 0029 * @brief The class exposing a browser tab to QML 0030 */ 0031 class QmlTab : public QObject 0032 { 0033 Q_OBJECT 0034 0035 /** 0036 * @brief url of the tab 0037 */ 0038 Q_PROPERTY(QString url READ url CONSTANT) 0039 0040 /** 0041 * @brief title of the tab 0042 */ 0043 Q_PROPERTY(QString title READ title CONSTANT) 0044 0045 /** 0046 * @brief zoom level of the tab 0047 * 0048 * Zoom levels are from 0 to 18 0049 */ 0050 Q_PROPERTY(int zoomLevel READ zoomLevel CONSTANT) 0051 0052 /** 0053 * @brief index of the tab 0054 */ 0055 Q_PROPERTY(int index READ index CONSTANT) 0056 0057 /** 0058 * @brief checks if the tab is pinned 0059 */ 0060 Q_PROPERTY(bool pinned READ pinned CONSTANT) 0061 0062 /** 0063 * @brief checks if the tab is muted 0064 */ 0065 Q_PROPERTY(bool muted READ muted CONSTANT) 0066 0067 /** 0068 * @brief checks if the tab is restored 0069 */ 0070 Q_PROPERTY(bool restored READ restored CONSTANT) 0071 0072 /** 0073 * @brief checks if the tab is the current tab 0074 */ 0075 Q_PROPERTY(bool current READ current CONSTANT) 0076 0077 /** 0078 * @brief checks if the tab is playing 0079 */ 0080 Q_PROPERTY(bool playing READ playing CONSTANT) 0081 0082 /** 0083 * @brief window of the tab 0084 */ 0085 Q_PROPERTY(QmlWindow* browserWindow READ browserWindow CONSTANT) 0086 0087 /** 0088 * @brief checks if the tab is loading 0089 */ 0090 Q_PROPERTY(bool loading READ loading CONSTANT) 0091 0092 /** 0093 * @brief get the loading progress of the tab 0094 */ 0095 Q_PROPERTY(int loadingProgress READ loadingProgress CONSTANT) 0096 0097 /** 0098 * @brief checks if the tab has associated background activity 0099 */ 0100 Q_PROPERTY(bool backgroundActivity READ backgroundActivity CONSTANT) 0101 0102 /** 0103 * @brief checks if the tab is can go back 0104 */ 0105 Q_PROPERTY(bool canGoBack READ canGoBack CONSTANT) 0106 0107 /** 0108 * @brief checks if the tab is can go forward 0109 */ 0110 Q_PROPERTY(bool canGoForward READ canGoForward CONSTANT) 0111 public: 0112 explicit QmlTab(WebTab *webTab = nullptr, QObject *parent = nullptr); 0113 0114 /** 0115 * @brief Detaches the tab 0116 */ 0117 Q_INVOKABLE void detach(); 0118 /** 0119 * @brief Set the zoom level of the tab 0120 * @param Integer representing the zoom level 0121 */ 0122 Q_INVOKABLE void setZoomLevel(int zoomLevel); 0123 /** 0124 * @brief Stops webview associated with the tab 0125 */ 0126 Q_INVOKABLE void stop(); 0127 /** 0128 * @brief Reloads webview associated with the tab 0129 */ 0130 Q_INVOKABLE void reload(); 0131 /** 0132 * @brief Unloads the tab 0133 */ 0134 Q_INVOKABLE void unload(); 0135 /** 0136 * @brief Loads webview associated with the tab 0137 * @param String representing the url to load 0138 */ 0139 Q_INVOKABLE void load(const QString &url); 0140 /** 0141 * @brief Decreases the zoom level of the tab 0142 */ 0143 Q_INVOKABLE void zoomIn(); 0144 /** 0145 * @brief Increases the zoom level of the tab 0146 */ 0147 Q_INVOKABLE void zoomOut(); 0148 /** 0149 * @brief Resets the tab zoom level 0150 */ 0151 Q_INVOKABLE void zoomReset(); 0152 /** 0153 * @brief Performs edit undo on the tab 0154 */ 0155 Q_INVOKABLE void undo(); 0156 /** 0157 * @brief Performs edit redo on the tab 0158 */ 0159 Q_INVOKABLE void redo(); 0160 /** 0161 * @brief Performs edit select-all on the tab 0162 */ 0163 Q_INVOKABLE void selectAll(); 0164 /** 0165 * @brief Reloads the tab by bypassing the cache 0166 */ 0167 Q_INVOKABLE void reloadBypassCache(); 0168 /** 0169 * @brief Loads the previous page 0170 */ 0171 Q_INVOKABLE void back(); 0172 /** 0173 * @brief Loads the next page 0174 */ 0175 Q_INVOKABLE void forward(); 0176 /** 0177 * @brief Prints the page 0178 */ 0179 Q_INVOKABLE void printPage(); 0180 /** 0181 * @brief Shows the page source 0182 */ 0183 Q_INVOKABLE void showSource(); 0184 /** 0185 * @brief Sends page by mail 0186 */ 0187 Q_INVOKABLE void sendPageByMail(); 0188 /** 0189 * @brief execute JavaScript function in a page 0190 * @param value, representing JavaScript function 0191 * @return QVariant, the return value of executed javascript 0192 */ 0193 Q_INVOKABLE QVariant execJavaScript(const QJSValue &value); 0194 /** 0195 * @brief Gets result of web hit test at a given point 0196 * @param point 0197 * @return result of web hit test 0198 */ 0199 Q_INVOKABLE QmlWebHitTestResult *hitTestContent(const QPoint &point); 0200 0201 void setWebPage(WebPage *webPage); 0202 0203 Q_SIGNALS: 0204 /** 0205 * @brief The signal emitted when the tab title is changed 0206 * @param String representing the new title 0207 */ 0208 void titleChanged(const QString &title); 0209 0210 /** 0211 * @brief The signal emitted when pinned state of the tab is changed 0212 * @param Bool representing if a tab is pinned 0213 */ 0214 void pinnedChanged(bool pinned); 0215 0216 /** 0217 * @brief The signal emitted when loading state of the tab is changed 0218 * @param Bool representing if the tab is loading 0219 */ 0220 void loadingChanged(bool loading); 0221 0222 /** 0223 * @brief The signal emitted when muted state of the tab is changed 0224 * @param Bool representing if the tab is muted 0225 */ 0226 void mutedChanged(bool muted); 0227 0228 /** 0229 * @brief The signal emitted when restored state of the tab is changed 0230 * @param Bool representing if the tab is restored 0231 */ 0232 void restoredChanged(bool restored); 0233 0234 /** 0235 * @brief The signal emitted when playing state of the tab is changed 0236 * @param Bool representing if the tab is in playing state 0237 */ 0238 void playingChanged(bool playing); 0239 0240 /** 0241 * @brief The signal emitted when zoom level of the tab is changed 0242 * @param Integer representing the zoom level 0243 */ 0244 void zoomLevelChanged(int zoomLevel); 0245 0246 /** 0247 * @brief The signal emitted when background activity of the tab is changed 0248 * @param Bool representing if there is background activity attached to the tab 0249 */ 0250 void backgroundActivityChanged(int backgroundActivityChanged); 0251 0252 /** 0253 * @brief The signal emitted when navigation request is accepted 0254 * @param url, representing requested url 0255 * @param type of navigation 0256 * @param isMainFrame, represents if navigation is requested for a top level page. 0257 */ 0258 void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame); 0259 0260 private: 0261 WebTab *m_webTab = nullptr; 0262 WebPage *m_webPage = nullptr; 0263 QList<QMetaObject::Connection> m_lambdaConnections; 0264 0265 QString url() const; 0266 QString title() const; 0267 int zoomLevel() const; 0268 int index() const; 0269 bool pinned() const; 0270 bool muted() const; 0271 bool restored() const; 0272 bool current() const; 0273 bool playing() const; 0274 QmlWindow *browserWindow() const; 0275 bool loading() const; 0276 int loadingProgress() const; 0277 bool backgroundActivity() const; 0278 bool canGoBack() const; 0279 bool canGoForward() const; 0280 0281 void createConnections(); 0282 void removeConnections(); 0283 };