aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/mainwindowtabbar.cpp (renamed from src/widgets/webviewtabbar.cpp)65
-rw-r--r--src/widgets/mainwindowtabbar.h (renamed from src/widgets/webviewtabbar.h)16
2 files changed, 43 insertions, 38 deletions
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/mainwindowtabbar.cpp
index 81851f3..cae42df 100644
--- a/src/widgets/webviewtabbar.cpp
+++ b/src/widgets/mainwindowtabbar.cpp
@@ -18,58 +18,58 @@
**
******************************************************************************/
-#include "webviewtabbar.h"
+#include "mainwindowtabbar.h"
#include <QAction>
#include <QContextMenuEvent>
#include <QMenu>
#include <settings/configuration.h>
#include <QShortcut>
-WebViewTabBar::WebViewTabBar(const std::shared_ptr<Configuration> &config, WebEngineProfile *profile, QWidget *parent) :
+#include "mainwindow.h"
+
+MainWindowTabBar::MainWindowTabBar(const std::shared_ptr<Configuration> &config, MainWindow *parent) :
QTabBar(parent)
{
- m_profile = profile;
+ Q_CHECK_PTR(parent);
+ m_parent = parent;
setElideMode(Qt::ElideRight);
setTabsClosable(true);
setMovable(true);
setContextMenuPolicy(Qt::DefaultContextMenu);
- connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(removeTab(int)));
- connect(this, SIGNAL(currentChanged(int)), this, SLOT(handleCurrentChanged(int)));
- connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(updateVectorArrangement(int,int)));
- QShortcut *tabCloseShortcut = new QShortcut(this);
+ connect(this, &MainWindowTabBar::tabCloseRequested, this, &MainWindowTabBar::removeTab);
+ connect(this, &MainWindowTabBar::currentChanged, this, &MainWindowTabBar::handleCurrentChanged);
+ connect(this, &MainWindowTabBar::tabMoved, this, &MainWindowTabBar::updateVectorArrangement);
+
+ QShortcut *tabCloseShortcut = new QShortcut(parent);
tabCloseShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabClose").value())));
connect(tabCloseShortcut, &QShortcut::activated, [this]() {
this->removeTab(currentIndex());
});
- QShortcut *tabLeftShortcut = new QShortcut(this);
+ QShortcut *tabLeftShortcut = new QShortcut(parent);
tabLeftShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabLeft").value())));
connect(tabLeftShortcut, &QShortcut::activated, [this]() {
this->setCurrentIndex(currentIndex()-1);
});
- QShortcut *tabRightShortcut = new QShortcut(this);
+ QShortcut *tabRightShortcut = new QShortcut(parent);
tabRightShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabRight").value())));
connect(tabRightShortcut, &QShortcut::activated, [this]() {
this->setCurrentIndex(currentIndex()+1);
});
}
-WebViewTabBar::~WebViewTabBar()
+MainWindowTabBar::~MainWindowTabBar()
{
// cleanup
qDeleteAll(m_views);
m_views.clear();
}
-int WebViewTabBar::addTab(const QUrl &url)
+int MainWindowTabBar::addTab(WebView *view)
{
- WebView *view = new WebView(0);
- QWebEnginePage *page = new QWebEnginePage(m_profile);
- view->setPage(page);
- page->load(url);
m_views.append(view);
connect(view, &QWebEngineView::titleChanged, [this, view](const QString &title) {
@@ -84,11 +84,10 @@ int WebViewTabBar::addTab(const QUrl &url)
return QTabBar::addTab("New Tab");
}
-void WebViewTabBar::setProfile(WebEngineProfile *profile)
+void MainWindowTabBar::setProfile(WebEngineProfile *profile)
{
Q_CHECK_PTR(profile);
- m_profile = profile;
for(auto view : qAsConst(m_views)) {
QWebEnginePage *page = new QWebEnginePage(profile);
page->load(view->url());
@@ -96,17 +95,12 @@ void WebViewTabBar::setProfile(WebEngineProfile *profile)
}
}
-WebEngineProfile *WebViewTabBar::profile()
-{
- return m_profile;
-}
-
-WebView *WebViewTabBar::currentView()
+WebView *MainWindowTabBar::currentView()
{
return m_views.at(currentIndex());
}
-void WebViewTabBar::contextMenuEvent(QContextMenuEvent *event)
+void MainWindowTabBar::contextMenuEvent(QContextMenuEvent *event)
{
int tabIndex = tabAt(event->pos());
if(tabIndex < 0) {
@@ -121,22 +115,23 @@ void WebViewTabBar::contextMenuEvent(QContextMenuEvent *event)
menu.exec(event->globalPos());
}
-QSize WebViewTabBar::tabSizeHint(int index) const
+QSize MainWindowTabBar::tabSizeHint(int index) const
{
Q_UNUSED(index)
return QSize(200, this->height());
}
-void WebViewTabBar::handleCurrentChanged(int index)
+void MainWindowTabBar::handleCurrentChanged(int index)
{
if(index < 0) {
- addTab(m_profile->newtab());
+ addTab(createWebView(m_parent->profile()->homepage(), m_parent->profile()));
return;
}
+
emit currentTabChanged(m_views.at(index));
}
-void WebViewTabBar::removeTab(int index)
+void MainWindowTabBar::removeTab(int index)
{
// remove the tab data from the index
m_views.at(index)->deleteLater();
@@ -147,13 +142,23 @@ void WebViewTabBar::removeTab(int index)
QTabBar::removeTab(index);
}
-void WebViewTabBar::updateTabText(WebView *view, const QString &text)
+void MainWindowTabBar::updateTabText(WebView *view, const QString &text)
{
int index = m_views.indexOf(view);
setTabText(index, text);
}
-void WebViewTabBar::updateVectorArrangement(int from, int to)
+void MainWindowTabBar::updateVectorArrangement(int from, int to)
{
m_views.move(from, to);
}
+
+WebView *createWebView(const QUrl &url, WebEngineProfile *profile)
+{
+ WebView *view = new WebView(nullptr);
+ QWebEnginePage *page = new QWebEnginePage(profile);
+ view->setPage(page);
+ page->load(url);
+
+ return view;
+}
diff --git a/src/widgets/webviewtabbar.h b/src/widgets/mainwindowtabbar.h
index 64bb6a2..1186695 100644
--- a/src/widgets/webviewtabbar.h
+++ b/src/widgets/mainwindowtabbar.h
@@ -27,24 +27,23 @@
#include <memory>
class Configuration;
-class WebViewTabBar : public QTabBar
+class MainWindow;
+class MainWindowTabBar : public QTabBar
{
Q_OBJECT
public:
- explicit WebViewTabBar(const std::shared_ptr<Configuration> &config, WebEngineProfile *profile = nullptr, QWidget *parent = 0);
- ~WebViewTabBar();
+ explicit MainWindowTabBar(const std::shared_ptr<Configuration> &config, MainWindow *parent = nullptr);
+ ~MainWindowTabBar();
void setProfile(WebEngineProfile *profile);
- WebEngineProfile *profile();
-
WebView *currentView();
signals:
void currentTabChanged(WebView *view);
public slots:
- int addTab(const QUrl &url);
+ int addTab(WebView *view);
void removeTab(int index);
protected:
@@ -60,8 +59,9 @@ private slots:
private:
// store all views in a vector since tabs can only store a QVariant, and that can't easily take a pointer
QVector<WebView*> m_views;
-
- WebEngineProfile *m_profile = nullptr;
+ MainWindow *m_parent;
};
+WebView *createWebView(const QUrl &url, WebEngineProfile *profile);
+
#endif // WEBVIEWTABBAR_H