BornAgain  1.19.0
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/coregui/Views/InfoWidgets/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/Utils/Assert.h"
18 #include <QAbstractScrollArea>
19 #include <QEvent>
20 #include <QRect>
21 
23  : QObject(parent), m_label(0), m_area(0)
24 {
25 }
26 
27 void OverlayLabelController::setText(const QString& text)
28 {
29  m_text = text;
30 }
31 
32 void OverlayLabelController::setArea(QAbstractScrollArea* area)
33 {
34  m_area = area;
35  m_area->installEventFilter(this);
36 }
37 
38 //! Shows/removes a label from the controlled widget
39 
41 {
42  if (shown) {
43  ASSERT(m_area);
44  if (!m_label) {
48  m_label->show();
49  }
50 
51  } else {
52  delete m_label;
53  m_label = 0;
54  }
55 }
56 
57 bool OverlayLabelController::eventFilter(QObject* obj, QEvent* event)
58 {
59  if (event->type() == QEvent::Resize)
61 
62  return QObject::eventFilter(obj, event);
63 }
64 
66 {
67  if (!m_label || !m_area)
68  return;
69  m_label->setRectangle(QRect(0, 0, m_area->width(), m_area->height()));
70  m_label->setPosition(0, 0);
71 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
Defines class OverlayLabelController.
Defines class OverlayLabelWidget.
QAbstractScrollArea * m_area
void setArea(QAbstractScrollArea *area)
bool eventFilter(QObject *obj, QEvent *event)
void setText(const QString &text)
OverlayLabelController(QObject *parent=0)
void setShown(bool shown)
Shows/removes a label from the controlled widget.
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)