BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
OverlayLabelWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/OverlayLabelWidget.cpp
6 //! @brief Implements class OverlayLabelWidget
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 
18 #include <QColor>
19 #include <QFont>
20 #include <QPainter>
21 
23  : QWidget(parent)
24  , m_bounding_rect(QRect(0, 0, 10, 10))
25 {
26  setAttribute(Qt::WA_TransparentForMouseEvents);
27 }
28 
29 void OverlayLabelWidget::setRectangle(const QRect& rect)
30 {
31  m_bounding_rect = rect;
32 }
33 
35 {
36  setGeometry(x, y, m_bounding_rect.width(), m_bounding_rect.height());
37 }
38 
39 void OverlayLabelWidget::paintEvent(QPaintEvent* event)
40 {
41  Q_UNUSED(event);
42  QPainter painter(this);
43  painter.setBrush(QColor(Qt::lightGray));
44  QFont serifFont("Monospace", DesignerHelper::getSectionFontSize(), QFont::Normal, true);
45  painter.setFont(serifFont);
46  // painter.drawRect(m_bounding_rect);
47  auto margin = GUI::Util::Style::SizeOfLetterM().width();
48  painter.drawText(m_bounding_rect.marginsRemoved(QMargins(margin, margin, margin, margin)),
49  Qt::AlignCenter, m_text);
50 }
Defines class DesignerHelper.
Defines class OverlayLabelWidget.
Defines GUI::StyleUtils namespace.
static int getSectionFontSize()
Returns system dependent font size.
OverlayLabelWidget(QWidget *parent=nullptr)
void setRectangle(const QRect &rect)
void paintEvent(QPaintEvent *event) override
void setPosition(int x, int y)
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:113