]>
Commit | Line | Data |
---|---|---|
f914f1a7 | 1 | // Copyright (c) 2011-2014 The Bitcoin Core developers |
78253fcb | 2 | // Distributed under the MIT software license, see the accompanying |
e592d43f WL |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | ||
f9124587 | 5 | #include "splashscreen.h" |
51ed9ec9 | 6 | |
60c14693 PK |
7 | #include "networkstyle.h" |
8 | ||
f9124587 | 9 | #include "clientversion.h" |
39278369 | 10 | #include "init.h" |
4bee715b | 11 | #include "util.h" |
60c14693 | 12 | #include "ui_interface.h" |
5e83bc40 PK |
13 | #include "version.h" |
14 | ||
39278369 | 15 | #ifdef ENABLE_WALLET |
50c72f23 | 16 | #include "wallet/wallet.h" |
39278369 | 17 | #endif |
f9124587 | 18 | |
f9124587 | 19 | #include <QApplication> |
cfc5cfb0 | 20 | #include <QCloseEvent> |
a49f11d9 | 21 | #include <QDesktopWidget> |
cfc5cfb0 | 22 | #include <QPainter> |
54f2571a | 23 | #include <QRadialGradient> |
f9124587 | 24 | |
6de50c3c | 25 | SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) : |
a49f11d9 | 26 | QWidget(0, f), curAlignment(0) |
f9124587 JS |
27 | { |
28 | // set reference point, paddings | |
29 | int paddingRight = 50; | |
30 | int paddingTop = 50; | |
31 | int titleVersionVSpace = 17; | |
32 | int titleCopyrightVSpace = 40; | |
33 | ||
34 | float fontFactor = 1.0; | |
54f2571a JS |
35 | float devicePixelRatio = 1.0; |
36 | #if QT_VERSION > 0x050100 | |
37 | devicePixelRatio = ((QGuiApplication*)QCoreApplication::instance())->devicePixelRatio(); | |
38 | #endif | |
f9124587 JS |
39 | |
40 | // define text to place | |
22f0135d | 41 | QString titleText = tr("Bitcoin Core"); |
f9124587 | 42 | QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion())); |
22f0135d | 43 | QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers")); |
6de50c3c | 44 | QString titleAddText = networkStyle->getTitleAddText(); |
f9124587 | 45 | |
73cd4edb | 46 | QString font = QApplication::font().toString(); |
f9124587 | 47 | |
54f2571a JS |
48 | // create a bitmap according to device pixelratio |
49 | QSize splashSize(480*devicePixelRatio,320*devicePixelRatio); | |
50 | pixmap = QPixmap(splashSize); | |
51 | ||
52 | #if QT_VERSION > 0x050100 | |
53 | // change to HiDPI if it makes sense | |
54 | pixmap.setDevicePixelRatio(devicePixelRatio); | |
55 | #endif | |
f9124587 | 56 | |
a49f11d9 | 57 | QPainter pixPaint(&pixmap); |
f9124587 JS |
58 | pixPaint.setPen(QColor(100,100,100)); |
59 | ||
45bfa137 | 60 | // draw a slightly radial gradient |
54f2571a JS |
61 | QRadialGradient gradient(QPoint(0,0), splashSize.width()/devicePixelRatio); |
62 | gradient.setColorAt(0, Qt::white); | |
63 | gradient.setColorAt(1, QColor(247,247,247)); | |
64 | QRect rGradient(QPoint(0,0), splashSize); | |
65 | pixPaint.fillRect(rGradient, gradient); | |
66 | ||
67 | // draw the bitcoin icon, expected size of PNG: 1024x1024 | |
68 | QRect rectIcon(QPoint(-150,-122), QSize(430,430)); | |
69 | ||
70 | const QSize requiredSize(1024,1024); | |
8e76ca04 | 71 | QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize)); |
54f2571a JS |
72 | |
73 | pixPaint.drawPixmap(rectIcon, icon); | |
74 | ||
f9124587 JS |
75 | // check font size and drawing with |
76 | pixPaint.setFont(QFont(font, 33*fontFactor)); | |
77 | QFontMetrics fm = pixPaint.fontMetrics(); | |
78 | int titleTextWidth = fm.width(titleText); | |
79 | if(titleTextWidth > 160) { | |
80 | // strange font rendering, Arial probably not found | |
81 | fontFactor = 0.75; | |
82 | } | |
83 | ||
84 | pixPaint.setFont(QFont(font, 33*fontFactor)); | |
85 | fm = pixPaint.fontMetrics(); | |
86 | titleTextWidth = fm.width(titleText); | |
54f2571a | 87 | pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText); |
f9124587 JS |
88 | |
89 | pixPaint.setFont(QFont(font, 15*fontFactor)); | |
90 | ||
91 | // if the version string is to long, reduce size | |
92 | fm = pixPaint.fontMetrics(); | |
93 | int versionTextWidth = fm.width(versionText); | |
94 | if(versionTextWidth > titleTextWidth+paddingRight-10) { | |
95 | pixPaint.setFont(QFont(font, 10*fontFactor)); | |
96 | titleVersionVSpace -= 5; | |
97 | } | |
54f2571a | 98 | pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText); |
f9124587 JS |
99 | |
100 | // draw copyright stuff | |
101 | pixPaint.setFont(QFont(font, 10*fontFactor)); | |
54f2571a | 102 | pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText); |
f9124587 | 103 | |
6de50c3c WL |
104 | // draw additional text if special network |
105 | if(!titleAddText.isEmpty()) { | |
f9124587 JS |
106 | QFont boldFont = QFont(font, 10*fontFactor); |
107 | boldFont.setWeight(QFont::Bold); | |
108 | pixPaint.setFont(boldFont); | |
109 | fm = pixPaint.fontMetrics(); | |
6de50c3c | 110 | int titleAddTextWidth = fm.width(titleAddText); |
54f2571a | 111 | pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText); |
f9124587 JS |
112 | } |
113 | ||
114 | pixPaint.end(); | |
115 | ||
a49f11d9 | 116 | // Set window title |
6de50c3c | 117 | setWindowTitle(titleText + " " + titleAddText); |
a49f11d9 WL |
118 | |
119 | // Resize window and move to center of desktop, disallow resizing | |
54f2571a | 120 | QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio)); |
a49f11d9 WL |
121 | resize(r.size()); |
122 | setFixedSize(r.size()); | |
123 | move(QApplication::desktop()->screenGeometry().center() - r.center()); | |
35ecf854 WL |
124 | |
125 | subscribeToCoreSignals(); | |
126 | } | |
127 | ||
128 | SplashScreen::~SplashScreen() | |
129 | { | |
130 | unsubscribeFromCoreSignals(); | |
131 | } | |
132 | ||
133 | void SplashScreen::slotFinish(QWidget *mainWin) | |
134 | { | |
bb26e2c8 | 135 | Q_UNUSED(mainWin); |
a49f11d9 | 136 | hide(); |
35ecf854 WL |
137 | } |
138 | ||
139 | static void InitMessage(SplashScreen *splash, const std::string &message) | |
140 | { | |
141 | QMetaObject::invokeMethod(splash, "showMessage", | |
142 | Qt::QueuedConnection, | |
143 | Q_ARG(QString, QString::fromStdString(message)), | |
144 | Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter), | |
145 | Q_ARG(QColor, QColor(55,55,55))); | |
146 | } | |
147 | ||
39278369 CL |
148 | static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress) |
149 | { | |
150 | InitMessage(splash, title + strprintf("%d", nProgress) + "%"); | |
151 | } | |
152 | ||
153 | #ifdef ENABLE_WALLET | |
154 | static void ConnectWallet(SplashScreen *splash, CWallet* wallet) | |
155 | { | |
156 | wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2)); | |
157 | } | |
158 | #endif | |
159 | ||
35ecf854 WL |
160 | void SplashScreen::subscribeToCoreSignals() |
161 | { | |
162 | // Connect signals to client | |
163 | uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1)); | |
06a91d96 | 164 | uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); |
39278369 CL |
165 | #ifdef ENABLE_WALLET |
166 | uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1)); | |
167 | #endif | |
35ecf854 WL |
168 | } |
169 | ||
170 | void SplashScreen::unsubscribeFromCoreSignals() | |
171 | { | |
172 | // Disconnect signals from client | |
173 | uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); | |
06a91d96 | 174 | uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); |
39278369 CL |
175 | #ifdef ENABLE_WALLET |
176 | if(pwalletMain) | |
177 | pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); | |
178 | #endif | |
f9124587 | 179 | } |
a49f11d9 WL |
180 | |
181 | void SplashScreen::showMessage(const QString &message, int alignment, const QColor &color) | |
182 | { | |
183 | curMessage = message; | |
184 | curAlignment = alignment; | |
185 | curColor = color; | |
186 | update(); | |
187 | } | |
188 | ||
189 | void SplashScreen::paintEvent(QPaintEvent *event) | |
190 | { | |
191 | QPainter painter(this); | |
192 | painter.drawPixmap(0, 0, pixmap); | |
193 | QRect r = rect().adjusted(5, 5, -5, -5); | |
194 | painter.setPen(curColor); | |
195 | painter.drawText(r, curAlignment, curMessage); | |
196 | } | |
197 | ||
cfc5cfb0 WL |
198 | void SplashScreen::closeEvent(QCloseEvent *event) |
199 | { | |
4bd11852 | 200 | StartShutdown(); // allows an "emergency" shutdown during startup |
cfc5cfb0 WL |
201 | event->ignore(); |
202 | } |