2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-04-14 11:35:37 +02:00
|
|
|
#include "splashscreen.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2015-01-30 10:08:46 +01:00
|
|
|
#include "networkstyle.h"
|
|
|
|
|
2013-04-14 11:35:37 +02:00
|
|
|
#include "clientversion.h"
|
2014-03-19 00:26:14 +01:00
|
|
|
#include "init.h"
|
2014-01-22 09:46:15 +01:00
|
|
|
#include "util.h"
|
2015-01-30 10:08:46 +01:00
|
|
|
#include "ui_interface.h"
|
2014-09-05 13:18:35 +02:00
|
|
|
#include "version.h"
|
|
|
|
|
2014-03-19 00:26:14 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2015-02-03 21:09:47 +01:00
|
|
|
#include "wallet/wallet.h"
|
2014-03-19 00:26:14 +01:00
|
|
|
#endif
|
2013-04-14 11:35:37 +02:00
|
|
|
|
|
|
|
#include <QApplication>
|
2014-09-22 10:08:47 +02:00
|
|
|
#include <QCloseEvent>
|
2014-09-18 13:14:38 +02:00
|
|
|
#include <QDesktopWidget>
|
2014-09-22 10:08:47 +02:00
|
|
|
#include <QPainter>
|
2014-11-06 16:28:29 +01:00
|
|
|
#include <QRadialGradient>
|
2013-04-14 11:35:37 +02:00
|
|
|
|
2014-10-09 11:04:49 +02:00
|
|
|
SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
|
2014-09-18 13:14:38 +02:00
|
|
|
QWidget(0, f), curAlignment(0)
|
2013-04-14 11:35:37 +02:00
|
|
|
{
|
|
|
|
// set reference point, paddings
|
|
|
|
int paddingRight = 50;
|
|
|
|
int paddingTop = 50;
|
|
|
|
int titleVersionVSpace = 17;
|
|
|
|
int titleCopyrightVSpace = 40;
|
|
|
|
|
|
|
|
float fontFactor = 1.0;
|
2014-11-06 16:28:29 +01:00
|
|
|
float devicePixelRatio = 1.0;
|
|
|
|
#if QT_VERSION > 0x050100
|
|
|
|
devicePixelRatio = ((QGuiApplication*)QCoreApplication::instance())->devicePixelRatio();
|
|
|
|
#endif
|
2013-04-14 11:35:37 +02:00
|
|
|
|
|
|
|
// define text to place
|
2013-12-13 07:39:56 +01:00
|
|
|
QString titleText = tr("Bitcoin Core");
|
2013-04-14 11:35:37 +02:00
|
|
|
QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
|
2013-12-13 07:39:56 +01:00
|
|
|
QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers"));
|
2014-10-09 11:04:49 +02:00
|
|
|
QString titleAddText = networkStyle->getTitleAddText();
|
2013-04-14 11:35:37 +02:00
|
|
|
|
2015-01-16 22:27:12 +01:00
|
|
|
QString font = QApplication::font().toString();
|
2013-04-14 11:35:37 +02:00
|
|
|
|
2014-11-06 16:28:29 +01:00
|
|
|
// create a bitmap according to device pixelratio
|
|
|
|
QSize splashSize(480*devicePixelRatio,320*devicePixelRatio);
|
|
|
|
pixmap = QPixmap(splashSize);
|
|
|
|
|
|
|
|
#if QT_VERSION > 0x050100
|
|
|
|
// change to HiDPI if it makes sense
|
|
|
|
pixmap.setDevicePixelRatio(devicePixelRatio);
|
|
|
|
#endif
|
2013-04-14 11:35:37 +02:00
|
|
|
|
2014-09-18 13:14:38 +02:00
|
|
|
QPainter pixPaint(&pixmap);
|
2013-04-14 11:35:37 +02:00
|
|
|
pixPaint.setPen(QColor(100,100,100));
|
|
|
|
|
2015-08-09 01:17:27 +02:00
|
|
|
// draw a slightly radial gradient
|
2014-11-06 16:28:29 +01:00
|
|
|
QRadialGradient gradient(QPoint(0,0), splashSize.width()/devicePixelRatio);
|
|
|
|
gradient.setColorAt(0, Qt::white);
|
|
|
|
gradient.setColorAt(1, QColor(247,247,247));
|
|
|
|
QRect rGradient(QPoint(0,0), splashSize);
|
|
|
|
pixPaint.fillRect(rGradient, gradient);
|
|
|
|
|
|
|
|
// draw the bitcoin icon, expected size of PNG: 1024x1024
|
|
|
|
QRect rectIcon(QPoint(-150,-122), QSize(430,430));
|
|
|
|
|
|
|
|
const QSize requiredSize(1024,1024);
|
2014-11-14 12:58:30 +01:00
|
|
|
QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize));
|
2014-11-06 16:28:29 +01:00
|
|
|
|
|
|
|
pixPaint.drawPixmap(rectIcon, icon);
|
|
|
|
|
2013-04-14 11:35:37 +02:00
|
|
|
// check font size and drawing with
|
|
|
|
pixPaint.setFont(QFont(font, 33*fontFactor));
|
|
|
|
QFontMetrics fm = pixPaint.fontMetrics();
|
|
|
|
int titleTextWidth = fm.width(titleText);
|
|
|
|
if(titleTextWidth > 160) {
|
|
|
|
// strange font rendering, Arial probably not found
|
|
|
|
fontFactor = 0.75;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixPaint.setFont(QFont(font, 33*fontFactor));
|
|
|
|
fm = pixPaint.fontMetrics();
|
|
|
|
titleTextWidth = fm.width(titleText);
|
2014-11-06 16:28:29 +01:00
|
|
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
|
2013-04-14 11:35:37 +02:00
|
|
|
|
|
|
|
pixPaint.setFont(QFont(font, 15*fontFactor));
|
|
|
|
|
|
|
|
// if the version string is to long, reduce size
|
|
|
|
fm = pixPaint.fontMetrics();
|
|
|
|
int versionTextWidth = fm.width(versionText);
|
|
|
|
if(versionTextWidth > titleTextWidth+paddingRight-10) {
|
|
|
|
pixPaint.setFont(QFont(font, 10*fontFactor));
|
|
|
|
titleVersionVSpace -= 5;
|
|
|
|
}
|
2014-11-06 16:28:29 +01:00
|
|
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
|
2013-04-14 11:35:37 +02:00
|
|
|
|
|
|
|
// draw copyright stuff
|
|
|
|
pixPaint.setFont(QFont(font, 10*fontFactor));
|
2014-11-06 16:28:29 +01:00
|
|
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
|
2013-04-14 11:35:37 +02:00
|
|
|
|
2014-10-09 11:04:49 +02:00
|
|
|
// draw additional text if special network
|
|
|
|
if(!titleAddText.isEmpty()) {
|
2013-04-14 11:35:37 +02:00
|
|
|
QFont boldFont = QFont(font, 10*fontFactor);
|
|
|
|
boldFont.setWeight(QFont::Bold);
|
|
|
|
pixPaint.setFont(boldFont);
|
|
|
|
fm = pixPaint.fontMetrics();
|
2014-10-09 11:04:49 +02:00
|
|
|
int titleAddTextWidth = fm.width(titleAddText);
|
2014-11-06 16:28:29 +01:00
|
|
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
|
2013-04-14 11:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pixPaint.end();
|
|
|
|
|
2014-09-18 13:14:38 +02:00
|
|
|
// Set window title
|
2014-10-09 11:04:49 +02:00
|
|
|
setWindowTitle(titleText + " " + titleAddText);
|
2014-09-18 13:14:38 +02:00
|
|
|
|
|
|
|
// Resize window and move to center of desktop, disallow resizing
|
2014-11-06 16:28:29 +01:00
|
|
|
QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
|
2014-09-18 13:14:38 +02:00
|
|
|
resize(r.size());
|
|
|
|
setFixedSize(r.size());
|
|
|
|
move(QApplication::desktop()->screenGeometry().center() - r.center());
|
2014-01-08 08:59:24 +01:00
|
|
|
|
|
|
|
subscribeToCoreSignals();
|
|
|
|
}
|
|
|
|
|
|
|
|
SplashScreen::~SplashScreen()
|
|
|
|
{
|
|
|
|
unsubscribeFromCoreSignals();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::slotFinish(QWidget *mainWin)
|
|
|
|
{
|
2014-09-22 15:48:34 +02:00
|
|
|
Q_UNUSED(mainWin);
|
2014-09-18 13:14:38 +02:00
|
|
|
hide();
|
2014-01-08 08:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void InitMessage(SplashScreen *splash, const std::string &message)
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(splash, "showMessage",
|
|
|
|
Qt::QueuedConnection,
|
|
|
|
Q_ARG(QString, QString::fromStdString(message)),
|
|
|
|
Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter),
|
|
|
|
Q_ARG(QColor, QColor(55,55,55)));
|
|
|
|
}
|
|
|
|
|
2014-03-19 00:26:14 +01:00
|
|
|
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
|
|
|
|
{
|
|
|
|
InitMessage(splash, title + strprintf("%d", nProgress) + "%");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
|
|
|
|
{
|
|
|
|
wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-08 08:59:24 +01:00
|
|
|
void SplashScreen::subscribeToCoreSignals()
|
|
|
|
{
|
|
|
|
// Connect signals to client
|
|
|
|
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
|
2014-05-23 18:04:09 +02:00
|
|
|
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
|
2014-03-19 00:26:14 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
|
|
|
|
#endif
|
2014-01-08 08:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::unsubscribeFromCoreSignals()
|
|
|
|
{
|
|
|
|
// Disconnect signals from client
|
|
|
|
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
|
2014-05-23 18:04:09 +02:00
|
|
|
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
2014-03-19 00:26:14 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(pwalletMain)
|
|
|
|
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
|
|
|
#endif
|
2013-04-14 11:35:37 +02:00
|
|
|
}
|
2014-09-18 13:14:38 +02:00
|
|
|
|
|
|
|
void SplashScreen::showMessage(const QString &message, int alignment, const QColor &color)
|
|
|
|
{
|
|
|
|
curMessage = message;
|
|
|
|
curAlignment = alignment;
|
|
|
|
curColor = color;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.drawPixmap(0, 0, pixmap);
|
|
|
|
QRect r = rect().adjusted(5, 5, -5, -5);
|
|
|
|
painter.setPen(curColor);
|
|
|
|
painter.drawText(r, curAlignment, curMessage);
|
|
|
|
}
|
|
|
|
|
2014-09-22 10:08:47 +02:00
|
|
|
void SplashScreen::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2014-10-02 11:26:36 +02:00
|
|
|
StartShutdown(); // allows an "emergency" shutdown during startup
|
2014-09-22 10:08:47 +02:00
|
|
|
event->ignore();
|
|
|
|
}
|