BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
CautionSign.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/CautionSign.cpp
6 //! @brief Implements class CautionSign
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 <QScrollBar>
21 #include <QTimer>
22 
23 namespace {
24 
25 const int xpos_offset = 40;
26 const int ypos_offset = 40;
27 
28 } // namespace
29 
30 CautionSign::CautionSign(QWidget* parent)
31  : QObject(parent)
32  , m_caution_header("Houston, we have a problem.")
33  , m_cautionWidget(nullptr)
34  , m_area(nullptr)
35  , m_clear_just_had_happened(false)
36 {
37  setArea(parent);
38 }
39 
40 //! Clears caution message;
41 
43 {
44  delete m_cautionWidget;
45  m_cautionWidget = nullptr;
46  m_caution_message.clear();
47 
49  QTimer::singleShot(10, this, [=]() { m_clear_just_had_happened = false; });
50 }
51 
52 void CautionSign::setCautionHeader(const QString& cautionHeader)
53 {
54  m_caution_header = cautionHeader;
55 }
56 
57 //! Shows caution sign on the screen. If clear of previous caution sign had happened just
58 //! few msec ago, make a small delay, to stress its reapearance.
59 
60 void CautionSign::setCautionMessage(const QString& cautionMessage)
61 {
62  ASSERT(m_area);
63 
66  QTimer::singleShot(50, this, [=]() { setCautionMessage(cautionMessage); });
67  } else {
68  m_caution_message = cautionMessage;
69 
70  if (!m_cautionWidget)
72 
75  m_cautionWidget->show();
76  }
77 }
78 
79 void CautionSign::setArea(QWidget* area)
80 {
81  m_area = area;
82  m_area->installEventFilter(this);
83 }
84 
86 {
87  return m_cautionWidget != nullptr;
88 }
89 
90 bool CautionSign::eventFilter(QObject* obj, QEvent* event)
91 {
92  if (event->type() == QEvent::Resize)
94 
95  return QObject::eventFilter(obj, event);
96 }
97 
99 {
100  if (!m_cautionWidget || !m_area)
101  return;
102 
103  QPoint pos = positionForCautionSign();
104  m_cautionWidget->setPosition(pos.x(), pos.y());
105 }
106 
108 {
109  ASSERT(m_area);
110 
111  int x = m_area->width() - xpos_offset;
112  int y = m_area->height() - ypos_offset;
113 
114  if (auto* scrollArea = dynamic_cast<QAbstractScrollArea*>(m_area)) {
115  if (QScrollBar* horizontal = scrollArea->horizontalScrollBar()) {
116  if (horizontal->isVisible())
117  y -= horizontal->height();
118  }
119 
120  if (QScrollBar* vertical = scrollArea->verticalScrollBar()) {
121  if (vertical->isVisible())
122  x -= vertical->width();
123  }
124  }
125 
126  return QPoint(x, y);
127 }
Defines class CautionSignWidget.
Defines class CautionSign.
The CautionSignWidget is an transparent widget with caution sign pixmap intended to be overlayed onto...
void setCautionMessage(const QString &message)
void setPosition(int x, int y)
set geometry of widget around center point
bool eventFilter(QObject *obj, QEvent *event) override
Definition: CautionSign.cpp:90
void updateLabelGeometry()
Definition: CautionSign.cpp:98
QWidget * m_area
Definition: CautionSign.h:49
CautionSign(QWidget *parent)
Definition: CautionSign.cpp:30
bool isShown() const
Definition: CautionSign.cpp:85
void setCautionHeader(const QString &cautionHeader)
Definition: CautionSign.cpp:52
QString m_caution_message
Definition: CautionSign.h:47
CautionSignWidget * m_cautionWidget
Definition: CautionSign.h:48
void setArea(QWidget *area)
Definition: CautionSign.cpp:79
void clear()
Clears caution message;.
Definition: CautionSign.cpp:42
QPoint positionForCautionSign() const
QString m_caution_header
Definition: CautionSign.h:46
bool m_clear_just_had_happened
Definition: CautionSign.h:50
void setCautionMessage(const QString &cautionMessage)
Shows caution sign on the screen. If clear of previous caution sign had happened just few msec ago,...
Definition: CautionSign.cpp:60