BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::MainBarWidget Class Reference

Widget container with functionality similar to QTabWidget. More...

Inheritance diagram for gui2::MainBarWidget:
[legend]
Collaboration diagram for gui2::MainBarWidget:
[legend]

Public Member Functions

 MainBarWidget (QWidget *parent=nullptr)
 
 ~MainBarWidget ()
 
void addWidget (QWidget *widget, const QString &title, bool is_enabled=true)
 
void setCurrentIndex (int index)
 

Private Attributes

std::map< int, FancyTab * > m_indexToTab
 
QHBoxLayout * m_labelLayout {nullptr}
 
QStackedWidget * m_stackedWidget {nullptr}
 

Detailed Description

Widget container with functionality similar to QTabWidget.

Has large button bar on top, and stacked widget at bottom.

Definition at line 33 of file mainbarwidget.h.

Constructor & Destructor Documentation

◆ MainBarWidget()

gui2::MainBarWidget::MainBarWidget ( QWidget *  parent = nullptr)

Definition at line 25 of file mainbarwidget.cpp.

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 }
QHBoxLayout * m_labelLayout
Definition: mainbarwidget.h:46
QStackedWidget * m_stackedWidget
Definition: mainbarwidget.h:45

References m_labelLayout, and m_stackedWidget.

◆ ~MainBarWidget()

gui2::MainBarWidget::~MainBarWidget ( )
default

Member Function Documentation

◆ addWidget()

void gui2::MainBarWidget::addWidget ( QWidget *  widget,
const QString &  title,
bool  is_enabled = true 
)

Definition at line 38 of file mainbarwidget.cpp.

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 }
std::map< int, FancyTab * > m_indexToTab
Definition: mainbarwidget.h:47
void setCurrentIndex(int index)

References gui2::FancyTab::clicked(), m_indexToTab, m_labelLayout, m_stackedWidget, and setCurrentIndex().

Referenced by gui2::MainWindow::init_components().

Here is the call graph for this function:

◆ setCurrentIndex()

void gui2::MainBarWidget::setCurrentIndex ( int  index)

Definition at line 51 of file mainbarwidget.cpp.

52 {
53  for (auto it : m_indexToTab)
54  it.second->setSelected(it.first == index);
55 
56  m_stackedWidget->setCurrentIndex(index);
57 }

References m_indexToTab, and m_stackedWidget.

Referenced by addWidget(), and gui2::MainWindow::init_components().

Member Data Documentation

◆ m_indexToTab

std::map<int, FancyTab*> gui2::MainBarWidget::m_indexToTab
private

Definition at line 47 of file mainbarwidget.h.

Referenced by addWidget(), and setCurrentIndex().

◆ m_labelLayout

QHBoxLayout* gui2::MainBarWidget::m_labelLayout {nullptr}
private

Definition at line 46 of file mainbarwidget.h.

Referenced by MainBarWidget(), and addWidget().

◆ m_stackedWidget

QStackedWidget* gui2::MainBarWidget::m_stackedWidget {nullptr}
private

Definition at line 45 of file mainbarwidget.h.

Referenced by MainBarWidget(), addWidget(), and setCurrentIndex().


The documentation for this class was generated from the following files: