Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 <qt/splashscreen.h>
10
11#include <clientversion.h>
12#include <common/system.h>
13#include <interfaces/handler.h>
14#include <interfaces/node.h>
15#include <interfaces/wallet.h>
16#include <qt/guiutil.h>
17#include <qt/networkstyle.h>
18#include <qt/walletmodel.h>
19#include <util/translation.h>
20
21#include <functional>
22
23#include <QApplication>
24#include <QCloseEvent>
25#include <QPainter>
26#include <QRadialGradient>
27#include <QScreen>
28
30 : QWidget(nullptr), curAlignment(0) {
31 // set reference point, paddings
32 int paddingRight = 50;
33 int paddingTop = 50;
34 int titleVersionVSpace = 17;
35 int titleCopyrightVSpace = 40;
36
37 float fontFactor = 1.0;
38 float devicePixelRatio = 1.0;
40 static_cast<QGuiApplication *>(QCoreApplication::instance())
42
43 // define text to place
46 QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
47 QString copyrightText = QString::fromUtf8(
48 CopyrightHolders(strprintf("\xc2\xA9 %u-%u ", 2009, COPYRIGHT_YEAR))
49 .c_str());
50 QString titleAddText = networkStyle->getTitleAddText();
51
52 QString font = QApplication::font().toString();
53
54 // create a bitmap according to device pixelratio
57
58 // change to HiDPI if it makes sense
59 pixmap.setDevicePixelRatio(devicePixelRatio);
60
62 pixPaint.setPen(QColor(100, 100, 100));
63
64 // draw a slightly radial gradient
67 gradient.setColorAt(0, Qt::white);
68 gradient.setColorAt(1, QColor(247, 247, 247));
70 pixPaint.fillRect(rGradient, gradient);
71
72 // draw the bitcoin icon, expected size of PNG: 1024x1024
73 QRect rectIcon(QPoint(-10, -100), QSize(430, 430));
74
75 const QSize requiredSize(1024, 1024);
76 QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize));
77
78 pixPaint.drawPixmap(rectIcon, icon);
79
80 // check font size and drawing with
81 pixPaint.setFont(QFont(font, 33 * fontFactor));
82 QFontMetrics fm = pixPaint.fontMetrics();
84 if (titleTextWidth > 176) {
86 }
87
88 pixPaint.setFont(QFont(font, 33 * fontFactor));
89 fm = pixPaint.fontMetrics();
91 pixPaint.drawText(pixmap.width() / devicePixelRatio - titleTextWidth -
94
95 pixPaint.setFont(QFont(font, 15 * fontFactor));
96
97 // if the version string is too long, reduce size
98 fm = pixPaint.fontMetrics();
101 pixPaint.setFont(QFont(font, 10 * fontFactor));
103 }
104 pixPaint.drawText(pixmap.width() / devicePixelRatio - titleTextWidth -
105 paddingRight + 2,
107
108 // draw copyright stuff
109 {
110 pixPaint.setFont(QFont(font, 10 * fontFactor));
111 const int x =
113 const int y = paddingTop + titleCopyrightVSpace;
114 QRect copyrightRect(x, y, pixmap.width() - x - paddingRight,
115 pixmap.height() - y);
116 pixPaint.drawText(copyrightRect,
117 Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap,
119 }
120
121 // draw additional text if special network
122 if (!titleAddText.isEmpty()) {
124 boldFont.setWeight(QFont::Bold);
125 pixPaint.setFont(boldFont);
126 fm = pixPaint.fontMetrics();
127 int titleAddTextWidth = GUIUtil::TextWidth(fm, titleAddText);
128 pixPaint.drawText(pixmap.width() / devicePixelRatio -
130 15, titleAddText);
131 }
132
133 pixPaint.end();
134
135 // Set window title
136 setWindowTitle(titleText + " " + titleAddText);
137
138 // Resize window and move to center of desktop, disallow resizing
139 QRect r(QPoint(), QSize(pixmap.size().width() / devicePixelRatio,
140 pixmap.size().height() / devicePixelRatio));
141 resize(r.size());
142 setFixedSize(r.size());
143 move(QGuiApplication::primaryScreen()->geometry().center() - r.center());
144
145 installEventFilter(this);
146
148}
149
155
164
166 m_shutdown = true;
167 if (m_node) {
169 }
170}
171
173 if (ev->type() == QEvent::KeyPress) {
174 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
175 if (keyEvent->key() == Qt::Key_Q) {
176 shutdown();
177 }
178 }
179 return QObject::eventFilter(obj, ev);
180}
181
183 /* If the window is minimized, hide() will be ignored. */
184 /* Make sure we de-minimize the splashscreen window before hiding */
185 if (isMinimized()) {
186 showNormal();
187 }
188 hide();
189 // No more need for this
190 deleteLater();
191}
192
193static void InitMessage(SplashScreen *splash, const std::string &message) {
194 bool invoked = QMetaObject::invokeMethod(
195 splash, "showMessage", Qt::QueuedConnection,
196 Q_ARG(QString, QString::fromStdString(message)),
197 Q_ARG(int, Qt::AlignBottom | Qt::AlignHCenter),
198 Q_ARG(QColor, QColor(55, 55, 55)));
200}
201
202static void ShowProgress(SplashScreen *splash, const std::string &title,
203 int nProgress, bool resume_possible) {
205 splash,
206 title + std::string("\n") +
208 ? _("(press q to shutdown and continue later)").translated
209 : _("press q to shutdown").translated) +
210 strprintf("\n%d", nProgress) + "%");
211}
212
214 // Connect signals to client
216 std::bind(InitMessage, this, std::placeholders::_1));
218 std::bind(ShowProgress, this, std::placeholders::_1,
219 std::placeholders::_2, std::placeholders::_3));
220}
221
223#ifdef ENABLE_WALLET
225 return;
226 }
228 [this](std::unique_ptr<interfaces::Wallet> wallet) {
229 m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(
230 std::bind(ShowProgress, this, std::placeholders::_1,
231 std::placeholders::_2, false)));
232 m_connected_wallets.emplace_back(std::move(wallet));
233 });
234#endif
235}
236
238 // Disconnect signals from client
239 m_handler_init_message->disconnect();
240 m_handler_show_progress->disconnect();
241 for (const auto &handler : m_connected_wallet_handlers) {
242 handler->disconnect();
243 }
245 m_connected_wallets.clear();
246}
247
248void SplashScreen::showMessage(const QString &message, int alignment,
249 const QColor &color) {
250 curMessage = message;
251 curAlignment = alignment;
252 curColor = color;
253 update();
254}
255
257 QPainter painter(this);
258 painter.drawPixmap(0, 0, pixmap);
259 QRect r = rect().adjusted(5, 5, -5, -5);
260 painter.setPen(curColor);
261 painter.drawText(r, curAlignment, curMessage);
262}
263
265 // allows an "emergency" shutdown during startup
266 shutdown();
267 event->ignore();
268}
Class for the splashscreen with information of the running client.
void shutdown()
Initiate shutdown.
std::unique_ptr< interfaces::Handler > m_handler_show_progress
void showMessage(const QString &message, int alignment, const QColor &color)
Show message and progress.
void unsubscribeFromCoreSignals()
Disconnect core signals to splash screen.
std::list< std::unique_ptr< interfaces::Wallet > > m_connected_wallets
void subscribeToCoreSignals()
Connect core signals to splash screen.
void finish()
Hide the splash screen window and schedule the splash screen object for deletion.
QColor curColor
std::list< std::unique_ptr< interfaces::Handler > > m_connected_wallet_handlers
std::unique_ptr< interfaces::Handler > m_handler_init_message
void paintEvent(QPaintEvent *event) override
void closeEvent(QCloseEvent *event) override
void handleLoadWallet()
Handle wallet load notifications.
QString curMessage
void setNode(interfaces::Node &node)
QPixmap pixmap
bool eventFilter(QObject *obj, QEvent *ev) override
SplashScreen(const NetworkStyle *networkStyle)
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
interfaces::Node * m_node
static bool isWalletEnabled()
Top-level interface for a bitcoin node (bitcoind process).
Definition node.h:59
virtual std::unique_ptr< Handler > handleInitMessage(InitMessageFn fn)=0
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
virtual void startShutdown()=0
Start shutdown.
virtual WalletClient & walletClient()=0
Get wallet client.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
std::string CopyrightHolders(const std::string &strPrefix)
std::string FormatFullVersion()
void handleCloseWindowShortcut(QWidget *w)
Definition guiutil.cpp:407
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
Definition guiutil.cpp:945
Definition init.h:28
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
bool(* handler)(Config &config, const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition rest.cpp:818
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress, bool resume_possible)
static void InitMessage(SplashScreen *splash, const std::string &message)
std::string translated
Definition translation.h:19
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
bilingual_str _(const char *psz)
Translation function.
Definition translation.h:68
assert(!tx.IsCoinBase())