BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
StatusLabel.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/StatusLabel.cpp
6 //! @brief Implements class StatusLabel
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 <QColor>
18 #include <QFont>
19 #include <QPainter>
20 
21 namespace {
22 int default_text_size()
23 {
25 }
26 int default_label_height()
27 {
28  return StyleUtils::SizeOfLetterM().height() * 1.75;
29 }
30 } // namespace
31 
32 StatusLabel::StatusLabel(QWidget* parent)
33  : QFrame(parent), m_font("Monospace", default_text_size(), QFont::Normal, false)
34 {
35  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
36  setFixedHeight(default_label_height());
37 }
38 
39 void StatusLabel::setText(const QString& text)
40 {
41  m_text = text;
42  update();
43 }
44 
45 void StatusLabel::setFont(const QFont& font)
46 {
47  m_font = font;
48  update();
49 }
50 
51 void StatusLabel::setPointSize(int pointSize)
52 {
53  m_font.setPointSize(pointSize);
54  update();
55 }
56 
57 void StatusLabel::setAlignment(Qt::Alignment alignment)
58 {
59  m_alignment = alignment;
60  update();
61 }
62 
63 void StatusLabel::paintEvent(QPaintEvent* event)
64 {
65  QWidget::paintEvent(event);
66 
67  QPainter painter(this);
68  painter.setBrush(QColor(Qt::black));
69  painter.setPen(QColor(Qt::black));
70  painter.setFont(m_font);
71 
72  QRect textRect(0, 0, geometry().width(), geometry().height());
73  painter.fillRect(textRect, QColor(Qt::white));
74  painter.drawText(textRect, m_alignment, m_text);
75 }
Defines class StatusLabel.
DefinesStyleUtils namespace.
void setText(const QString &text)
Definition: StatusLabel.cpp:39
void setPointSize(int pointSize)
Definition: StatusLabel.cpp:51
void setFont(const QFont &font)
Definition: StatusLabel.cpp:45
void setAlignment(Qt::Alignment)
Definition: StatusLabel.cpp:57
QString m_text
Definition: StatusLabel.h:43
void paintEvent(QPaintEvent *event)
Definition: StatusLabel.cpp:63
QFont m_font
Definition: StatusLabel.h:45
StatusLabel(QWidget *parent=0)
Definition: StatusLabel.cpp:32
Qt::Alignment m_alignment
Definition: StatusLabel.h:44
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110
int SystemPointSize()
Returns size in points of default system font.
Definition: StyleUtils.cpp:116