BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupBoxCollapser Class Reference

Description

Add-on to group boxes to make them collapsible.

Also adds the possibility to show toolbuttons or widgets in the group box's title. This add-on takes the layout (plus the contained widgets) of a given group box and moves it into a newly created content area widget. A title widget will be added, and the original group box title will be hidden.

To support style sheets, the custom bool property "collapsible" will be added to the group box an set to true.

Definition at line 34 of file GroupBoxCollapser.h.

Inheritance diagram for GroupBoxCollapser:
[legend]
Collaboration diagram for GroupBoxCollapser:
[legend]

Public Member Functions

void addAction (QAction *action)
 Add a tool button to the title bar, connected to the given action. More...
 
void addWidget (QWidget *widget)
 Add a widget to the title bar. More...
 
QWidget * contentArea () const
 The content area, to which the found group box content has been moved when the add-on has been installed. More...
 
void setExpanded (bool expanded=true)
 Expand/collapse the content area. More...
 
void setTitle (const QString &title)
 Set the title of the group box. Do not use the method groupBox->setTitle() any more once the add-on is installed. More...
 

Static Public Member Functions

static GroupBoxCollapserfindInstalledCollapser (QGroupBox *groupBox)
 
static GroupBoxCollapserinstallIntoGroupBox (QGroupBox *groupBox, bool expanded=true)
 

Private Member Functions

 GroupBoxCollapser (QGroupBox *groupBox)
 
void toggle (bool checked)
 

Private Attributes

QWidget * m_contentArea
 widget to where the original group box content has been moved More...
 
QHBoxLayout * m_titleLayout
 layout in the title widget More...
 
QWidget * m_titleWidget
 widget used to present the new groupbox title More...
 
QToolButton * m_toggleButton
 button to toggle between collapsed/expanded More...
 

Constructor & Destructor Documentation

◆ GroupBoxCollapser()

GroupBoxCollapser::GroupBoxCollapser ( QGroupBox *  groupBox)
private

Definition at line 78 of file GroupBoxCollapser.cpp.

79  : QObject(groupBox)
80 {
81  auto* mainLayout = new QVBoxLayout;
82  mainLayout->setSpacing(0);
83  mainLayout->setContentsMargins(0, 0, 0, 0);
84 
85  m_contentArea = new QWidget(groupBox);
86  m_contentArea->setObjectName("ContentArea");
87  m_contentArea->setLayout(groupBox->layout());
88 
89  mainLayout->addWidget(m_contentArea);
90  groupBox->setLayout(mainLayout);
91 
92  m_toggleButton = new QToolButton(groupBox);
93  m_toggleButton->setObjectName("GroupBoxToggler");
95  m_toggleButton->setStyleSheet(
96  "QToolButton { border: none; text-align: left; font: bold; padding: 5px}");
97  m_toggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
98  m_toggleButton->setCheckable(true);
99  m_toggleButton->setText(groupBox->title());
100  m_toggleButton->setArrowType(Qt::ArrowType::DownArrow);
101  m_toggleButton->setChecked(true);
102  m_toggleButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
103 
104  m_titleWidget = new QWidget(groupBox);
105  m_titleWidget->setObjectName("GroupBoxTogglerTitleWidget");
106  m_titleWidget->setAttribute(Qt::WA_StyledBackground, true);
107 
108  m_titleLayout = new QHBoxLayout;
109  m_titleLayout->setContentsMargins(0, 0, 3, 0);
110  m_titleLayout->setSpacing(3);
111  m_titleLayout->setAlignment(Qt::AlignVCenter);
112  m_titleWidget->setLayout(m_titleLayout);
113  m_titleLayout->addWidget(m_toggleButton);
114 
115  groupBox->layout()->setMenuBar(m_titleWidget);
116  groupBox->setTitle("");
117  groupBox->setProperty("collapsible", true); // helps to distinguish GroupBoxes in stylesheets
118 
119  connect(m_toggleButton, &QAbstractButton::clicked, this, &GroupBoxCollapser::toggle);
120 }
ApplicationSettings * appSettings
global pointer to the instance
ApplicationSettings::Style currentStyle()
QWidget * m_contentArea
widget to where the original group box content has been moved
QHBoxLayout * m_titleLayout
layout in the title widget
void toggle(bool checked)
QWidget * m_titleWidget
widget used to present the new groupbox title
QToolButton * m_toggleButton
button to toggle between collapsed/expanded

References appSettings, ApplicationSettings::currentStyle(), m_contentArea, m_titleLayout, m_titleWidget, m_toggleButton, ApplicationSettings::native, and toggle().

Referenced by installIntoGroupBox().

Here is the call graph for this function:

Member Function Documentation

◆ addAction()

void GroupBoxCollapser::addAction ( QAction *  action)

Add a tool button to the title bar, connected to the given action.

Definition at line 49 of file GroupBoxCollapser.cpp.

50 {
51  auto* btn = new QToolButton(m_titleWidget);
52  btn->setToolButtonStyle(Qt::ToolButtonIconOnly);
53  btn->setDefaultAction(action);
54  if (action->menu() != nullptr)
55  btn->setPopupMode(QToolButton::InstantPopup);
56 
57  m_titleLayout->addWidget(btn);
58 
59  connect(action, &QAction::changed, [=]() { btn->setVisible(action->isVisible()); });
60 }

References m_titleLayout, and m_titleWidget.

Referenced by LayerForm::LayerForm(), ParticleCoreShellForm::ParticleCoreShellForm(), and ParticleLayoutForm::ParticleLayoutForm().

◆ addWidget()

