/* ============================================================ * The rekonq project * ============================================================ * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua * ============================================================ */ #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("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; }