BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
mainbarwidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/mainwindow/mainbarwidget.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include <QHBoxLayout>
18 #include <QLabel>
19 #include <QPushButton>
20 #include <QStackedWidget>
21 #include <QVBoxLayout>
22 
23 namespace gui2 {
24 
26  : QWidget(parent), m_stackedWidget(new QStackedWidget), m_labelLayout(new QHBoxLayout)
27 {
28  m_labelLayout->setContentsMargins(0, 0, 0, 0);
29 
30  auto layout = new QVBoxLayout(this);
31  layout->addLayout(m_labelLayout);
32  layout->addWidget(m_stackedWidget);
33  layout->setContentsMargins(0, 0, 0, 0);
34 }
35 
37 
38 void MainBarWidget::addWidget(QWidget* widget, const QString& title, bool is_enabled)
39 {
40  int index = m_stackedWidget->addWidget(widget);
41 
42  auto tab = new FancyTab(title);
43  tab->setEnabled(is_enabled);
44  auto on_tab_clicked = [this, index]() { setCurrentIndex(index); };
45  connect(tab, &FancyTab::clicked, on_tab_clicked);
46 
47  m_indexToTab[index] = tab;
48  m_labelLayout->addWidget(tab);
49 }
50 
52 {
53  for (auto it : m_indexToTab)
54  it.second->setSelected(it.first == index);
55 
56  m_stackedWidget->setCurrentIndex(index);
57 }
58 
59 } // namespace gui2
QHBoxLayout * m_labelLayout
Definition: mainbarwidget.h:46
MainBarWidget(QWidget *parent=nullptr)
void addWidget(QWidget *widget, const QString &title, bool is_enabled=true)
std::map< int, FancyTab * > m_indexToTab
Definition: mainbarwidget.h:47
void setCurrentIndex(int index)
QStackedWidget * m_stackedWidget
Definition: mainbarwidget.h:45
Defines class CLASS?
Defines class CLASS?
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20