Falkon Develop
Cross-platform Qt-based web browser
tabwidget.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@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#ifndef TABWIDGET_H
19#define TABWIDGET_H
20
21#include <QMenu>
22#include <QPointer>
23
24#include "tabstackedwidget.h"
25#include "toolbutton.h"
26#include "loadrequest.h"
27#include "webtab.h"
28#include "qzcommon.h"
29
30class QMenu;
31
32class TabBar;
33class TabIcon;
34class TabWidget;
35class BrowserWindow;
36class TabbedWebView;
38
40{
41public:
42 explicit AddTabButton(TabWidget* tabWidget, TabBar* tabBar);
43
44private:
45 void wheelEvent(QWheelEvent* event) override;
46 void mouseReleaseEvent(QMouseEvent* event) override;
47
48 TabBar* m_tabBar;
49 TabWidget* m_tabWidget;
50};
51
52class FALKON_EXPORT MenuTabs : public QMenu
53{
54 Q_OBJECT
55public:
56 explicit MenuTabs(QWidget* parent = nullptr) : QMenu(parent) {}
57
58Q_SIGNALS:
59 void closeTab(int);
60
61private:
62 void mouseReleaseEvent(QMouseEvent* event) override;
63};
64
66{
67 Q_OBJECT
68public:
69 explicit TabWidget(BrowserWindow *window, QWidget *parent = nullptr);
70 ~TabWidget() override;
71
72 BrowserWindow *browserWindow() const;
73
74 bool restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab);
75
76 void setCurrentIndex(int index);
77
78 void nextTab();
79 void previousTab();
80 void currentTabChanged(int index);
81
82 int normalTabsCount() const;
83 int pinnedTabsCount() const;
84 int extraReservedWidth() const;
85
86 WebTab *webTab(int index = -1) const;
87
88 TabBar* tabBar() const;
89 ClosedTabsManager* closedTabsManager() const;
90 QList<WebTab*> allTabs(bool withPinned = true);
91 bool canRestoreTab() const;
92 bool isCurrentTabFresh() const;
93 void setCurrentTabFresh(bool currentTabFresh);
94
95 QStackedWidget* locationBars() const;
96 ToolButton* buttonClosedTabs() const;
97 AddTabButton* buttonAddTab() const;
98
99 void moveTab(int from, int to);
100 int pinUnPinTab(int index, const QString &title = QString());
101
102 void detachTab(WebTab* tab);
103
104public Q_SLOTS:
105 int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine = false, bool pinned = false);
106 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);
107 int addView(WebTab *tab, const Qz::NewTabPositionFlags &openFlags);
108 int insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags &openFlags);
109
110 void addTabFromClipboard();
111 int duplicateTab(int index);
112
113 // Force close tab
114 void closeTab(int index = -1);
115 // Request close tab (may be rejected)
116 void requestCloseTab(int index = -1);
117
118 void reloadTab(int index);
119 void reloadAllTabs();
120 void stopTab(int index);
121 void closeAllButCurrent(int index);
122 void closeToRight(int index);
123 void closeToLeft(int index);
124 void detachTab(int index);
125 void loadTab(int index);
126 void unloadTab(int index);
127 void restoreClosedTab(QObject* obj = nullptr);
128 void restoreAllClosedTabs();
129 void clearClosedTabsList();
130
131 void moveAddTabButton(int posX);
132
133 void tabBarOverFlowChanged(bool overflowed);
134
135Q_SIGNALS:
136 void changed();
137 void tabInserted(int index);
138 void tabRemoved(int index);
139 void tabMoved(int from, int to);
140
141private Q_SLOTS:
142 void loadSettings();
143
144 void aboutToShowTabsMenu();
145 void aboutToShowClosedTabsMenu();
146
147 void actionChangeIndex();
148 void tabWasMoved(int before, int after);
149
150private:
151 WebTab* weTab() const;
152 WebTab* weTab(int index) const;
153 TabIcon* tabIcon(int index) const;
154
155 bool validIndex(int index) const;
156 void updateClosedTabsButton();
157
158 void keyPressEvent(QKeyEvent *event) override;
159 void keyReleaseEvent(QKeyEvent *event) override;
160
161 BrowserWindow* m_window;
162 TabBar* m_tabBar;
163 QStackedWidget* m_locationBars;
164 ClosedTabsManager* m_closedTabsManager;
165
166 MenuTabs* m_menuTabs;
167 ToolButton* m_buttonListTabs;
168 QMenu* m_menuClosedTabs;
169 ToolButton* m_buttonClosedTabs;
170 AddTabButton* m_buttonAddTab;
171 AddTabButton* m_buttonAddTab2;
172
173 QPointer<WebTab> m_lastBackgroundTab;
174
175 bool m_dontCloseWithOneTab;
176 bool m_showClosedTabsButton;
177 bool m_newTabAfterActive;
178 bool m_newEmptyTabAfterActive;
179 QUrl m_urlOnNewTab;
180
181 bool m_currentTabFresh;
182 bool m_blockTabMovedSignal = false;
183};
184
185#endif // TABWIDGET_H
MenuTabs(QWidget *parent=nullptr)
Definition: tabwidget.h:56
void closeTab(int)
Definition: tabbar.h:31
void changed()
void tabInserted(int index)
void tabRemoved(int index)
void tabMoved(int from, int to)
void mouseReleaseEvent(QMouseEvent *e) override
Definition: toolbutton.cpp:203
Definition: webtab.h:40
@ NT_SelectedTab
Definition: qzcommon.h:97
#define FALKON_EXPORT
Definition: qzcommon.h:28