2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2018-01-01 11:57:31 +01:00
|
|
|
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifndef TABWIDGET_H
|
|
|
|
#define TABWIDGET_H
|
|
|
|
|
2013-06-14 12:28:38 +02:00
|
|
|
#include <QMenu>
|
2018-02-04 13:14:46 +01:00
|
|
|
#include <QPointer>
|
2011-11-03 20:12:35 +01:00
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
#include "tabstackedwidget.h"
|
2012-03-05 11:30:18 +01:00
|
|
|
#include "toolbutton.h"
|
2014-03-19 21:27:43 +01:00
|
|
|
#include "loadrequest.h"
|
2012-08-21 20:28:38 +02:00
|
|
|
#include "webtab.h"
|
2014-03-17 15:01:28 +01:00
|
|
|
#include "qzcommon.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
class QMenu;
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
class TabBar;
|
2014-03-17 10:43:18 +01:00
|
|
|
class TabIcon;
|
2012-03-05 11:30:18 +01:00
|
|
|
class TabWidget;
|
2014-03-17 15:01:28 +01:00
|
|
|
class BrowserWindow;
|
|
|
|
class TabbedWebView;
|
2011-05-07 12:59:53 +02:00
|
|
|
class ClosedTabsManager;
|
2012-03-05 11:30:18 +01:00
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT AddTabButton : public ToolButton
|
2012-03-05 11:30:18 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AddTabButton(TabWidget* tabWidget, TabBar* tabBar);
|
|
|
|
|
|
|
|
private:
|
2012-05-27 12:44:56 +02:00
|
|
|
void wheelEvent(QWheelEvent* event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
2012-03-05 11:30:18 +01:00
|
|
|
|
|
|
|
TabBar* m_tabBar;
|
|
|
|
TabWidget* m_tabWidget;
|
|
|
|
};
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT MenuTabs : public QMenu
|
2013-06-14 12:28:38 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-18 11:03:52 +02:00
|
|
|
explicit MenuTabs(QWidget* parent = 0) : QMenu(parent) {}
|
2013-06-14 12:28:38 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void closeTab(int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
|
|
|
};
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT TabWidget : public TabStackedWidget
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-02-04 11:02:02 +01:00
|
|
|
explicit TabWidget(BrowserWindow *window, QWidget *parent = nullptr);
|
2011-03-02 16:57:41 +01:00
|
|
|
~TabWidget();
|
|
|
|
|
2018-02-04 11:02:02 +01:00
|
|
|
BrowserWindow *browserWindow() const;
|
|
|
|
|
2013-02-26 12:56:11 +01:00
|
|
|
bool restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab);
|
2012-03-13 17:51:06 +01:00
|
|
|
|
2012-09-03 22:40:52 +02:00
|
|
|
void setCurrentIndex(int index);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-22 17:19:10 +01:00
|
|
|
void nextTab();
|
|
|
|
void previousTab();
|
2013-02-09 13:00:45 +01:00
|
|
|
void currentTabChanged(int index);
|
2012-03-22 17:19:10 +01:00
|
|
|
|
2012-08-24 19:24:48 +02:00
|
|
|
int normalTabsCount() const;
|
|
|
|
int pinnedTabsCount() const;
|
2014-03-18 17:35:44 +01:00
|
|
|
int extraReservedWidth() const;
|
2012-03-22 17:19:10 +01:00
|
|
|
|
2018-02-05 11:41:15 +01:00
|
|
|
WebTab *webTab(int index = -1) const;
|
|
|
|
|
2014-04-04 17:14:31 +02:00
|
|
|
TabBar* tabBar() const;
|
2013-02-09 13:00:45 +01:00
|
|
|
ClosedTabsManager* closedTabsManager() const;
|
2011-04-18 21:35:57 +02:00
|
|
|
QList<WebTab*> allTabs(bool withPinned = true);
|
2013-02-09 13:00:45 +01:00
|
|
|
bool canRestoreTab() const;
|
2016-08-15 13:54:54 +02:00
|
|
|
bool isCurrentTabFresh() const;
|
|
|
|
void setCurrentTabFresh(bool currentTabFresh);
|
2013-02-09 13:00:45 +01:00
|
|
|
|
|
|
|
QStackedWidget* locationBars() const;
|
2014-03-17 15:01:28 +01:00
|
|
|
ToolButton* buttonClosedTabs() const;
|
2013-02-09 13:00:45 +01:00
|
|
|
AddTabButton* buttonAddTab() const;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2018-02-12 16:16:53 +01:00
|
|
|
void moveTab(int from, int to);
|
2018-02-01 20:21:11 +01:00
|
|
|
int pinUnPinTab(int index, const QString &title = QString());
|
|
|
|
|
2017-10-03 14:42:28 +02:00
|
|
|
void detachTab(WebTab* tab);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
public slots:
|
2014-03-19 21:27:43 +01:00
|
|
|
int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine = false, bool pinned = false);
|
|
|
|
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);
|
2018-01-01 11:57:31 +01:00
|
|
|
int addView(WebTab *tab, const Qz::NewTabPositionFlags &openFlags);
|
|
|
|
int insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags &openFlags);
|
2012-03-10 13:57:50 +01:00
|
|
|
|
2013-06-02 16:46:26 +02:00
|
|
|
void addTabFromClipboard();
|
2011-12-29 15:45:29 +01:00
|
|
|
int duplicateTab(int index);
|
|
|
|
|
2015-10-12 12:04:48 +02:00
|
|
|
// Force close tab
|
|
|
|
void closeTab(int index = -1);
|
|
|
|
// Request close tab (may be rejected)
|
|
|
|
void requestCloseTab(int index = -1);
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
void reloadTab(int index);
|
2011-03-02 16:57:41 +01:00
|
|
|
void reloadAllTabs();
|
2012-01-21 23:19:38 +01:00
|
|
|
void stopTab(int index);
|
2011-03-02 16:57:41 +01:00
|
|
|
void closeAllButCurrent(int index);
|
2016-08-28 16:24:09 +02:00
|
|
|
void closeToRight(int index);
|
|
|
|
void closeToLeft(int index);
|
2013-05-13 22:01:36 +02:00
|
|
|
void detachTab(int index);
|
2018-01-28 21:53:38 +01:00
|
|
|
void loadTab(int index);
|
2018-01-23 17:02:51 +01:00
|
|
|
void unloadTab(int index);
|
2013-02-07 15:01:25 +01:00
|
|
|
void restoreClosedTab(QObject* obj = 0);
|
2011-05-16 21:36:39 +02:00
|
|
|
void restoreAllClosedTabs();
|
2011-07-28 21:59:56 +02:00
|
|
|
void clearClosedTabsList();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-23 14:44:18 +02:00
|
|
|
void moveAddTabButton(int posX);
|
|
|
|
|
2014-03-18 17:35:44 +01:00
|
|
|
void tabBarOverFlowChanged(bool overflowed);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
2014-03-06 16:12:36 +01:00
|
|
|
signals:
|
|
|
|
void changed();
|
2018-01-30 14:53:18 +01:00
|
|
|
void tabInserted(int index);
|
|
|
|
void tabRemoved(int index);
|
|
|
|
void tabMoved(int from, int to);
|
2014-03-06 16:12:36 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
private slots:
|
2014-03-09 12:49:45 +01:00
|
|
|
void loadSettings();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void aboutToShowTabsMenu();
|
2014-03-17 15:01:28 +01:00
|
|
|
void aboutToShowClosedTabsMenu();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void actionChangeIndex();
|
2018-01-30 14:53:18 +01:00
|
|
|
void tabWasMoved(int before, int after);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
private:
|
2018-02-05 11:41:15 +01:00
|
|
|
WebTab* weTab() const;
|
|
|
|
WebTab* weTab(int index) const;
|
|
|
|
TabIcon* tabIcon(int index) const;
|
2014-03-17 10:43:18 +01:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
bool validIndex(int index) const;
|
|
|
|
void updateClosedTabsButton();
|
2013-02-09 13:00:45 +01:00
|
|
|
|
2018-02-04 10:11:38 +01:00
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
|
|
|
void keyReleaseEvent(QKeyEvent *event) override;
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
BrowserWindow* m_window;
|
2011-03-02 16:57:41 +01:00
|
|
|
TabBar* m_tabBar;
|
2014-03-17 15:01:28 +01:00
|
|
|
QStackedWidget* m_locationBars;
|
|
|
|
ClosedTabsManager* m_closedTabsManager;
|
|
|
|
|
2013-06-14 12:28:38 +02:00
|
|
|
MenuTabs* m_menuTabs;
|
2011-09-11 19:15:06 +02:00
|
|
|
ToolButton* m_buttonListTabs;
|
2014-03-17 15:01:28 +01:00
|
|
|
QMenu* m_menuClosedTabs;
|
|
|
|
ToolButton* m_buttonClosedTabs;
|
2012-03-05 11:30:18 +01:00
|
|
|
AddTabButton* m_buttonAddTab;
|
2013-11-26 14:14:36 +01:00
|
|
|
AddTabButton* m_buttonAddTab2;
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2018-02-04 13:14:46 +01:00
|
|
|
QPointer<WebTab> m_lastBackgroundTab;
|
2014-03-17 15:01:28 +01:00
|
|
|
|
|
|
|
bool m_dontCloseWithOneTab;
|
|
|
|
bool m_showClosedTabsButton;
|
|
|
|
bool m_newTabAfterActive;
|
|
|
|
bool m_newEmptyTabAfterActive;
|
|
|
|
QUrl m_urlOnNewTab;
|
2016-08-15 13:54:54 +02:00
|
|
|
|
|
|
|
bool m_currentTabFresh;
|
2018-02-12 17:49:27 +01:00
|
|
|
bool m_blockTabMovedSignal = false;
|
2011-03-02 16:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TABWIDGET_H
|