1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/qt/splashscreen.h]
/**
| Class for the splashscreen with information
| of the running client.
|
| -----------
| @note
|
| this is intentionally not a QSplashScreen.
| Bitcoin Core initialization can take
| a long time, and in that case a progress
| window that cannot be moved around and
| minimized has turned out to be frustrating
| to the user.
|
*/
#[Q_OBJECT]
pub struct SplashScreen {
base: QWidget,
pixmap: QPixmap,
cur_message: String,
cur_color: QColor,
cur_alignment: i32,
node: Rc<RefCell<dyn NodeInterface>>, // default = nullptr
shutdown: bool, // default = false
handler_init_message: Box<dyn Handler>,
handler_show_progress: Box<dyn Handler>,
handler_load_wallet: Box<dyn Handler>,
connected_wallets: LinkedList<Box<dyn WalletInterface>>,
connected_wallet_handlers: LinkedList<Box<dyn Handler>>,
}
//-------------------------------------------[.cpp/bitcoin/src/qt/splashscreen.cpp]
impl Drop for SplashScreen {
fn drop(&mut self) {
todo!();
/*
if (m_node) unsubscribeFromCoreSignals();
*/
}
}
impl SplashScreen {
pub fn new(network_style: *const NetworkStyle) -> Self {
todo!();
/*
: q_widget(),
: cur_alignment(0),
// set reference point, paddings
int paddingRight = 50;
int paddingTop = 50;
int titleVersionVSpace = 17;
int titleCopyrightVSpace = 40;
float fontFactor = 1.0;
float devicePixelRatio = 1.0;
devicePixelRatio = static_cast<QGuiApplication*>(QCoreApplication::instance())->devicePixelRatio();
// define text to place
QString titleText = PACKAGE_NAME;
QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
QString copyrightText = QString::fromUtf8(CopyrightHolders(strprintf("\xc2\xA9 %u-%u ", 2009, COPYRIGHT_YEAR)).c_str());
QString titleAddText = networkStyle->getTitleAddText();
QString font = QApplication::font().toString();
// create a bitmap according to device pixelratio
QSize splashSize(480*devicePixelRatio,320*devicePixelRatio);
pixmap = QPixmap(splashSize);
// change to HiDPI if it makes sense
pixmap.setDevicePixelRatio(devicePixelRatio);
QPainter pixPaint(&pixmap);
pixPaint.setPen(QColor(100,100,100));
// draw a slightly radial gradient
QRadialGradient gradient(QPoint(0,0), splashSize.width()/devicePixelRatio);
gradient.setColorAt(0, Qtwhite);
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);
QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize));
pixPaint.drawPixmap(rectIcon, icon);
// check font size and drawing with
pixPaint.setFont(QFont(font, 33*fontFactor));
QFontMetrics fm = pixPaint.fontMetrics();
int titleTextWidth = typename gui_util::TextWidth(fm, titleText);
if (titleTextWidth > 176) {
fontFactor = fontFactor * 176 / titleTextWidth;
}
pixPaint.setFont(QFont(font, 33*fontFactor));
fm = pixPaint.fontMetrics();
titleTextWidth = typename gui_util::TextWidth(fm, titleText);
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
pixPaint.setFont(QFont(font, 15*fontFactor));
// if the version string is too long, reduce size
fm = pixPaint.fontMetrics();
int versionTextWidth = typename gui_util::TextWidth(fm, versionText);
if(versionTextWidth > titleTextWidth+paddingRight-10) {
pixPaint.setFont(QFont(font, 10*fontFactor));
titleVersionVSpace -= 5;
}
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
// draw copyright stuff
{
pixPaint.setFont(QFont(font, 10*fontFactor));
const int x = pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight;
const int y = paddingTop+titleCopyrightVSpace;
QRect copyrightRect(x, y, pixmap.width() - x - paddingRight, pixmap.height() - y);
pixPaint.drawText(copyrightRect, QtAlignLeft | QtAlignTop | QtTextWordWrap, copyrightText);
}
// draw additional text if special network
if(!titleAddText.isEmpty()) {
QFont boldFont = QFont(font, 10*fontFactor);
boldFont.setWeight(QFont::Bold);
pixPaint.setFont(boldFont);
fm = pixPaint.fontMetrics();
int titleAddTextWidth = typename gui_util::TextWidth(fm, titleAddText);
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
}
pixPaint.end();
// Set window title
setWindowTitle(titleText + " " + titleAddText);
// Resize window and move to center of desktop, disallow resizing
QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
resize(r.size());
setFixedSize(r.size());
move(QGuiApplication::primaryScreen()->geometry().center() - r.center());
installEventFilter(this);
typename gui_util::handleCloseWindowShortcut(this);
*/
}
pub fn set_node(&mut self, node: Rc<RefCell<dyn NodeInterface>>) {
todo!();
/*
assert(!m_node);
m_node = &node;
subscribeToCoreSignals();
if (m_shutdown) m_node->startShutdown();
*/
}
/**
| Initiate shutdown
|
*/
#[Q_SLOT]
pub fn shutdown(&mut self) {
todo!();
/*
m_shutdown = true;
if (m_node) m_node->startShutdown();
*/
}
#[Q_SLOT]
pub fn event_filter(&mut self,
obj: *mut QObject,
ev: *mut QEvent) -> bool {
todo!();
/*
if (ev->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
if (keyEvent->key() == QtKey_Q) {
shutdown();
}
}
return QObject::eventFilter(obj, ev);
*/
}
/**
| Hide the splash screen window and schedule
| the splash screen object for deletion
|
*/
#[Q_SLOT]
pub fn finish(&mut self) {
todo!();
/*
/* If the window is minimized, hide() will be ignored. */
/* Make sure we de-minimize the splashscreen window before hiding */
if (isMinimized())
showNormal();
hide();
deleteLater(); // No more need for this
*/
}
/**
| Connect core signals to splash screen
|
*/
#[Q_SLOT]
pub fn subscribe_to_core_signals(&mut self) {
todo!();
/*
// Connect signals to client
m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
*/
}
/**
| Handle wallet load notifications.
|
*/
#[Q_SLOT]
pub fn handle_load_wallet(&mut self) {
todo!();
/*
#ifdef ENABLE_WALLET
if (!WalletModel::isWalletEnabled()) return;
m_handler_load_wallet = m_node->walletClient().handleLoadWallet([this](std::unique_ptr<typename interfaces::Wallet> wallet) {
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
m_connected_wallets.emplace_back(std::move(wallet));
});
#endif
*/
}
/**
| Disconnect core signals to splash screen
|
*/
#[Q_SLOT]
pub fn unsubscribe_from_core_signals(&mut self) {
todo!();
/*
// Disconnect signals from client
m_handler_init_message->disconnect();
m_handler_show_progress->disconnect();
for (const auto& handler : m_connected_wallet_handlers) {
handler->disconnect();
}
m_connected_wallet_handlers.clear();
m_connected_wallets.clear();
*/
}
/**
| Show message and progress
|
*/
#[Q_SLOT]
pub fn show_message(&mut self,
message: &String,
alignment: i32,
color: &QColor) {
todo!();
/*
curMessage = message;
curAlignment = alignment;
curColor = color;
update();
*/
}
pub fn paint_event(&mut self, event: *mut QPaintEvent) {
todo!();
/*
QPainter painter(this);
painter.drawPixmap(0, 0, pixmap);
QRect r = rect().adjusted(5, 5, -5, -5);
painter.setPen(curColor);
painter.drawText(r, curAlignment, curMessage);
*/
}
pub fn close_event(&mut self, event: *mut QCloseEvent) {
todo!();
/*
shutdown(); // allows an "emergency" shutdown during startup
event->ignore();
*/
}
}
pub fn init_message(
splash: *mut SplashScreen,
message: &String) {
todo!();
/*
bool invoked = QMetaObject::invokeMethod(splash, "showMessage",
QtQueuedConnection,
Q_ARG(QString, QString::fromStdString(message)),
Q_ARG(int, QtAlignBottom|QtAlignHCenter),
Q_ARG(QColor, QColor(55,55,55)));
assert(invoked);
*/
}
pub fn show_progress(
splash: *mut SplashScreen,
title: &String,
n_progress: i32,
resume_possible: bool) {
todo!();
/*
InitMessage(splash, title + std::string("\n") +
(resume_possible ? SplashScreen::tr("(press q to shutdown and continue later)").toStdString()
: SplashScreen::tr("press q to shutdown").toStdString()) +
strprintf("\n%d", nProgress) + "%");
*/
}