summaryrefslogtreecommitdiff
path: root/src/panels/tabtoolbar.cpp
blob: be3f13843e61fa1cd483dbcb988af21dac62cef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}