BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupBoxCollapser.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Tool/GroupBoxCollapser.h
6 //! @brief Defines class GroupBoxCollapser
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_VIEW_TOOL_GROUPBOXCOLLAPSER_H
16 #define BORNAGAIN_GUI_VIEW_TOOL_GROUPBOXCOLLAPSER_H
17 
18 #include <QObject>
19 
20 class QToolButton;
21 class QGroupBox;
22 class QHBoxLayout;
23 class QAction;
24 
25 //! Add-on to group boxes to make them collapsible.
26 //!
27 //! Also adds the possibility to show toolbuttons or widgets in the group box's title.
28 //! This add-on takes the layout (plus the contained widgets) of a given group box and moves it into
29 //! a newly created content area widget. A title widget will be added, and the original group box
30 //! title will be hidden.
31 //!
32 //! To support style sheets, the custom bool property "collapsible" will be added to the group box
33 //! an set to true.
34 class GroupBoxCollapser : public QObject {
35  Q_OBJECT
36 public:
37  static GroupBoxCollapser* installIntoGroupBox(QGroupBox* groupBox, bool expanded = true);
38  static GroupBoxCollapser* findInstalledCollapser(QGroupBox* groupBox);
39 
40  //! Set the title of the group box. Do not use the method groupBox->setTitle() any more once the
41  //! add-on is installed.
42  void setTitle(const QString& title);
43 
44  //! Add a tool button to the title bar, connected to the given action
45  void addAction(QAction* action);
46 
47  //! Add a widget to the title bar.
48  void addWidget(QWidget* widget);
49 
50  //! The content area, to which the found group box content has been moved when the add-on has
51  //! been installed.
52  QWidget* contentArea() const;
53 
54  //! Expand/collapse the content area
55  void setExpanded(bool expanded = true);
56 
57 private:
58  GroupBoxCollapser(QGroupBox* groupBox);
59  void toggle(bool checked);
60 
61  QWidget* m_titleWidget; //!< widget used to present the new groupbox title
62  QHBoxLayout* m_titleLayout; //!< layout in the title widget
63  QToolButton* m_toggleButton; //!< button to toggle between collapsed/expanded
64  QWidget* m_contentArea; //!< widget to where the original group box content has been moved
65 };
66 
67 
68 #endif // BORNAGAIN_GUI_VIEW_TOOL_GROUPBOXCOLLAPSER_H
Add-on to group boxes to make them collapsible.
QWidget * m_contentArea
widget to where the original group box content has been moved
QHBoxLayout * m_titleLayout
layout in the title widget
void setExpanded(bool expanded=true)
Expand/collapse the content area.
GroupBoxCollapser(QGroupBox *groupBox)
void toggle(bool checked)
QWidget * contentArea() const
The content area, to which the found group box content has been moved when the add-on has been instal...
QWidget * m_titleWidget
widget used to present the new groupbox title
void addAction(QAction *action)
Add a tool button to the title bar, connected to the given action.
void addWidget(QWidget *widget)
Add a widget to the title bar.
QToolButton * m_toggleButton
button to toggle between collapsed/expanded
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
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 i...
static GroupBoxCollapser * findInstalledCollapser(QGroupBox *groupBox)