void GroupBoxCollapser::addWidget ( QWidget *  widget)

Add a widget to the title bar.

Definition at line 62 of file GroupBoxCollapser.cpp.

63 {
64  m_titleLayout->addWidget(widget);
65 }

References m_titleLayout.

Referenced by LayerForm::LayerForm().

◆ contentArea()

QWidget * GroupBoxCollapser::contentArea ( ) const

The content area, to which the found group box content has been moved when the add-on has been installed.

Definition at line 67 of file GroupBoxCollapser.cpp.

68 {
69  return m_contentArea;
70 }

References m_contentArea.

◆ findInstalledCollapser()

GroupBoxCollapser * GroupBoxCollapser::findInstalledCollapser ( QGroupBox *  groupBox)
static

Definition at line 37 of file GroupBoxCollapser.cpp.

38 {
39  if (groupBox == nullptr)
40  return nullptr;
41  return groupBox->findChild<GroupBoxCollapser*>();
42 }
Add-on to group boxes to make them collapsible.

Referenced by FormLayouter::FormLayouter().

◆ installIntoGroupBox()

GroupBoxCollapser * GroupBoxCollapser::installIntoGroupBox ( QGroupBox *  groupBox,
bool  expanded = true 
)
static

Definition at line 23 of file GroupBoxCollapser.cpp.

24 {
25  auto* p = new GroupBoxCollapser(groupBox);
26 
27  if (!expanded) {
28  QSignalBlocker b(p->m_toggleButton);
29  p->m_toggleButton->setChecked(false);
30  p->m_toggleButton->setArrowType(Qt::ArrowType::RightArrow);
31  p->m_contentArea->hide();
32  }
33 
34  return p;
35 }
GroupBoxCollapser(QGroupBox *groupBox)

References GroupBoxCollapser().

Referenced by AxisPropertyEditor::AxisPropertyEditor(), DepthProbeInstrumentEditor::DepthProbeInstrumentEditor(), DetectorEditor::DetectorEditor(), DistributionEditor::DistributionEditor(), EnvironmentEditor::EnvironmentEditor(), FootprintCorrectionEditor::FootprintCorrectionEditor(), GISASBeamEditor::GISASBeamEditor(), InclinationAnglesEditor::InclinationAnglesEditor(), InterferenceForm::InterferenceForm(), LayerForm::LayerForm(), MaskEditorPropertyPanel::MaskEditorPropertyPanel(), MesoCrystalForm::MesoCrystalForm(), MultiLayerForm::MultiLayerForm(), OffspecBeamEditor::OffspecBeamEditor(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), ParticleForm::ParticleForm(), ParticleLayoutForm::ParticleLayoutForm(), PolarizationAnalysisEditor::PolarizationAnalysisEditor(), ProjectSettingsView::ProjectSettingsView(), RectangularDetectorEditor::RectangularDetectorEditor(), ResolutionFunctionEditor::ResolutionFunctionEditor(), SimulationView::SimulationView(), SpecularBeamEditor::SpecularBeamEditor(), WelcomeView::WelcomeView(), InstrumentLibraryEditor::createWidgetsForCurrentInstrument(), and InstrumentView::createWidgetsForCurrentInstrument().

Here is the call graph for this function:

◆ setExpanded()

void GroupBoxCollapser::setExpanded ( bool  expanded = true)

Expand/collapse the content area.

Definition at line 72 of file GroupBoxCollapser.cpp.

73 {
74  if (m_toggleButton->isChecked() != expanded)
75  m_toggleButton->click();
76 }

References m_toggleButton.

Referenced by LayerForm::expand().

◆ setTitle()

void GroupBoxCollapser::setTitle ( const QString &  title)

Set the title of the group box. Do not use the method groupBox->setTitle() any more once the add-on is installed.

Definition at line 44 of file GroupBoxCollapser.cpp.

45 {
46  m_toggleButton->setText(title);
47 }

References m_toggleButton.

Referenced by ParticleCoreShellForm::createCoreWidgets(), ParticleCoreShellForm::createShellWidgets(), InterferenceForm::updateTitle(), LayerForm::updateTitle(), and ParticleLayoutForm::updateTitle().

◆ toggle()

void GroupBoxCollapser::toggle ( bool  checked)
private

Definition at line 122 of file GroupBoxCollapser.cpp.

123 {
124  m_toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
125 
126  if (m_toggleButton->isChecked())
127  m_contentArea->show();
128  else
129  m_contentArea->hide();
130 }

References m_contentArea, and m_toggleButton.

Referenced by GroupBoxCollapser().

Member Data Documentation

◆ m_contentArea

QWidget* GroupBoxCollapser::m_contentArea
private

widget to where the original group box content has been moved

Definition at line 64 of file GroupBoxCollapser.h.

Referenced by GroupBoxCollapser(), contentArea(), and toggle().

◆ m_titleLayout

QHBoxLayout* GroupBoxCollapser::m_titleLayout
private

layout in the title widget

Definition at line 62 of file GroupBoxCollapser.h.

Referenced by GroupBoxCollapser(), addAction(), and addWidget().

◆ m_titleWidget

QWidget* GroupBoxCollapser::m_titleWidget
private

widget used to present the new groupbox title

Definition at line 61 of file GroupBoxCollapser.h.

Referenced by GroupBoxCollapser(), and addAction().

◆ m_toggleButton

QToolButton* GroupBoxCollapser::m_toggleButton
private

button to toggle between collapsed/expanded

Definition at line 63 of file GroupBoxCollapser.h.

Referenced by GroupBoxCollapser(), setExpanded(), setTitle(), and toggle().


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