BornAgain  1.19.79
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/View/PlotUtil/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 
23 int default_text_size()
24 {
26 }
27 int default_label_height()
28 {
29  return GUI::Util::Style::SizeOfLetterM().height() * 1.75;
30 }
31 
32 } // namespace
33 
34 StatusLabel::StatusLabel(QWidget* parent)
35  : QFrame(parent)
36  , m_font("Monospace", default_text_size(), QFont::Normal, false)
37 {
38  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
39  setFixedHeight(default_label_height());
40 }
41 
42 void StatusLabel::setText(const QString& text)
43 {
44  m_text = text;
45  update();
46 }
47 
48 void StatusLabel::setFont(const QFont& font)
49 {
50  m_font = font;
51  update();
52 }
53 
54 void StatusLabel::setPointSize(int pointSize)
55 {
56  m_font.setPointSize(pointSize);
57  update();
58 }
59 
60 void StatusLabel::setAlignment(Qt::Alignment alignment)
61 {
62  m_alignment = alignment;
63  update();
64 }
65 
66 void StatusLabel::paintEvent(QPaintEvent* event)
67 {
68  QWidget::paintEvent(event);
69 
70  QPainter painter(this);
71  painter.setBrush(QColor(Qt::black));
72  painter.setPen(QColor(Qt::black));
73  painter.setFont(m_font);
74 
75  QRect textRect(0, 0, geometry().width(), geometry().height());
76  painter.fillRect(textRect, QColor(Qt::white));
77  painter.drawText(textRect, m_alignment, m_text);
78 }
Defines class StatusLabel.
Defines GUI::StyleUtils namespace.
void setText(const QString &text)
Definition: StatusLabel.cpp:42
void paintEvent(QPaintEvent *event) override
Definition: StatusLabel.cpp:66
void setPointSize(int pointSize)
Definition: StatusLabel.cpp:54
void setFont(const QFont &font)
Definition: StatusLabel.cpp:48
void setAlignment(Qt::Alignment)
Definition: StatusLabel.cpp:60
QString m_text
Definition: StatusLabel.h:43
StatusLabel(QWidget *parent=nullptr)
Definition: StatusLabel.cpp:34
QFont m_font
Definition: StatusLabel.h:45
Qt::Alignment m_alignment
Definition: StatusLabel.h:44
int SystemPointSize()
Returns size in points of default system font.
Definition: StyleUtils.cpp:119
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:113