From 120a5f7c6d31a3bc5acdb54b19326516f8399767 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 11 Jan 2017 10:18:08 +0100 Subject: Initial commit --- src/widgets/webviewtabbar.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/widgets/webviewtabbar.cpp (limited to 'src/widgets/webviewtabbar.cpp') diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp new file mode 100644 index 0000000..59e5c69 --- /dev/null +++ b/src/widgets/webviewtabbar.cpp @@ -0,0 +1,50 @@ +#include "webviewtabbar.h" + +WebViewTabBar::WebViewTabBar(QWidget *parent) : + QTabBar(parent) +{ + setTabsClosable(true); + connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabClose(int))); + connect(this, SIGNAL(currentChanged(int)), this, SLOT(handleCurrentChanged(int))); +} + +WebViewTabBar::~WebViewTabBar() +{ + // cleanup + qDeleteAll(m_views); + m_views.clear(); +} + +int WebViewTabBar::addTab(QWebEngineView *view) +{ + 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); + }); + return QTabBar::addTab("New Tab"); +} + +QWebEngineView *WebViewTabBar::currentView() +{ + return m_views.at(currentIndex()); +} + +void WebViewTabBar::handleCurrentChanged(int index) +{ + emit(currentTabChanged(m_views.at(index))); +} + +void WebViewTabBar::handleTabClose(int index) +{ + removeTab(index); + m_views.at(index)->deleteLater(); + m_views.remove(index); +} + +void WebViewTabBar::updateTabText(QWebEngineView *view, const QString &text) +{ + int index = m_views.indexOf(view); + setTabText(index, text); +} -- cgit v1.2.1