File indexing completed on 2024-05-12 04:58:31
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2018 David Rosca <nowrep@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 #ifndef WEBTAB_H 0019 #define WEBTAB_H 0020 0021 #include <QWidget> 0022 #include <QIcon> 0023 #include <QUrl> 0024 0025 #include "qzcommon.h" 0026 0027 class QVBoxLayout; 0028 class QWebEngineHistory; 0029 class QSplitter; 0030 0031 class BrowserWindow; 0032 class TabbedWebView; 0033 class WebInspector; 0034 class LocationBar; 0035 class TabIcon; 0036 class TabBar; 0037 class LoadRequest; 0038 0039 class FALKON_EXPORT WebTab : public QWidget 0040 { 0041 Q_OBJECT 0042 public: 0043 struct FALKON_EXPORT SavedTab { 0044 QString title; 0045 QUrl url; 0046 QIcon icon; 0047 QByteArray history; 0048 bool isPinned; 0049 int zoomLevel; 0050 int parentTab; 0051 QVector<int> childTabs; 0052 QHash<QString, QVariant> sessionData; 0053 0054 SavedTab(); 0055 SavedTab(WebTab* webTab); 0056 0057 bool isValid() const; 0058 void clear(); 0059 0060 friend FALKON_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab); 0061 friend FALKON_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab); 0062 }; 0063 0064 enum AddChildBehavior { 0065 AppendChild = 0, 0066 PrependChild 0067 }; 0068 0069 explicit WebTab(QWidget *parent = nullptr); 0070 0071 BrowserWindow *browserWindow() const; 0072 TabbedWebView* webView() const; 0073 LocationBar* locationBar() const; 0074 TabIcon* tabIcon() const; 0075 0076 WebTab *parentTab() const; 0077 void setParentTab(WebTab *tab); 0078 void addChildTab(WebTab *tab, int index = -1); 0079 QVector<WebTab*> childTabs() const; 0080 0081 QHash<QString, QVariant> sessionData() const; 0082 void setSessionData(const QString &key, const QVariant &value); 0083 0084 QUrl url() const; 0085 QString title(bool allowEmpty = false) const; 0086 QIcon icon(bool allowNull = false) const; 0087 QWebEngineHistory* history() const; 0088 int zoomLevel() const; 0089 void setZoomLevel(int level); 0090 0091 void detach(); 0092 void attach(BrowserWindow* window); 0093 0094 QByteArray historyData() const; 0095 0096 void stop(); 0097 void reload(); 0098 void load(const LoadRequest &request); 0099 void unload(); 0100 bool isLoading() const; 0101 0102 bool isPinned() const; 0103 void setPinned(bool state); 0104 void togglePinned(); 0105 0106 bool isMuted() const; 0107 bool isPlaying() const; 0108 void setMuted(bool muted); 0109 void toggleMuted(); 0110 0111 bool backgroundActivity() const; 0112 0113 int tabIndex() const; 0114 0115 bool isCurrentTab() const; 0116 void makeCurrentTab(); 0117 void closeTab(); 0118 void moveTab(int to); 0119 0120 bool haveInspector() const; 0121 void showWebInspector(bool inspectElement = false); 0122 void toggleWebInspector(); 0123 0124 void showSearchToolBar(const QString &searchText = QString()); 0125 0126 bool isRestored() const; 0127 void restoreTab(const SavedTab &tab); 0128 void p_restoreTab(const SavedTab &tab); 0129 void p_restoreTab(const QUrl &url, const QByteArray &history, int zoomLevel); 0130 0131 void tabActivated(); 0132 0133 static AddChildBehavior addChildBehavior(); 0134 static void setAddChildBehavior(AddChildBehavior behavior); 0135 0136 private Q_SLOTS: 0137 void showNotification(QWidget* notif); 0138 void loadFinished(); 0139 0140 Q_SIGNALS: 0141 void titleChanged(const QString &title); 0142 void iconChanged(const QIcon &icon); 0143 void pinnedChanged(bool pinned); 0144 void restoredChanged(bool restored); 0145 void currentTabChanged(bool current); 0146 void loadingChanged(bool loading); 0147 void mutedChanged(bool muted); 0148 void playingChanged(bool playing); 0149 void backgroundActivityChanged(bool activity); 0150 void parentTabChanged(WebTab *tab); 0151 void childTabAdded(WebTab *tab, int index); 0152 void childTabRemoved(WebTab *tab, int index); 0153 0154 private: 0155 void titleWasChanged(const QString &title); 0156 void resizeEvent(QResizeEvent *event) override; 0157 void removeFromTabTree(); 0158 0159 QVBoxLayout* m_layout; 0160 QSplitter* m_splitter; 0161 0162 TabbedWebView* m_webView; 0163 WebInspector* m_inspector; 0164 LocationBar* m_locationBar; 0165 TabIcon* m_tabIcon; 0166 QWidget *m_notificationWidget; 0167 BrowserWindow* m_window = nullptr; 0168 TabBar* m_tabBar = nullptr; 0169 0170 WebTab *m_parentTab = nullptr; 0171 QVector<WebTab*> m_childTabs; 0172 QHash<QString, QVariant> m_sessionData; 0173 0174 SavedTab m_savedTab; 0175 bool m_isPinned = false; 0176 bool m_isCurrentTab = false; 0177 }; 0178 0179 #endif // WEBTAB_H