1 /*
2  * Copyright (C) 2019 Ruslan Kabatsayev
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17  */
18 
19 #include "StelSplashScreen.hpp"
20 #include "StelFileMgr.hpp"
21 #include "StelUtils.hpp"
22 
23 #include <QPainter>
24 
25 SplashScreen::SplashScreenWidget* SplashScreen::instance;
26 
makePixmap()27 static QPixmap makePixmap()
28 {
29 	QPixmap pixmap(StelFileMgr::findFile("data/splash.png"));
30 	QPainter p(&pixmap);
31 	p.setRenderHint(QPainter::Antialiasing);
32 	p.setRenderHint(QPainter::HighQualityAntialiasing);
33 	p.setPen(Qt::white);
34 	QFontMetrics metrics(p.font());
35 	p.drawText(QPointF(metrics.averageCharWidth(), 1.3*metrics.height()), StelUtils::getApplicationVersion());
36 	return pixmap;
37 }
38 
present()39 void SplashScreen::present()
40 {
41 	QFont splashFont;
42 	splashFont.setPixelSize(11);
43 	Q_ASSERT(!instance);
44 	instance=new SplashScreenWidget(makePixmap());
45 	instance->setFont(splashFont);
46 	instance->show();
47 	instance->ensureFirstPaint();
48 }
49 
showMessage(QString const & message)50 void SplashScreen::showMessage(QString const& message)
51 {
52 	Q_ASSERT(instance);
53 	instance->showMessage(message, Qt::AlignLeft|Qt::AlignBottom, Qt::white);
54 }
55 
finish(QWidget * mainWindow)56 void SplashScreen::finish(QWidget* mainWindow)
57 {
58 	Q_ASSERT(instance);
59 	instance->finish(mainWindow);
60 	delete instance;
61 	instance=nullptr;
62 }
63 
clearMessage()64 void SplashScreen::clearMessage()
65 {
66 	Q_ASSERT(instance);
67 	instance->clearMessage();
68 }
69