Falkon Develop
Cross-platform Qt-based web browser
tabmanagerwidget.h
Go to the documentation of this file.
1/* ============================================================
2* TabManager plugin for Falkon
3* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@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 TABMANAGERWIDGET_H
19#define TABMANAGERWIDGET_H
20
21#include <QWidget>
22#include <QPointer>
23#include <QMultiHash>
24#include <QTreeWidgetItem>
25
26namespace Ui
27{
29}
30class QUrl;
31class QTreeWidgetItem;
32class BrowserWindow;
33class WebPage;
34class WebTab;
35class WebView;
36class TLDExtractor;
37
38class TabTreeWidget : public QTreeWidget
39{
40 Q_OBJECT
41
42public:
43 TabTreeWidget(QWidget* parent = nullptr);
44
45 Qt::DropActions supportedDropActions() const override;
46 QStringList mimeTypes() const override;
47 QMimeData* mimeData(const QList<QTreeWidgetItem*> &items) const override;
48 bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) override;
49
50 void setEnableDragTabs(bool enable);
51
52Q_SIGNALS:
54
55};
56
57class TabManagerWidget : public QWidget
58{
59 Q_OBJECT
60
61public:
62 enum GroupType {
65 GroupByHost = 2
66 };
67
68 explicit TabManagerWidget(BrowserWindow* mainClass, QWidget* parent = nullptr, bool defaultWidget = false);
69 ~TabManagerWidget() override;
70
71 void closeSelectedTabs(const QMultiHash<BrowserWindow*, WebTab*> &tabsHash);
72 void detachSelectedTabs(const QMultiHash<BrowserWindow*, WebTab*> &tabsHash);
73 bool bookmarkSelectedTabs(const QMultiHash<BrowserWindow*, WebTab*> &tabsHash);
74 void unloadSelectedTabs(const QMultiHash<BrowserWindow*, WebTab*> &tabsHash);
75
76 void setGroupType(GroupType type);
77
78 static QString domainFromUrl(const QUrl &url, bool useHostName = false);
79
80public Q_SLOTS:
81 void delayedRefreshTree(WebPage* p = nullptr);
82 void changeGroupType();
83
84private:
85 QTreeWidgetItem* groupByDomainName(bool useHostName = false);
86 QTreeWidgetItem* groupByWindow();
87 BrowserWindow* getWindow();
88
89 Ui::TabManagerWidget* ui;
90 QPointer<BrowserWindow> m_window;
91 WebPage* m_webPage;
92
93 bool m_isRefreshing;
94 bool m_refreshBlocked;
95 bool m_waitForRefresh;
96 bool m_isDefaultWidget;
97 GroupType m_groupType;
98
99 QString m_filterText;
100
101 static TLDExtractor* s_tldExtractor;
102
103private Q_SLOTS:
104 void refreshTree();
105 void processActions();
106 void onItemActivated(QTreeWidgetItem* item, int column);
107 bool isTabSelected();
108 void customContextMenuRequested(const QPoint &pos);
109 void filterChanged(const QString &filter, bool force = false);
110 void filterBarClosed();
111
112protected:
113 bool eventFilter(QObject* obj, QEvent* event) override;
114
115Q_SIGNALS:
118};
119
120class TabItem : public QObject, public QTreeWidgetItem
121{
122 Q_OBJECT
123
124public:
126 ActiveOrCaptionRole = Qt::UserRole + 1,
127 SavedRole = Qt::UserRole + 2
128 };
129
130 TabItem(QTreeWidget* treeWidget, bool supportDrag = true, bool isTab = true, QTreeWidgetItem* parent = nullptr, bool addToTree = true);
131
132 BrowserWindow* window() const;
134
135 WebTab* webTab() const;
136 void setWebTab(WebTab* webTab);
137
138 bool isTab() const;
139
140public Q_SLOTS:
141 void updateIcon();
142 void setTitle(const QString& title);
143 void setIsActiveOrCaption(bool yes);
144 void setIsSavedTab(bool yes);
145
146private:
147 QTreeWidget* m_treeWidget;
148 BrowserWindow* m_window;
149 WebTab* m_webTab;
150 bool m_isTab;
151};
152
153#endif // TABMANAGERWIDGET_H
bool isTab() const
void setIsActiveOrCaption(bool yes)
void setTitle(const QString &title)
void updateIcon()
void setIsSavedTab(bool yes)
void setBrowserWindow(BrowserWindow *window)
WebTab * webTab() const
BrowserWindow * window() const
TabItem(QTreeWidget *treeWidget, bool supportDrag=true, bool isTab=true, QTreeWidgetItem *parent=nullptr, bool addToTree=true)
void setWebTab(WebTab *webTab)
~TabManagerWidget() override
bool eventFilter(QObject *obj, QEvent *event) override
void delayedRefreshTree(WebPage *p=nullptr)
TabManagerWidget(BrowserWindow *mainClass, QWidget *parent=nullptr, bool defaultWidget=false)
bool bookmarkSelectedTabs(const QMultiHash< BrowserWindow *, WebTab * > &tabsHash)
void closeSelectedTabs(const QMultiHash< BrowserWindow *, WebTab * > &tabsHash)
void detachSelectedTabs(const QMultiHash< BrowserWindow *, WebTab * > &tabsHash)
void setGroupType(GroupType type)
static QString domainFromUrl(const QUrl &url, bool useHostName=false)
void groupTypeChanged(TabManagerWidget::GroupType)
void unloadSelectedTabs(const QMultiHash< BrowserWindow *, WebTab * > &tabsHash)
void setEnableDragTabs(bool enable)
Qt::DropActions supportedDropActions() const override
TabTreeWidget(QWidget *parent=nullptr)
bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) override
void requestRefreshTree()
QMimeData * mimeData(const QList< QTreeWidgetItem * > &items) const override
QStringList mimeTypes() const override
Definition: webtab.h:40