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

Horizontal collapsible bar, part of CollapsibleListWidget. More...

Inheritance diagram for ModelView::CollapsibleBar:
[legend]
Collaboration diagram for ModelView::CollapsibleBar:
[legend]

Public Member Functions

 CollapsibleBar (QWidget *parent=nullptr)
 
void setWidget (QWidget *widget, const QString &title)
 

Protected Member Functions

void mousePressEvent (QMouseEvent *event) override
 

Private Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 Listens for widget signals and update collapse/expand icon on visibility change. More...
 
void updatePixmap ()
 Set pixmap depending from the visibility of the widget. More...
 

Private Attributes

QWidget * m_controlledWidget {nullptr}
 
QLabel * m_pixmapLabel {nullptr}
 
QLabel * m_titleLabel {nullptr}
 

Detailed Description

Horizontal collapsible bar, part of CollapsibleListWidget.

Intended for placement into the QSplitter, makes client widget visible/invisible on clicks.

Definition at line 29 of file collapsiblebar.h.

Constructor & Destructor Documentation

◆ CollapsibleBar()

CollapsibleBar::CollapsibleBar ( QWidget *  parent = nullptr)

Definition at line 25 of file collapsiblebar.cpp.

26  : QFrame(parent), m_pixmapLabel(new QLabel), m_titleLabel(new QLabel)
27 {
28  m_pixmapLabel->setPixmap(QPixmap(":/icons/chevron-down.svg"));
29 
30  auto layout = new QHBoxLayout(this);
31  layout->setContentsMargins(0, 4, 0, 0);
32 
33  layout->addWidget(m_pixmapLabel, Qt::AlignLeft);
34  layout->addWidget(m_titleLabel, Qt::AlignCenter);
35 
36  setFixedHeight(ModelView::Utils::HeightOfLetterM() * 2);
37  setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
38 }
MVVM_VIEW_EXPORT int HeightOfLetterM()
Returns height of the letter 'M' deduced from current font metrics.

References ModelView::Utils::HeightOfLetterM(), m_pixmapLabel, and m_titleLabel.

Here is the call graph for this function:

Member Function Documentation

◆ eventFilter()

bool CollapsibleBar::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprivate

Listens for widget signals and update collapse/expand icon on visibility change.

Definition at line 57 of file collapsiblebar.cpp.

58 {
59  bool is_event_of_interest = (event->type() == QEvent::Show || event->type() == QEvent::Hide);
60  if (obj == m_controlledWidget && is_event_of_interest)
61  updatePixmap();
62  return QObject::eventFilter(obj, event);
63 }
void updatePixmap()
Set pixmap depending from the visibility of the widget.

References m_controlledWidget, and updatePixmap().

Here is the call graph for this function:

◆ mousePressEvent()

void CollapsibleBar::mousePressEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 48 of file collapsiblebar.cpp.

49 {
50  if (event->button() == Qt::LeftButton)
51  m_controlledWidget->setHidden(m_controlledWidget->isVisible());
52  updatePixmap();
53 }

References m_controlledWidget, and updatePixmap().

Here is the call graph for this function:

◆ setWidget()

void CollapsibleBar::setWidget ( QWidget *  widget,
const QString &  title 
)

Definition at line 40 of file collapsiblebar.cpp.

41 {
42  m_controlledWidget = widget;
43  m_titleLabel->setText(title);
44  widget->installEventFilter(this);
45  updatePixmap();
46 }

References m_controlledWidget, m_titleLabel, and updatePixmap().

Here is the call graph for this function:

◆ updatePixmap()

void CollapsibleBar::updatePixmap ( )
private

Set pixmap depending from the visibility of the widget.

Definition at line 67 of file collapsiblebar.cpp.

68 {
69  if (m_controlledWidget->isVisible()) {
70  m_pixmapLabel->setPixmap(QPixmap(":/icons/chevron-down.svg"));
71  setFrameStyle(QFrame::StyledPanel);
72  } else {
73  m_pixmapLabel->setPixmap(QPixmap(":/icons/chevron-right.svg"));
74  setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
75  }
76 }

References m_controlledWidget, and m_pixmapLabel.

Referenced by eventFilter(), mousePressEvent(), and setWidget().

Member Data Documentation

◆ m_controlledWidget

QWidget* ModelView::CollapsibleBar::m_controlledWidget {nullptr}
private

Definition at line 44 of file collapsiblebar.h.

Referenced by eventFilter(), mousePressEvent(), setWidget(), and updatePixmap().

◆ m_pixmapLabel

QLabel* ModelView::CollapsibleBar::m_pixmapLabel {nullptr}
private

Definition at line 45 of file collapsiblebar.h.

Referenced by CollapsibleBar(), and updatePixmap().

◆ m_titleLabel

QLabel* ModelView::CollapsibleBar::m_titleLabel {nullptr}
private

Definition at line 46 of file collapsiblebar.h.

Referenced by CollapsibleBar(), and setWidget().


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