Falkon Develop
Cross-platform Qt-based web browser
tabmanagerwidgetcontroller.cpp
Go to the documentation of this file.
1/* ============================================================
2* TabManager plugin for Falkon
3* Copyright (C) 2013-2018 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
4* Copyright (C) 2017-2018 David Rosca <nowrep@gmail.com>
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation, either version 3 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program. If not, see <http://www.gnu.org/licenses/>.
18* ============================================================ */
21#include "browserwindow.h"
22#include "tabwidget.h"
23#include "mainapplication.h"
24#include "tabbar.h"
25#include "statusbar.h"
26#include "navigationbar.h"
27
28#include <QScreen>
29#include <QAction>
30#include <QStyle>
31
32#include <QDebug>
33
35{
36 Q_OBJECT
37public:
38 explicit TabManagerButton(QObject *parent = nullptr)
40 {
41 }
42
43 QString id() const override
44 {
45 return QSL("tabmanager-icon");
46 }
47
48 QString name() const override
49 {
50 return tr("Tab Manager button");
51 }
52};
53
54
56 : SideBarInterface(parent)
57 , m_defaultTabManager(nullptr)
58 , m_groupType(TabManagerWidget::GroupByWindow)
59{
60}
61
63= default;
64
66{
67 return tr("Tab Manager");
68}
69
71{
72 auto* act = new QAction(tr("Tab Manager"), this);
73 act->setCheckable(true);
74 act->setIcon(QIcon(QSL(":tabmanager/data/tabmanager.png")));
75 act->setShortcut(QKeySequence(QSL("Ctrl+Shift+M")));
76 act->setData(QSL("TabManager"));
77
78 return act;
79}
80
82{
83 return createTabManagerWidget(mainWindow, mainWindow);
84}
85
87{
88 if (!defaultTabManager()) {
89 return nullptr;
90 }
91
92 if (m_statusBarIcons.contains(mainWindow)) {
93 return m_statusBarIcons.value(mainWindow);
94 }
95
96 auto* icon = new TabManagerButton(this);
97 icon->setIcon(QPixmap(QSL(":tabmanager/data/tabmanager.png")));
98 icon->setTitle(tr("Tab Manager"));
99 icon->setToolTip(tr("Show Tab Manager"));
101 if (!defaultTabManager()) {
102 return;
103 }
104
105 static int frameWidth = (defaultTabManager()->frameGeometry().width() - defaultTabManager()->geometry().width()) / 2;
106 static int titleBarHeight = defaultTabManager()->style()->pixelMetric(QStyle::PM_TitleBarHeight);
107
108 QSize newSize(defaultTabManager()->width(), mainWindow->height() - titleBarHeight - frameWidth);
109 QRect newGeo(c->popupPosition(newSize), newSize);
110 defaultTabManager()->setGeometry(newGeo);
112
113 QTimer::singleShot(0, this, [=]() {
114 c->popupClosed();
115 });
116 });
117
118 QAction* showAction = createMenuAction();
119 showAction->setCheckable(false);
120 showAction->setParent(icon);
121 mainWindow->addAction(showAction);
122 connect(showAction, SIGNAL(triggered()), this, SLOT(raiseTabManager()));
123
124 m_statusBarIcons.insert(mainWindow, icon);
125 m_actions.insert(mainWindow, showAction);
126
127 return icon;
128}
129
131{
132 return m_groupType;
133}
134
136{
137 m_groupType = type;
138}
139
141{
142 auto* tabManagerWidget = new TabManagerWidget(mainClass, parent, defaultWidget);
143 tabManagerWidget->setGroupType(m_groupType);
144
145 if (defaultWidget) {
146 m_defaultTabManager = tabManagerWidget;
147 QAction* showAction = createMenuAction();
148 showAction->setCheckable(false);
149 showAction->setParent(m_defaultTabManager);
150 m_defaultTabManager->addAction(showAction);
151 connect(showAction, SIGNAL(triggered()), this, SLOT(raiseTabManager()));
152 connect(tabManagerWidget, SIGNAL(showSideBySide()), this, SLOT(showSideBySide()));
153 }
154 else {
155 m_defaultTabManager = nullptr;
156 }
157
158 connect(tabManagerWidget, SIGNAL(groupTypeChanged(TabManagerWidget::GroupType)), this, SLOT(setGroupType(TabManagerWidget::GroupType)));
159 connect(this, SIGNAL(requestRefreshTree(WebPage*)), tabManagerWidget, SLOT(delayedRefreshTree(WebPage*)));
160
161 Q_EMIT requestRefreshTree();
162
163 return tabManagerWidget;
164}
165
167{
168 return m_defaultTabManager;
169}
170
172{
173 if (window) {
174 window->statusBar()->addButton(createStatusBarIcon(window));
176 }
177}
178
180{
181 if (window) {
182 window->statusBar()->removeButton(m_statusBarIcons.value(window));
183 window->navigationBar()->removeToolButton(m_statusBarIcons.value(window));
184 window->removeAction(m_actions.value(window));
185 delete m_actions.value(window);
186 delete m_statusBarIcons.value(window);
187 m_statusBarIcons.remove(window);
188 m_actions.remove(window);
189 }
190}
191
193{
194 removeStatusBarIcon(window);
195
196 Q_EMIT requestRefreshTree();
197}
198
200{
201 if (!defaultTabManager()) {
202 return;
203 }
204
205 defaultTabManager()->activateWindow();
206 defaultTabManager()->showNormal();
207 defaultTabManager()->raise();
208}
209
211{
212 if (!defaultTabManager()) {
213 return;
214 }
215
216 const QRect &availableGeometry = defaultTabManager()->screen()->availableGeometry();
217 static int frameWidth = (defaultTabManager()->frameGeometry().width() - defaultTabManager()->geometry().width()) / 2;
218 static int titleBarHeight = defaultTabManager()->style()->pixelMetric(QStyle::PM_TitleBarHeight);
219
220 QRect managerRect(availableGeometry.left() + frameWidth, availableGeometry.top() + titleBarHeight,
221 defaultTabManager()->width(), availableGeometry.height() - titleBarHeight - frameWidth);
222 QRect windowRect(managerRect.topRight().x() + 2 * frameWidth, managerRect.top(),
223 availableGeometry.width() - managerRect.width() - 4 * frameWidth, managerRect.height());
224
225 defaultTabManager()->setGeometry(managerRect);
226 mApp->getWindow()->setGeometry(windowRect);
227 mApp->getWindow()->showNormal();
228 mApp->getWindow()->raise();
229
230 defaultTabManager()->show();
231 defaultTabManager()->activateWindow();
232 defaultTabManager()->raise();
233}
234
236{
237 Q_EMIT requestRefreshTree();
238}
239
240#include "tabmanagerwidgetcontroller.moc"
void clicked(AbstractButtonInterface::ClickController *controller)
NavigationBar * navigationBar() const
StatusBar * statusBar() const
void removeToolButton(AbstractButtonInterface *button)
void addToolButton(AbstractButtonInterface *button)
void addButton(AbstractButtonInterface *button)
Definition: statusbar.cpp:217
void removeButton(AbstractButtonInterface *button)
Definition: statusbar.cpp:235
QString name() const override
TabManagerButton(QObject *parent=nullptr)
QString id() const override
TabManagerWidget * createTabManagerWidget(BrowserWindow *mainClass, QWidget *parent=nullptr, bool defaultWidget=false)
void mainWindowDeleted(BrowserWindow *window)
void setGroupType(TabManagerWidget::GroupType type)
TabManagerWidgetController(QObject *parent=nullptr)
QWidget * createSideBarWidget(BrowserWindow *mainWindow) override
void removeStatusBarIcon(BrowserWindow *window)
TabManagerWidget::GroupType groupType()
AbstractButtonInterface * createStatusBarIcon(BrowserWindow *mainWindow)
void addStatusBarIcon(BrowserWindow *window)
void requestRefreshTree(WebPage *p=nullptr)
~TabManagerWidgetController() override
#define mApp
#define QSL(x)
Definition: qzcommon.h:40