Fix
[ryzomcore.git] / studio / src / splash_screen.cpp
blob6d8360b9f0283f40dc8d1b8d166d72a88664cf0d
1 // Ryzom Core - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "splash_screen.h"
22 #include <QPainter>
23 #include <QStyleOptionProgressBarV2>
24 #include <QCoreApplication>
25 #include <QPixmap>
27 SplashScreen::SplashScreen() :
28 QSplashScreen()
30 progress = 0;
31 textX = 5;
32 textY = 20;
33 pbLeft = 2;
34 pbTop = 0;
35 pbWidth = 100;
36 pbHeight = 20;
39 SplashScreen::~SplashScreen()
43 void SplashScreen::setPixmap( const QPixmap &pixmap )
45 QSplashScreen::setPixmap( pixmap );
47 if( this->pixmap().width() > 0 )
48 pbWidth = this->pixmap().width() - 4;
50 if( this->pixmap().height() > 0 )
51 pbTop = this->pixmap().height() - pbHeight - 2;
53 textY = pbTop - pbHeight / 2;
56 void SplashScreen::setText( const QString &text )
58 this->text = text;
59 repaint();
60 QCoreApplication::instance()->processEvents();
63 void SplashScreen::clearText()
65 setText( "" );
68 void SplashScreen::setProgress( int percent )
70 progress = percent;
71 repaint();
72 QCoreApplication::instance()->processEvents();
75 void SplashScreen::advanceProgress( int percent )
77 progress += percent;
78 repaint();
79 QCoreApplication::instance()->processEvents();
82 void SplashScreen::drawContents( QPainter *painter )
84 QSplashScreen::drawContents( painter );
86 if( progressBarEnabled )
88 QStyleOptionProgressBarV2 pbStyle;
89 pbStyle.initFrom( this );
90 pbStyle.state = QStyle::State_Enabled;
91 pbStyle.textVisible = false;
92 pbStyle.minimum = 0;
93 pbStyle.maximum = 100;
94 pbStyle.progress = progress;
95 pbStyle.invertedAppearance = false;
96 pbStyle.rect = QRect( pbLeft, pbTop, pbWidth, pbHeight );
98 style()->drawControl( QStyle::CE_ProgressBar, &pbStyle, painter, this );
101 if( !text.isEmpty() )
103 QPen oldPen = painter->pen();
104 QPen pen;
105 pen.setColor( Qt::white );
106 painter->setPen( pen );
107 painter->drawText( textX, textY, text );
108 painter->setPen( oldPen );