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