Dogecoin Core  1.14.2
P2P Digital Currency
splashscreen.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include "config/bitcoin-config.h"
7 #endif
8 
9 #include "splashscreen.h"
10 
11 #include "networkstyle.h"
12 
13 #include "clientversion.h"
14 #include "init.h"
15 #include "util.h"
16 #include "ui_interface.h"
17 #include "version.h"
18 
19 #ifdef ENABLE_WALLET
20 #include "wallet/wallet.h"
21 #endif
22 
23 #include <QApplication>
24 #include <QCloseEvent>
25 #include <QDesktopWidget>
26 #include <QPainter>
27 #include <QRadialGradient>
28 
29 #include <boost/bind/bind.hpp>
30 
31 SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
32  QWidget(0, f), curAlignment(0)
33 {
34  // set reference point, paddings
35  int paddingRight = 50;
36  int paddingTop = 50;
37  int titleVersionVSpace = 17;
38  int titleCopyrightVSpace = 40;
39 
40  float fontFactor = 1.0;
41  float devicePixelRatio = 1.0;
42 #if QT_VERSION > 0x050100
43  devicePixelRatio = ((QGuiApplication*)QCoreApplication::instance())->devicePixelRatio();
44 #endif
45 
46  // define text to place
47  QString titleText = tr(PACKAGE_NAME);
48  QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
49  QString copyrightText = QString::fromUtf8(CopyrightHolders(strprintf("\xc2\xA9 %u-%u ", 2009, COPYRIGHT_YEAR)).c_str());
50  QString titleAddText = networkStyle->getTitleAddText();
51 
52  QString font = "Comic Sans MS";
53 
54  // create a bitmap according to device pixelratio
55  QSize splashSize(480*devicePixelRatio,320*devicePixelRatio);
56  pixmap = QPixmap(splashSize);
57 
58 #if QT_VERSION > 0x050100
59  // change to HiDPI if it makes sense
60  pixmap.setDevicePixelRatio(devicePixelRatio);
61 #endif
62 
63  QPainter pixPaint(&pixmap);
64  pixPaint.setPen(QColor(100,100,100));
65 
66  // draw a slightly radial gradient
67  QRadialGradient gradient(QPoint(0,0), splashSize.width()/devicePixelRatio);
68  gradient.setColorAt(0, Qt::white);
69  gradient.setColorAt(1, QColor(247,247,247));
70  QRect rGradient(QPoint(0,0), splashSize);
71  pixPaint.fillRect(rGradient, gradient);
72 
73  // draw the bitcoin icon, expected size of PNG: 1024x1024
74  QRect rectIcon(QPoint(-150,-122), QSize(430,430));
75 
76  const QSize requiredSize(1024,1024);
77  QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize));
78 
79  pixPaint.drawPixmap(rectIcon, icon);
80 
81  // check font size and drawing with
82  pixPaint.setFont(QFont(font, 33*fontFactor));
83  QFontMetrics fm = pixPaint.fontMetrics();
84  int titleTextWidth = fm.width(titleText);
85  if (titleTextWidth > 176) {
86  fontFactor = fontFactor * 176 / titleTextWidth;
87  }
88 
89  pixPaint.setFont(QFont(font, 33*fontFactor));
90  fm = pixPaint.fontMetrics();
91  titleTextWidth = fm.width(titleText);
92  pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
93 
94  pixPaint.setFont(QFont(font, 15*fontFactor));
95 
96  // if the version string is to long, reduce size
97  fm = pixPaint.fontMetrics();
98  int versionTextWidth = fm.width(versionText);
99  if(versionTextWidth > titleTextWidth+paddingRight-10) {
100  pixPaint.setFont(QFont(font, 10*fontFactor));
101  titleVersionVSpace -= 5;
102  }
103  pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
104 
105  // draw copyright stuff
106  {
107  pixPaint.setFont(QFont(font, 10*fontFactor));
108  const int x = pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight;
109  const int y = paddingTop+titleCopyrightVSpace;
110  QRect copyrightRect(x, y, pixmap.width() - x - paddingRight, pixmap.height() - y);
111  pixPaint.drawText(copyrightRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, copyrightText);
112  }
113 
114  // draw additional text if special network
115  if(!titleAddText.isEmpty()) {
116  QFont boldFont = QFont(font, 10*fontFactor);
117  boldFont.setWeight(QFont::Bold);
118  pixPaint.setFont(boldFont);
119  fm = pixPaint.fontMetrics();
120  int titleAddTextWidth = fm.width(titleAddText);
121  pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
122  }
123 
124  pixPaint.end();
125 
126  // Set window title
127  setWindowTitle(titleText + " " + titleAddText);
128 
129  // Resize window and move to center of desktop, disallow resizing
130  QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
131  resize(r.size());
132  setFixedSize(r.size());
133  move(QApplication::desktop()->screenGeometry().center() - r.center());
134 
136 }
137 
139 {
141 }
142 
143 void SplashScreen::slotFinish(QWidget *mainWin)
144 {
145  Q_UNUSED(mainWin);
146 
147  /* If the window is minimized, hide() will be ignored. */
148  /* Make sure we de-minimize the splashscreen window before hiding */
149  if (isMinimized())
150  showNormal();
151  hide();
152  deleteLater(); // No more need for this
153 }
154 
155 static void InitMessage(SplashScreen *splash, const std::string &message)
156 {
157  QMetaObject::invokeMethod(splash, "showMessage",
158  Qt::QueuedConnection,
159  Q_ARG(QString, QString::fromStdString(message)),
160  Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter),
161  Q_ARG(QColor, QColor(55,55,55)));
162 }
163 
164 static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
165 {
166  InitMessage(splash, title + strprintf("%d", nProgress) + "%");
167 }
168 
169 #ifdef ENABLE_WALLET
171 {
172  wallet->ShowProgress.connect(boost::bind(ShowProgress, this,
173  boost::placeholders::_1,
174  boost::placeholders::_2));
175  connectedWallets.push_back(wallet);
176 }
177 #endif
178 
180 {
181  // Connect signals to client
182  uiInterface.InitMessage.connect(boost::bind(InitMessage, this,
183  boost::placeholders::_1));
184  uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this,
185  boost::placeholders::_1,boost::placeholders::_2));
186 #ifdef ENABLE_WALLET
187  uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this,
188  boost::placeholders::_1));
189 #endif
190 }
191 
193 {
194  // Disconnect signals from client
195  uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this,
196  boost::placeholders::_1));
197  uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this,
198  boost::placeholders::_1,
199  boost::placeholders::_2));
200 #ifdef ENABLE_WALLET
201  Q_FOREACH(CWallet* const & pwallet, connectedWallets) {
202  pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this,
203  boost::placeholders::_1,
204  boost::placeholders::_2));
205  }
206 #endif
207 }
208 
209 void SplashScreen::showMessage(const QString &message, int alignment, const QColor &color)
210 {
211  curMessage = message;
212  curAlignment = alignment;
213  curColor = color;
214  update();
215 }
216 
217 void SplashScreen::paintEvent(QPaintEvent *event)
218 {
219  QPainter painter(this);
220  painter.drawPixmap(0, 0, pixmap);
221  QRect r = rect().adjusted(5, 5, -5, -5);
222  painter.setPen(curColor);
223  painter.drawText(r, curAlignment, curMessage);
224 }
225 
226 void SplashScreen::closeEvent(QCloseEvent *event)
227 {
228  StartShutdown(); // allows an "emergency" shutdown during startup
229  event->ignore();
230 }
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
A wallet has been loaded.
Definition: ui_interface.h:98
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: ui_interface.h:101
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
Definition: ui_interface.h:83
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:493
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:878
const QString & getTitleAddText() const
Definition: networkstyle.h:22
const QIcon & getAppIcon() const
Definition: networkstyle.h:20
Class for the splashscreen with information of the running client.
Definition: splashscreen.h:20
void ConnectWallet(CWallet *)
Connect wallet signals to splash screen.
void paintEvent(QPaintEvent *event)
void showMessage(const QString &message, int alignment, const QColor &color)
Show message and progress.
void unsubscribeFromCoreSignals()
Disconnect core signals to splash screen.
void subscribeToCoreSignals()
Connect core signals to splash screen.
QColor curColor
Definition: splashscreen.h:48
QList< CWallet * > connectedWallets
Definition: splashscreen.h:51
SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
QString curMessage
Definition: splashscreen.h:47
QPixmap pixmap
Definition: splashscreen.h:46
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it's not defined as slot.
void closeEvent(QCloseEvent *event)
std::string FormatFullVersion()
#define COPYRIGHT_YEAR
Copyright year (2009-this) Todo: update this when changing our copyright comments in the source.
Definition: clientversion.h:29
void StartShutdown()
Definition: init.cpp:134
const char * titleAddText
#define strprintf
Definition: tinyformat.h:1047
CClientUIInterface uiInterface
Definition: ui_interface.cpp:8
std::string CopyrightHolders(const std::string &strPrefix)
Definition: util.cpp:847