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

Shows a single line of text on a white background. More...

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

Public Member Functions

 StatusLabel (QWidget *parent=nullptr)
 
void setAlignment (Qt::Alignment)
 
void setFont (const QFont &font)
 
void setPointSize (int pointSize)
 
void setText (const QString &text)
 

Protected Member Functions

void paintEvent (QPaintEvent *event)
 

Private Attributes

Qt::Alignment m_alignment
 
QFont m_font
 
QString m_text
 

Detailed Description

Shows a single line of text on a white background.

Opposite to QLabel, doesn't trigger layout resize, being happy with place it has. If text string is too long for current size, it will be clipped.

Definition at line 29 of file statuslabel.h.

Constructor & Destructor Documentation

◆ StatusLabel()

StatusLabel::StatusLabel ( QWidget *  parent = nullptr)
explicit

Definition at line 24 of file statuslabel.cpp.

25  : QFrame(parent), m_font("Monospace", Style::DefaultInfoBarTextSize(), QFont::Normal, false)
26 {
27  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
28  setFixedHeight(Style::DefaultInfoBarHeight());
29 }
MVVM_VIEWMODEL_EXPORT int DefaultInfoBarHeight()
Returns default height of info bar.
Definition: styleutils.cpp:23
MVVM_VIEWMODEL_EXPORT int DefaultInfoBarTextSize()
Returns default size of text on info bar.
Definition: styleutils.cpp:29

References ModelView::Style::DefaultInfoBarHeight().

Here is the call graph for this function:

Member Function Documentation

◆ paintEvent()

void StatusLabel::paintEvent ( QPaintEvent *  event)
protected

Definition at line 55 of file statuslabel.cpp.

56 {
57  QFrame::paintEvent(event);
58 
59  QPainter painter(this);
60  painter.setBrush(QColor(Qt::black));
61  painter.setPen(QColor(Qt::black));
62  painter.setFont(m_font);
63 
64  QRect bbox(0, 0, geometry().width(), geometry().height());
65  const int gap(Utils::WidthOfLetterM() / 2); // make it smaller
66  auto textRect = bbox.adjusted(gap, 0, gap, 0);
67 
68  painter.fillRect(bbox, QColor(Qt::white));
69  painter.drawText(textRect, static_cast<int>(m_alignment), m_text);
70 }
Qt::Alignment m_alignment
Definition: statuslabel.h:45
MVVM_VIEW_EXPORT int WidthOfLetterM()
Returns width of the letter 'M' deduced from current font metrics.

References m_alignment, m_font, m_text, and ModelView::Utils::WidthOfLetterM().

Here is the call graph for this function:

◆ setAlignment()

void StatusLabel::setAlignment ( Qt::Alignment  alignment)

Definition at line 49 of file statuslabel.cpp.

50 {
51  m_alignment = alignment;
52  update();
53 }

References m_alignment.

◆ setFont()

void StatusLabel::setFont ( const QFont &  font)

Definition at line 37 of file statuslabel.cpp.

38 {
39  m_font = font;
40  update();
41 }

References m_font.

◆ setPointSize()

void StatusLabel::setPointSize ( int  pointSize)

Definition at line 43 of file statuslabel.cpp.

44 {
45  m_font.setPointSize(pointSize);
46  update();
47 }

References m_font.

◆ setText()

void StatusLabel::setText ( const QString &  text)

Definition at line 31 of file statuslabel.cpp.

32 {
33  m_text = text;
34  update();
35 }

References m_text.

Referenced by ModelView::GraphCanvas::GraphCanvasImpl::GraphCanvasImpl().

Member Data Documentation

◆ m_alignment

Qt::Alignment ModelView::StatusLabel::m_alignment
private

Definition at line 45 of file statuslabel.h.

Referenced by paintEvent(), and setAlignment().

◆ m_font

QFont ModelView::StatusLabel::m_font
private

Definition at line 46 of file statuslabel.h.

Referenced by paintEvent(), setFont(), and setPointSize().

◆ m_text

QString ModelView::StatusLabel::m_text
private

Definition at line 44 of file statuslabel.h.

Referenced by paintEvent(), and setText().


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