aboutsummaryrefslogtreecommitdiff
path: root/src/subwindow/tabwidget.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/subwindow/tabwidget.h')
-rw-r--r--src/subwindow/tabwidget.h53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/subwindow/tabwidget.h b/src/subwindow/tabwidget.h
index de5e6fb..2a5f360 100644
--- a/src/subwindow/tabwidget.h
+++ b/src/subwindow/tabwidget.h
@@ -9,9 +9,17 @@
#ifndef SMOLBOTE_TABWIDGET_H
#define SMOLBOTE_TABWIDGET_H
-#include <QTabWidget>
-#include <QQueue>
#include <QBuffer>
+#include <QQueue>
+#include <QTabWidget>
+
+template <typename T>
+concept c_WebView = requires(T *a)
+{
+ a->title();
+ a->titleChanged(QString());
+ a->iconChanged(QIcon());
+};
class QAction;
class QMenu;
@@ -24,19 +32,34 @@ class TabWidget : public QTabWidget
Q_OBJECT
public:
- struct TabInformation
- {
- WebProfile *profile;
- QString title;
- int historyIndex;
- QByteArray historyBuffer;
- };
-
explicit TabWidget(SubWindow *parent = nullptr);
~TabWidget() override;
+ template <c_WebView T>
+ int addTab(T *view)
+ {
+ if(view == nullptr) {
+ return -1;
+ }
+
+ const int idx = QTabWidget::addTab(view, view->title());
+ connect(view, &T::titleChanged, [this, view](const QString &title) {
+ const int current_idx = indexOf(view);
+ if(current_idx != -1) {
+ setTabText(current_idx, title);
+ }
+ });
+ connect(view, &T::iconChanged, [this, view](const QIcon &icon) {
+ const int current_idx = indexOf(view);
+ if(current_idx != -1) {
+ setTabIcon(current_idx, icon);
+ }
+ });
+ //tabBar()->setTabData(idx, QVariant::fromValue<SubWindow::TabData>(SubWindow::TabData{}));
+ return idx;
+ }
+
public slots:
- int addTab(WebView *view);
void removeTab(int index);
int restoreLastTab();
@@ -47,6 +70,14 @@ protected:
void mousePressEvent(QMouseEvent *event) override;
private:
+ struct TabInformation {
+ WebProfile *profile;
+ QString title;
+ int historyIndex;
+ QByteArray historyBuffer;
+ };
+ [[nodiscard]] WebView *createViewFromInfo(TabInformation &tab, SubWindow *parent);
+
SubWindow *m_parent;
int current = -1;
int previous = -1;