aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/webviewtabbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/webviewtabbar.cpp')
-rw-r--r--src/widgets/webviewtabbar.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp
index 429b103..d57e095 100644
--- a/src/widgets/webviewtabbar.cpp
+++ b/src/widgets/webviewtabbar.cpp
@@ -22,12 +22,15 @@
#include "browser.h"
#include <QAction>
-WebViewTabBar::WebViewTabBar(QWidget *parent) :
+WebViewTabBar::WebViewTabBar(QWebEngineProfile *profile, QWidget *parent) :
QTabBar(parent)
{
+ m_profile = profile;
+
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)));
@@ -73,15 +76,14 @@ QSignalMapper *WebViewTabBar::signalMapper()
return m_signalMapper;
}
-int WebViewTabBar::addTab(QWebEngineProfile *profile, const QUrl &url)
+int WebViewTabBar::addTab(const QUrl &url)
{
WebView *view = new WebView(0);
- QWebEnginePage *page = new QWebEnginePage(profile);
+ QWebEnginePage *page = new QWebEnginePage(m_profile);
view->setPage(page);
page->load(url);
m_views.append(view);
- //connect(view, SIGNAL(titleChanged()), this, SLOT(updateTabText()));
connect(view, &QWebEngineView::titleChanged, [this, view](const QString &title) {
int index = m_views.indexOf(view);
setTabText(index, title);
@@ -96,6 +98,7 @@ int WebViewTabBar::addTab(QWebEngineProfile *profile, const QUrl &url)
void WebViewTabBar::setProfile(QWebEngineProfile *profile)
{
+ m_profile = profile;
for(auto view : qAsConst(m_views)) {
QWebEnginePage *page = new QWebEnginePage(profile);
page->load(view->url());
@@ -108,6 +111,21 @@ WebView *WebViewTabBar::currentView()
return m_views.at(currentIndex());
}
+void WebViewTabBar::contextMenuEvent(QContextMenuEvent *event)
+{
+ int tabIndex = tabAt(event->pos());
+ if(tabIndex < 0) {
+ return;
+ }
+
+ QMenu menu(this);
+ QAction* closeAction = menu.addAction(tr("Close tab"));
+ connect(closeAction, &QAction::triggered, this, [tabIndex, this]() {
+ removeTab(tabIndex);
+ });
+ menu.exec(event->globalPos());
+}
+
QSize WebViewTabBar::tabSizeHint(int index) const
{
Q_UNUSED(index)
@@ -116,6 +134,10 @@ QSize WebViewTabBar::tabSizeHint(int index) const
void WebViewTabBar::handleCurrentChanged(int index)
{
+ if(index < 0) {
+ addTab(QUrl::fromUserInput(sSettings->value("general.newtab").toString()));
+ return;
+ }
emit currentTabChanged(m_views.at(index));
}