Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OSplashScreen.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
22 // Added by qt3to4:
23 #include <qapplication.h>
24 #include <qpainter.h>
25 #include <QMouseEvent>
26 #include <QPixmap>
27 #include <QMessageBox>
28 #include <QLabel>
29 #include <QScreen>
30 
31 #include "OSplashScreen.h"
32 
33 // WStyle_Splash est dispo que depuis Qt 3.1, il est equivalent a :
34 // WStyle_NoBorder|WStyle_StaysOnTop|WX11BypassWM
35 OSplashScreen::OSplashScreen(const QPixmap& pixmap, const QString& msgText)
36  : QWidget(0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint),
37  _pix(pixmap)
38 {
39  // Defini l'image
40  QPalette _palette = palette();
41  _palette.setBrush(backgroundRole(), QBrush(_pix));
42  setPalette(_palette);
43  resize(_pix.size());
44 
45  // Defini le message texte
46  _msgLabel = new QLabel(msgText,
47  this); // "<font color=\"#09367A\"><i><b>TYMPAN "+version+"</i></b></font>", this);
48  _msgLabel->setFont(QFont("Times", 30)); // la police du label
49  _msgLabel->setGeometry(80, 480, 300, 60);
50 
51  // Recupere la taille de l'ecran
52  QRect scr = QGuiApplication::screens().at(0)->geometry();
53  // Centre le splash screen
54  move(scr.center() - rect().center());
55 
56  show();
57  repaint();
58 }
59 
61 
62 void OSplashScreen::setStatus(const QString& message, int alignment, const QColor& color)
63 {
64  QPixmap textPix = _pix;
65  QPainter painter(&textPix);
66  painter.setPen(color);
67  QFont tmpFont = painter.font();
68  // RNU : pb de version QT : en version 4.1, il faut donner un petit chiffre, mais pas en version 4.5
69 #if TY_PLATFORM == TY_PLATFORM_LINUX
70  tmpFont.setPointSize(3);
71 #else
72  tmpFont.setPointSize(10);
73 #endif
74  painter.setFont(tmpFont);
75 
76  QRect r = rect();
77  r.setRect(r.x() + 10, r.y() + 10, r.width() - 20, r.height() - 20);
78 
79  painter.drawText(r, alignment, message);
80 
81  QPalette _palette = palette();
82 
83  _palette.setBrush(backgroundRole(), QBrush(textPix));
84  setPalette(_palette);
85 
86  repaint();
87 }
88 
89 #if defined(Q_WS_X11)
90 // void qt_wait_for_window_manager(QWidget * widget);
91 #endif
92 
93 void OSplashScreen::finish(QWidget* mainWin)
94 {
95 #if defined(Q_WS_X11)
96  // qt_wait_for_window_manager(mainWin);
97 #endif
98 
99  close();
100 }
101 
103 {
104  QWidget::repaint();
105 }
106 
107 void OSplashScreen::mousePressEvent(QMouseEvent* pEvent)
108 {
109  hide();
110 }
Splash screen widget (fichier header)
void setStatus(const QString &message, int alignment=Qt::AlignLeft, const QColor &color=Qt::black)
Affiche un nouveau message indiquant le status de l'application.
QLabel * _msgLabel
Definition: OSplashScreen.h:72
void repaint()
Mise a jour.
void mousePressEvent(QMouseEvent *pEvent)
QPixmap _pix
L'image du splash screen.
Definition: OSplashScreen.h:69
virtual ~OSplashScreen()
Destructeur.
OSplashScreen(const QPixmap &pixmap, const QString &msgText)
Constructeur par defaut.
void finish(QWidget *pMainWin)
Indique que le chargement de l'application est termine.