neobytes/src/qt/splashscreen.cpp

188 lines
6.0 KiB
C++
Raw Normal View History

// Copyright (c) 2011-2015 The Bitcoin Core developers
2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 The Dash Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "splashscreen.h"
#include "guiutil.h"
#include "networkstyle.h"
#include "clientversion.h"
2014-03-19 00:26:14 +01:00
#include "init.h"
#include "util.h"
#include "ui_interface.h"
#include "version.h"
2014-03-19 00:26:14 +01:00
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
2014-03-19 00:26:14 +01:00
#endif
#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QPainter>
SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0)
{
// transparent background
setAttribute(Qt::WA_TranslucentBackground);
setStyleSheet("background:transparent;");
// no window decorations
setWindowFlags(Qt::FramelessWindowHint);
// set reference point, paddings
int paddingLeft = 14;
int paddingTop = 470;
int titleVersionVSpace = 17;
int titleCopyrightVSpace = 32;
float fontFactor = 1.0;
// define text to place
2015-03-18 00:06:58 +01:00
QString titleText = tr("Dash Core");
2015-02-04 12:00:23 +01:00
QString versionText = QString(tr("Version %1")).arg(QString::fromStdString(FormatFullVersion()));
QString copyrightTextBtc = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers"));
2015-04-03 00:51:08 +02:00
QString copyrightTextDash = QChar(0xA9)+QString(" 2014-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Dash Core developers"));
QString titleAddText = networkStyle->getTitleAddText();
2016-04-20 08:04:46 +02:00
// networkstyle.cpp can't (yet) read themes, so we do it here to get the correct Splash-screen
QString splashScreenPath = ":/images/" + GUIUtil::getThemeName() + "/splash";
if(GetBoolArg("-regtest", false))
splashScreenPath = ":/images/" + GUIUtil::getThemeName() + "/splash_testnet";
if(GetBoolArg("-testnet", false))
splashScreenPath = ":/images/" + GUIUtil::getThemeName() + "/splash_testnet";
QString font = QApplication::font().toString();
// load the bitmap for writing some text over it
2016-04-20 08:04:46 +02:00
pixmap = QPixmap(splashScreenPath);
QPainter pixPaint(&pixmap);
pixPaint.setPen(QColor(100,100,100));
// check font size and drawing with
pixPaint.setFont(QFont(font, 28*fontFactor));
QFontMetrics fm = pixPaint.fontMetrics();
int titleTextWidth = fm.width(titleText);
if(titleTextWidth > 160) {
// strange font rendering, Arial probably not found
fontFactor = 0.75;
}
pixPaint.setFont(QFont(font, 28*fontFactor));
fm = pixPaint.fontMetrics();
titleTextWidth = fm.width(titleText);
pixPaint.drawText(paddingLeft,paddingTop,titleText);
pixPaint.setFont(QFont(font, 15*fontFactor));
pixPaint.drawText(paddingLeft,paddingTop+titleVersionVSpace,versionText);
// draw copyright stuff
pixPaint.setFont(QFont(font, 10*fontFactor));
pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace,copyrightTextBtc);
2015-04-03 00:51:08 +02:00
pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace+12,copyrightTextDash);
// 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 = fm.width(titleAddText);
2015-04-03 00:51:08 +02:00
pixPaint.drawText(pixmap.width()-titleAddTextWidth-10,pixmap.height()-25,titleAddText);
}
pixPaint.end();
// Resize window and move to center of desktop, disallow resizing
QRect r(QPoint(), pixmap.size());
resize(r.size());
setFixedSize(r.size());
move(QApplication::desktop()->screenGeometry().center() - r.center());
subscribeToCoreSignals();
}
SplashScreen::~SplashScreen()
{
unsubscribeFromCoreSignals();
}
void SplashScreen::slotFinish(QWidget *mainWin)
{
Q_UNUSED(mainWin);
Backport Bitcoin Qt/Gui changes up to 0.14.x part 2 (#1615) * Merge #7506: Use CCoinControl selection in CWallet::FundTransaction d6cc6a1 Use CCoinControl selection in CWallet::FundTransaction (João Barbosa) * Merge #7732: [Qt] Debug window: replace "Build date" with "Datadir" fc737d1 [Qt] remove unused formatBuildDate method (Jonas Schnelli) 4856f1d [Qt] Debug window: replace "Build date" with "Datadir" (Jonas Schnelli) * Merge #7707: [RPC][QT] UI support for abandoned transactions 8efed3b [Qt] Support for abandoned/abandoning transactions (Jonas Schnelli) * Merge #7688: List solvability in listunspent output and improve help c3932b3 List solvability in listunspent output and improve help (Pieter Wuille) * Merge #8006: Qt: Add option to disable the system tray icon 8b0e497 Qt: Add option to hide the system tray icon (Tyler Hardin) * Merge #8073: qt: askpassphrasedialog: Clear pass fields on accept 02ce2a3 qt: askpassphrasedialog: Clear pass fields on accept (Pavel Vasin) * Merge #8231: [Qt] fix a bug where the SplashScreen will not be hidden during startup b3e1348 [Qt] fix a bug where the SplashScreen will not be hidden during startup (Jonas Schnelli) * Merge #8257: Do not ask a UI question from bitcoind 1acf1db Do not ask a UI question from bitcoind (Pieter Wuille) * Merge #8463: [qt] Remove Priority from coincontrol dialog fa8dd78 [qt] Remove Priority from coincontrol dialog (MarcoFalke) * Merge #8678: [Qt][CoinControl] fix UI bug that could result in paying unexpected fee 0480293 [Qt][CoinControl] fix UI bug that could result in paying unexpected fee (Jonas Schnelli) * Merge #8672: Qt: Show transaction size in transaction details window c015634 qt: Adding transaction size to transaction details window (Hampus Sjöberg) \-- merge fix for s/size/total size/ fdf82fb Adding method GetTotalSize() to CTransaction (Hampus Sjöberg) * Merge #8371: [Qt] Add out-of-sync modal info layer 08827df [Qt] modalinfolayer: removed unused comments, renamed signal, code style overhaul (Jonas Schnelli) d8b062e [Qt] only update "amount of blocks left" when the header chain is in-sync (Jonas Schnelli) e3245b4 [Qt] add out-of-sync modal info layer (Jonas Schnelli) e47052f [Qt] ClientModel add method to get the height of the header chain (Jonas Schnelli) a001f18 [Qt] Always pass the numBlocksChanged signal for headers tip changed (Jonas Schnelli) bd44a04 [Qt] make Out-Of-Sync warning icon clickable (Jonas Schnelli) 0904c3c [Refactor] refactor function that forms human readable text out of a timeoffset (Jonas Schnelli) * Merge #8805: Trivial: Grammar and capitalization c9ce17b Trivial: Grammar and capitalization (Derek Miller) * Merge #8885: gui: fix ban from qt console cb78c60 gui: fix ban from qt console (Cory Fields) * Merge #8821: [qt] sync-overlay: Don't block during reindex fa85e86 [qt] sync-overlay: Don't show estimated number of headers left (MarcoFalke) faa4de2 [qt] sync-overlay: Don't block during reindex (MarcoFalke) * Support themes for new transaction_abandoned icon * Fix constructor call to COutput * Merge #7842: RPC: do not print minping time in getpeerinfo when no ping received yet 62a6486 RPC: do not print ping info in getpeerinfo when no ping received yet, fix help (Pavel Janík) * Merge #8918: Qt: Add "Copy URI" to payment request context menu 21f5a63 Qt: Add "Copy URI" to payment request context menu (Luke Dashjr) * Merge #8925: qt: Display minimum ping in debug window. 1724a40 Display minimum ping in debug window. (R E Broadley) * Merge #8972: [Qt] make warnings label selectable (jonasschnelli) ef0c9ee [Qt] make warnings label selectable (Jonas Schnelli) * Make background of warning icon transparent in modaloverlay * Merge #9088: Reduce ambiguity of warning message 77cbbd9 Make warning message about wallet balance possibly being incorrect less ambiguous. (R E Broadley) * Replace Bitcoin with Dash in modal overlay * Remove clicked signals from labelWalletStatus and labelTransactionsStatus As both are really just labels, clicking on those is not possible. This is different in Bitcoin, where these labels are actually buttons. * Pull out modaloverlay show/hide into it's own if/else block and switch to time based check Also don't use masternodeSync.IsBlockchainSynced() for now as it won't report the blockchain being synced before the first block (or other MN data?) arrives. This would otherwise give the impression that sync is being stuck.
2017-09-09 09:04:02 +02:00
/* If the window is minimized, hide() will be ignored. */
/* Make sure we de-minimize the splashscreen window before hiding */
if (isMinimized())
showNormal();
hide();
}
static void InitMessage(SplashScreen *splash, const std::string &message)
{
QMetaObject::invokeMethod(splash, "showMessage",
Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdString(message)),
Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter),
Q_ARG(QColor, QColor(55,55,55)));
}
2014-03-19 00:26:14 +01:00
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
{
InitMessage(splash, title + strprintf("%d", nProgress) + "%");
}
#ifdef ENABLE_WALLET
static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
{
wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
}
#endif
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
2014-05-23 18:04:09 +02:00
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
2014-03-19 00:26:14 +01:00
#ifdef ENABLE_WALLET
uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
#endif
}
void SplashScreen::unsubscribeFromCoreSignals()
{
// Disconnect signals from client
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
2014-05-23 18:04:09 +02:00
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
2014-03-19 00:26:14 +01:00
#ifdef ENABLE_WALLET
if(pwalletMain)
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
#endif
}
void SplashScreen::showMessage(const QString &message, int alignment, const QColor &color)
{
curMessage = message;
curAlignment = alignment;
curColor = color;
update();
}
void SplashScreen::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(0, 0, pixmap);
QRect r = rect().adjusted(5, 5, -5, -5);
painter.setPen(curColor);
painter.drawText(r, curAlignment, curMessage);
}
void SplashScreen::closeEvent(QCloseEvent *event)
{
StartShutdown(); // allows an "emergency" shutdown during startup
event->ignore();
}