BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FancyLabel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/utils/FancyLabel.cpp
6 //! @brief Implements class FancyLabel
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 <QTimer>
17 
18 FancyLabel::FancyLabel(const QString& text, QWidget* parent) : QLabel(text, parent)
19 {
21 }
22 
23 FancyLabel::FancyLabel(QWidget* parent) : QLabel(parent)
24 {
26 }
27 
28 void FancyLabel::setTextAnimated(const QString& animated_text)
29 {
30  if (m_timer->isActive())
31  m_timer->stop();
32 
33  if (animated_text == text())
34  return;
35 
36  if (animated_text.isEmpty()) {
37  setText(animated_text);
38  return;
39  }
40 
41  m_text = animated_text;
42  m_current_index = 0;
43 
44  m_timer->setInterval(m_total_effect_duration / m_text.size());
45 
46  m_timer->start();
47 }
48 
50 {
51  if (m_current_index <= m_text.size()) {
52  setText(m_text.left(m_current_index));
54  return;
55  }
56  m_timer->stop();
57 }
58 
60 {
61  m_total_effect_duration = 200; // in msec
62  m_current_index = 0;
63  m_timer = new QTimer(this);
64  connect(m_timer, &QTimer::timeout, this, &FancyLabel::onTimeout);
65 }
Defines class FancyLabel.
int m_current_index
Definition: FancyLabel.h:41
void init_fancy_label()
Definition: FancyLabel.cpp:59
void onTimeout()
Definition: FancyLabel.cpp:49
QTimer * m_timer
Definition: FancyLabel.h:39
FancyLabel(const QString &text, QWidget *parent=nullptr)
Definition: FancyLabel.cpp:18
void setTextAnimated(const QString &animated_text)
Definition: FancyLabel.cpp:28
int m_total_effect_duration
Definition: FancyLabel.h:40
QString m_text
Definition: FancyLabel.h:38