Changeset View
Changeset View
Standalone View
Standalone View
src/qt/splashscreen.cpp
Show All 17 Lines | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QCloseEvent> | #include <QCloseEvent> | ||||
#include <QPainter> | #include <QPainter> | ||||
#include <QRadialGradient> | #include <QRadialGradient> | ||||
#include <QScreen> | #include <QScreen> | ||||
SplashScreen::SplashScreen(interfaces::Node &node, | SplashScreen::SplashScreen(const NetworkStyle *networkStyle) | ||||
const NetworkStyle *networkStyle) | : QWidget(nullptr), curAlignment(0) { | ||||
: QWidget(nullptr), curAlignment(0), m_node(node) { | |||||
// set reference point, paddings | // set reference point, paddings | ||||
int paddingRight = 50; | int paddingRight = 50; | ||||
int paddingTop = 50; | int paddingTop = 50; | ||||
int titleVersionVSpace = 17; | int titleVersionVSpace = 17; | ||||
int titleCopyrightVSpace = 40; | int titleCopyrightVSpace = 40; | ||||
float fontFactor = 1.0; | float fontFactor = 1.0; | ||||
float devicePixelRatio = 1.0; | float devicePixelRatio = 1.0; | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | SplashScreen::SplashScreen(const NetworkStyle *networkStyle) | ||||
// Resize window and move to center of desktop, disallow resizing | // Resize window and move to center of desktop, disallow resizing | ||||
QRect r(QPoint(), QSize(pixmap.size().width() / devicePixelRatio, | QRect r(QPoint(), QSize(pixmap.size().width() / devicePixelRatio, | ||||
pixmap.size().height() / devicePixelRatio)); | pixmap.size().height() / devicePixelRatio)); | ||||
resize(r.size()); | resize(r.size()); | ||||
setFixedSize(r.size()); | setFixedSize(r.size()); | ||||
move(QGuiApplication::primaryScreen()->geometry().center() - r.center()); | move(QGuiApplication::primaryScreen()->geometry().center() - r.center()); | ||||
subscribeToCoreSignals(); | |||||
installEventFilter(this); | installEventFilter(this); | ||||
} | } | ||||
SplashScreen::~SplashScreen() { | SplashScreen::~SplashScreen() { | ||||
if (m_node) { | |||||
unsubscribeFromCoreSignals(); | unsubscribeFromCoreSignals(); | ||||
} | } | ||||
} | |||||
void SplashScreen::setNode(interfaces::Node &node) { | |||||
assert(!m_node); | |||||
m_node = &node; | |||||
subscribeToCoreSignals(); | |||||
} | |||||
void SplashScreen::shutdown() { | |||||
if (m_node) { | |||||
m_node->startShutdown(); | |||||
} | |||||
} | |||||
bool SplashScreen::eventFilter(QObject *obj, QEvent *ev) { | bool SplashScreen::eventFilter(QObject *obj, QEvent *ev) { | ||||
if (ev->type() == QEvent::KeyPress) { | if (ev->type() == QEvent::KeyPress) { | ||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); | ||||
if (keyEvent->text()[0] == 'q') { | if (keyEvent->text()[0] == 'q') { | ||||
m_node.startShutdown(); | shutdown(); | ||||
} | } | ||||
} | } | ||||
return QObject::eventFilter(obj, ev); | return QObject::eventFilter(obj, ev); | ||||
} | } | ||||
void SplashScreen::finish() { | void SplashScreen::finish() { | ||||
/* If the window is minimized, hide() will be ignored. */ | /* If the window is minimized, hide() will be ignored. */ | ||||
/* Make sure we de-minimize the splashscreen window before hiding */ | /* Make sure we de-minimize the splashscreen window before hiding */ | ||||
Show All 30 Lines | m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress( | ||||
std::bind(ShowProgress, this, std::placeholders::_1, | std::bind(ShowProgress, this, std::placeholders::_1, | ||||
std::placeholders::_2, false))); | std::placeholders::_2, false))); | ||||
m_connected_wallets.emplace_back(std::move(wallet)); | m_connected_wallets.emplace_back(std::move(wallet)); | ||||
} | } | ||||
#endif | #endif | ||||
void SplashScreen::subscribeToCoreSignals() { | void SplashScreen::subscribeToCoreSignals() { | ||||
// Connect signals to client | // Connect signals to client | ||||
m_handler_init_message = m_node.handleInitMessage( | m_handler_init_message = m_node->handleInitMessage( | ||||
std::bind(InitMessage, this, std::placeholders::_1)); | std::bind(InitMessage, this, std::placeholders::_1)); | ||||
m_handler_show_progress = m_node.handleShowProgress( | m_handler_show_progress = m_node->handleShowProgress( | ||||
std::bind(ShowProgress, this, std::placeholders::_1, | std::bind(ShowProgress, this, std::placeholders::_1, | ||||
std::placeholders::_2, std::placeholders::_3)); | std::placeholders::_2, std::placeholders::_3)); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
m_handler_load_wallet = m_node.handleLoadWallet( | m_handler_load_wallet = m_node->handleLoadWallet( | ||||
[this](std::unique_ptr<interfaces::Wallet> wallet) { | [this](std::unique_ptr<interfaces::Wallet> wallet) { | ||||
ConnectWallet(std::move(wallet)); | ConnectWallet(std::move(wallet)); | ||||
}); | }); | ||||
#endif | #endif | ||||
} | } | ||||
void SplashScreen::unsubscribeFromCoreSignals() { | void SplashScreen::unsubscribeFromCoreSignals() { | ||||
// Disconnect signals from client | // Disconnect signals from client | ||||
Show All 19 Lines | void SplashScreen::paintEvent(QPaintEvent *event) { | ||||
painter.drawPixmap(0, 0, pixmap); | painter.drawPixmap(0, 0, pixmap); | ||||
QRect r = rect().adjusted(5, 5, -5, -5); | QRect r = rect().adjusted(5, 5, -5, -5); | ||||
painter.setPen(curColor); | painter.setPen(curColor); | ||||
painter.drawText(r, curAlignment, curMessage); | painter.drawText(r, curAlignment, curMessage); | ||||
} | } | ||||
void SplashScreen::closeEvent(QCloseEvent *event) { | void SplashScreen::closeEvent(QCloseEvent *event) { | ||||
// allows an "emergency" shutdown during startup | // allows an "emergency" shutdown during startup | ||||
m_node.startShutdown(); | shutdown(); | ||||
event->ignore(); | event->ignore(); | ||||
} | } |