BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
OverlayLabelController.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/OverlayLabelController.cpp
6 //! @brief Implements class OverlayLabelController
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 
16 #include "Base/Util/Assert.h"
18 #include <QAbstractScrollArea>
19 #include <QEvent>
20 #include <QRect>
21 
23  : QObject(parent)
24  , m_label(nullptr)
25  , m_area(nullptr)
26 {
27 }
28 
29 void OverlayLabelController::setText(const QString& text)
30 {
31  m_text = text;
32 }
33 
34 void OverlayLabelController::setArea(QAbstractScrollArea* area)
35 {
36  m_area = area;
37  m_area->installEventFilter(this);
38 }
39 
40 //! Shows/removes a label from the controlled widget
41 
43 {
44  if (shown) {
45  ASSERT(m_area);
46  if (!m_label) {
50  m_label->show();
51  }
52  } else {
53  delete m_label;
54  m_label = nullptr;
55  }
56 }
57 
58 bool OverlayLabelController::eventFilter(QObject* obj, QEvent* event)
59 {
60  if (event->type() == QEvent::Resize)
62 
63  return QObject::eventFilter(obj, event);
64 }
65 
67 {
68  if (!m_label || !m_area)
69  return;
70  m_label->setRectangle(QRect(0, 0, m_area->width(), m_area->height()));
71  m_label->setPosition(0, 0);
72 }
Defines class OverlayLabelController.
Defines class OverlayLabelWidget.
QAbstractScrollArea * m_area
void setArea(QAbstractScrollArea *area)
bool eventFilter(QObject *obj, QEvent *event) override
void setText(const QString &text)
void setShown(bool shown)
Shows/removes a label from the controlled widget.
OverlayLabelController(QObject *parent=nullptr)
OverlayLabelWidget * m_label
The OverlayLabelWidget is a semi-transparent overlay label to place on top of other widgets outside o...
void setRectangle(const QRect &rect)
void setText(const QString &text)
void setPosition(int x, int y)