aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/webviewtabbar.cpp50
-rw-r--r--src/widgets/webviewtabbar.h31
2 files changed, 81 insertions, 0 deletions
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);
+}
diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h
new file mode 100644
index 0000000..28a9a18
--- /dev/null
+++ b/src/widgets/webviewtabbar.h
@@ -0,0 +1,31 @@
+#ifndef WEBVIEWTABBAR_H
+#define WEBVIEWTABBAR_H
+
+#include <QTabBar>
+#include <QWebEngineView>
+
+class WebViewTabBar : public QTabBar
+{
+ Q_OBJECT
+
+public:
+ WebViewTabBar(QWidget *parent = 0);
+ ~WebViewTabBar();
+
+ int addTab(QWebEngineView *view);
+ QWebEngineView *currentView();
+
+signals:
+ void currentTabChanged(QWebEngineView *view);
+
+private slots:
+ void handleCurrentChanged(int index);
+ void handleTabClose(int index);
+
+ void updateTabText(QWebEngineView *view, const QString &text);
+
+private:
+ QVector<QWebEngineView*> m_views;
+};
+
+#endif // WEBVIEWTABBAR_H