BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SplashScreen.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/mainwindow/SplashScreen.cpp
6 //! @brief Implements class SplashScreen
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 <QCoreApplication>
19 #include <QDebug>
20 #include <QElapsedTimer>
21 #include <QStyle>
22 #include <QTime>
23 
25  : QSplashScreen(QPixmap(":/images/splashscreen.png")), m_percentage_done(0)
26 
27 {
28  QSplashScreen::setCursor(Qt::BusyCursor);
29 
30  QFont font;
31  font.setPointSize(StyleUtils::SystemPointSize() * 0.9);
32  font.setBold(false);
33  QSplashScreen::setFont(font);
34 }
35 
36 void SplashScreen::start(int show_during)
37 {
38  show();
39  QTime dieTime = QTime::currentTime().addMSecs(show_during);
40  QElapsedTimer timer;
41  timer.start();
42  while (QTime::currentTime() < dieTime) {
43  setProgress(timer.elapsed() / (show_during / 100));
44  QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
45  }
46 }
47 
49 {
50  m_percentage_done = value;
51  if (m_percentage_done > 100)
52  m_percentage_done = 100;
53  if (m_percentage_done < 0)
55  update();
56 }
57 
58 void SplashScreen::drawContents(QPainter* painter)
59 {
60  QSplashScreen::drawContents(painter);
61 
62  auto img_rect = frameGeometry();
63  auto char_height = StyleUtils::SizeOfLetterM().height();
64 
65  QRect textRect(img_rect.width() * 0.02, img_rect.height() - char_height * 2.5,
66  img_rect.width() * 0.5, char_height * 3);
67 
68  QString versionText = QString("version ").append(GUIHelpers::getBornAgainVersionString());
69  style()->drawItemText(painter, textRect, 0, this->palette(), true, versionText);
70 
71  QString loadingText("loading . ");
72  for (size_t i = 0; i < size_t(m_percentage_done / 20); ++i) {
73  loadingText.append(". ");
74  }
75 
76  QRect loadingRect(img_rect.width() * 0.8, img_rect.height() - char_height * 2.5,
77  img_rect.width(), char_height * 3);
78  style()->drawItemText(painter, loadingRect, 0, this->palette(), true, loadingText);
79 }
Defines class GUIHelpers functions.
Defines class SplashScreen.
DefinesStyleUtils namespace.
SplashScreen(QWidget *parent=nullptr)
void drawContents(QPainter *painter)
void start(int show_during=1500)
int m_percentage_done
Definition: SplashScreen.h:34
void setProgress(int value)
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110
int SystemPointSize()
Returns size in points of default system font.
Definition: StyleUtils.cpp:116