diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-09-18 09:57:29 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-09-18 09:57:29 +0300 |
commit | 1b1e327cb73491c17972a33a07c3c9beafe7f938 (patch) | |
tree | 57fa4bc121fc2e172db42288fec7cdd7ff95399c /src/panels/tabtoolbar.cpp | |
parent | Add Bookmarks toolbar (diff) | |
download | rekonq-1b1e327cb73491c17972a33a07c3c9beafe7f938.tar.xz |
Add Navigation and Tab toolbars
Diffstat (limited to 'src/panels/tabtoolbar.cpp')
-rw-r--r-- | src/panels/tabtoolbar.cpp | 49 |
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; +} |