File indexing completed on 2024-05-12 04:58:25
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 TABWIDGET_H 0019 #define TABWIDGET_H 0020 0021 #include <QMenu> 0022 #include <QPointer> 0023 0024 #include "tabstackedwidget.h" 0025 #include "toolbutton.h" 0026 #include "loadrequest.h" 0027 #include "webtab.h" 0028 #include "qzcommon.h" 0029 0030 class QMenu; 0031 0032 class TabBar; 0033 class TabIcon; 0034 class TabWidget; 0035 class BrowserWindow; 0036 class TabbedWebView; 0037 class ClosedTabsManager; 0038 0039 class FALKON_EXPORT AddTabButton : public ToolButton 0040 { 0041 public: 0042 explicit AddTabButton(TabWidget* tabWidget, TabBar* tabBar); 0043 0044 private: 0045 void wheelEvent(QWheelEvent* event) override; 0046 void mouseReleaseEvent(QMouseEvent* event) override; 0047 0048 TabBar* m_tabBar; 0049 TabWidget* m_tabWidget; 0050 }; 0051 0052 class FALKON_EXPORT MenuTabs : public QMenu 0053 { 0054 Q_OBJECT 0055 public: 0056 explicit MenuTabs(QWidget* parent = nullptr) : QMenu(parent) {} 0057 0058 Q_SIGNALS: 0059 void closeTab(int); 0060 0061 private: 0062 void mouseReleaseEvent(QMouseEvent* event) override; 0063 }; 0064 0065 class FALKON_EXPORT TabWidget : public TabStackedWidget 0066 { 0067 Q_OBJECT 0068 public: 0069 explicit TabWidget(BrowserWindow *window, QWidget *parent = nullptr); 0070 ~TabWidget() override; 0071 0072 BrowserWindow *browserWindow() const; 0073 0074 bool restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab); 0075 0076 void setCurrentIndex(int index); 0077 0078 void nextTab(); 0079 void previousTab(); 0080 void currentTabChanged(int index); 0081 0082 int normalTabsCount() const; 0083 int pinnedTabsCount() const; 0084 int extraReservedWidth() const; 0085 0086 WebTab *webTab(int index = -1) const; 0087 0088 TabBar* tabBar() const; 0089 ClosedTabsManager* closedTabsManager() const; 0090 QList<WebTab*> allTabs(bool withPinned = true); 0091 bool canRestoreTab() const; 0092 bool isCurrentTabFresh() const; 0093 void setCurrentTabFresh(bool currentTabFresh); 0094 0095 QStackedWidget* locationBars() const; 0096 ToolButton* buttonClosedTabs() const; 0097 AddTabButton* buttonAddTab() const; 0098 0099 void moveTab(int from, int to); 0100 int pinUnPinTab(int index, const QString &title = QString()); 0101 0102 void detachTab(WebTab* tab); 0103 0104 public Q_SLOTS: 0105 int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine = false, bool pinned = false); 0106 int addView(const LoadRequest &req, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1, bool pinned = false); 0107 int addView(WebTab *tab, const Qz::NewTabPositionFlags &openFlags); 0108 int insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags &openFlags); 0109 0110 void addTabFromClipboard(); 0111 int duplicateTab(int index); 0112 0113 // Force close tab 0114 void closeTab(int index = -1); 0115 // Request close tab (may be rejected) 0116 void requestCloseTab(int index = -1); 0117 0118 void reloadTab(int index); 0119 void reloadAllTabs(); 0120 void stopTab(int index); 0121 void closeAllButCurrent(int index); 0122 void closeToRight(int index); 0123 void closeToLeft(int index); 0124 void detachTab(int index); 0125 void loadTab(int index); 0126 void unloadTab(int index); 0127 void restoreClosedTab(QObject* obj = nullptr); 0128 void restoreAllClosedTabs(); 0129 void clearClosedTabsList(); 0130 0131 void moveAddTabButton(int posX); 0132 0133 void tabBarOverFlowChanged(bool overflowed); 0134 0135 Q_SIGNALS: 0136 void changed(); 0137 void tabInserted(int index); 0138 void tabRemoved(int index); 0139 void tabMoved(int from, int to); 0140 0141 private Q_SLOTS: 0142 void loadSettings(); 0143 0144 void aboutToShowTabsMenu(); 0145 void aboutToShowClosedTabsMenu(); 0146 0147 void actionChangeIndex(); 0148 void tabWasMoved(int before, int after); 0149 0150 private: 0151 WebTab* weTab() const; 0152 WebTab* weTab(int index) const; 0153 TabIcon* tabIcon(int index) const; 0154 0155 bool validIndex(int index) const; 0156 void updateClosedTabsButton(); 0157 0158 void keyPressEvent(QKeyEvent *event) override; 0159 void keyReleaseEvent(QKeyEvent *event) override; 0160 0161 BrowserWindow* m_window; 0162 TabBar* m_tabBar; 0163 QStackedWidget* m_locationBars; 0164 ClosedTabsManager* m_closedTabsManager; 0165 0166 MenuTabs* m_menuTabs; 0167 ToolButton* m_buttonListTabs; 0168 QMenu* m_menuClosedTabs; 0169 ToolButton* m_buttonClosedTabs; 0170 AddTabButton* m_buttonAddTab; 0171 AddTabButton* m_buttonAddTab2; 0172 0173 QPointer<WebTab> m_lastBackgroundTab; 0174 0175 bool m_dontCloseWithOneTab; 0176 bool m_showClosedTabsButton; 0177 bool m_newTabAfterActive; 0178 bool m_newEmptyTabAfterActive; 0179 QUrl m_urlOnNewTab; 0180 0181 bool m_currentTabFresh; 0182 bool m_blockTabMovedSignal = false; 0183 }; 0184 0185 #endif // TABWIDGET_H