BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InfoPanel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/CommonWidgets/InfoPanel.cpp
6 //! @brief Declares class InfoPanel
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include <QBoxLayout>
18 #include <QResizeEvent>
19 #include <QStackedWidget>
20 
21 namespace {
22 const int minimum_widget_height = 25; // height of toolbar
23 const int minimum_height_before_collapse = 50;
24 const int default_height = 200;
25 } // namespace
26 
27 InfoPanel::InfoPanel(QWidget* parent)
28  : QFrame(parent)
29  , m_toolBar(new InfoPanelToolBar)
30  , m_stackedWidget(new QStackedWidget)
31  , m_cached_height(default_height)
32 {
33  auto mainLayout = new QVBoxLayout;
34  mainLayout->addWidget(m_toolBar);
35  mainLayout->addWidget(m_stackedWidget);
36 
37  mainLayout->setContentsMargins(0, 0, 0, 0);
38  mainLayout->setMargin(0);
39  mainLayout->setSpacing(0);
40 
41  setLayout(mainLayout);
42 
45 }
46 
47 QSize InfoPanel::sizeHint() const
48 {
49  QSize result = m_toolBar->sizeHint();
50 
51  if (QWidget* widget = m_stackedWidget->currentWidget()) {
52  if (widget->isVisible())
53  result.setHeight(widget->height() + m_toolBar->height());
54  } else {
55  result.setHeight(m_toolBar->height());
56  }
57 
58  return result;
59 }
60 
62 {
63  return QSize(minimum_widget_height, minimum_widget_height);
64 }
65 
67 {
69 }
70 
71 void InfoPanel::setContentVisible(bool editor_status, bool dock_notify)
72 {
73  m_toolBar->setExpandStatus(editor_status);
74  if (editor_status) {
75  if (m_cached_height)
76  if (dock_notify)
78 
79  if (m_stackedWidget->currentWidget())
80  m_stackedWidget->currentWidget()->show();
81 
82  } else {
83  m_cached_height = (height() < minimum_height_before_collapse ? default_height : height());
84  if (m_stackedWidget->currentWidget())
85  m_stackedWidget->currentWidget()->hide();
86 
87  if (dock_notify)
88  emit widgetHeightRequest(minimum_widget_height);
89  }
90 }
91 
93 {
94  if (m_stackedWidget->currentWidget())
95  return m_stackedWidget->currentWidget()->isVisible();
96 
97  return false;
98 }
99 
100 void InfoPanel::resizeEvent(QResizeEvent* event)
101 {
102  // widget is schrinking in height
103  if (event->oldSize().height() > event->size().height()) {
104  if (event->size().height() <= minimum_height_before_collapse && isContentVisible())
105  setContentVisible(false);
106  }
107 
108  // widget is growing in height
109  if (event->oldSize().height() < event->size().height()) {
110  if (event->size().height() > minimum_height_before_collapse && !isContentVisible())
111  setContentVisible(true);
112  }
113 
114  QWidget::resizeEvent(event);
115 }
Defines class InfoPanelToolBar.
Defines class InfoPanel.
Toolbar for InfoPanel with collapse/expand buttons.
void expandButtonClicked()
void setExpandStatus(bool status)
bool isContentVisible()
Definition: InfoPanel.cpp:92
QStackedWidget * m_stackedWidget
Definition: InfoPanel.h:49
void setContentVisible(bool editor_status, bool dock_notify=false)
Definition: InfoPanel.cpp:71
InfoPanel(QWidget *parent)
Definition: InfoPanel.cpp:27
void widgetHeightRequest(int)
QSize minimumSizeHint() const
Definition: InfoPanel.cpp:61
void onExpandButtonClicked()
Definition: InfoPanel.cpp:66
InfoPanelToolBar * m_toolBar
Definition: InfoPanel.h:48
int m_cached_height
Definition: InfoPanel.h:50
QSize sizeHint() const
Definition: InfoPanel.cpp:47
void resizeEvent(QResizeEvent *event)
Definition: InfoPanel.cpp:100