summaryrefslogtreecommitdiff
path: root/src/panels/tabtoolbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/panels/tabtoolbar.cpp')
-rw-r--r--src/panels/tabtoolbar.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/panels/tabtoolbar.cpp b/src/panels/tabtoolbar.cpp
new file mode 100644
index 00000000..be3f1384
--- /dev/null
+++ b/src/panels/tabtoolbar.cpp
@@ -0,0 +1,49 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "tabtoolbar.hpp"
+
+TabToolBar::TabToolBar(QWidget *parent) : QToolBar(parent), tabs(new TabBar(this))
+{
+ addWidget(tabs);
+
+ auto *spacer = new QWidget(this);
+ spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ addWidget(spacer);
+
+ auto *actionNewTab = parent->findChild<QAction *>("actionNewTab");
+ Q_CHECK_PTR(actionNewTab);
+ addAction(QIcon::fromTheme("document-new"), "Add Tab", actionNewTab, &QAction::trigger);
+
+ // currentViewChanged
+ connect(tabs, &QTabBar::currentChanged, this, [this](int index) {
+ if (index == -1) emit currentViewChanged(nullptr);
+ else {
+ auto view = tabs->view(index);
+ Q_CHECK_PTR(view);
+ emit currentViewChanged(view);
+ }
+ });
+
+ // removeView
+ connect(tabs, &QTabBar::tabCloseRequested, this, [this](int index) { emit tabClosed(tabs->removeTab(index)); });
+}
+
+int TabToolBar::addView(RekonqView *view)
+{
+ Q_CHECK_PTR(view);
+ return tabs->addTab(view);
+}
+
+void TabToolBar::setCurrentView(RekonqView *view) { tabs->setCurrentView(view); }
+
+RekonqView *TabToolBar::currentView() const
+{
+ auto *view = tabs->view(tabs->currentIndex());
+ Q_CHECK_PTR(view);
+ return view;
+}