You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

splashscreen.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright (c) 2011-2014 The Bitcoin developers
  2. // Distributed under the MIT/X11 software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "splashscreen.h"
  5. #include "clientversion.h"
  6. #include "init.h"
  7. #include "ui_interface.h"
  8. #include "util.h"
  9. #include "version.h"
  10. #ifdef ENABLE_WALLET
  11. #include "wallet.h"
  12. #endif
  13. #include <QApplication>
  14. #include <QPainter>
  15. SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
  16. QSplashScreen(pixmap, f)
  17. {
  18. setAutoFillBackground(true);
  19. // set reference point, paddings
  20. int paddingRight = 50;
  21. int paddingTop = 50;
  22. int titleVersionVSpace = 17;
  23. int titleCopyrightVSpace = 40;
  24. float fontFactor = 1.0;
  25. // define text to place
  26. QString titleText = tr("Bitcoin Core");
  27. QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
  28. QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers"));
  29. QString testnetAddText = QString(tr("[testnet]")); // define text to place as single text object
  30. QString font = "Arial";
  31. // load the bitmap for writing some text over it
  32. QPixmap newPixmap;
  33. if(isTestNet) {
  34. newPixmap = QPixmap(":/images/splash_testnet");
  35. }
  36. else {
  37. newPixmap = QPixmap(":/images/splash");
  38. }
  39. QPainter pixPaint(&newPixmap);
  40. pixPaint.setPen(QColor(100,100,100));
  41. // check font size and drawing with
  42. pixPaint.setFont(QFont(font, 33*fontFactor));
  43. QFontMetrics fm = pixPaint.fontMetrics();
  44. int titleTextWidth = fm.width(titleText);
  45. if(titleTextWidth > 160) {
  46. // strange font rendering, Arial probably not found
  47. fontFactor = 0.75;
  48. }
  49. pixPaint.setFont(QFont(font, 33*fontFactor));
  50. fm = pixPaint.fontMetrics();
  51. titleTextWidth = fm.width(titleText);
  52. pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);
  53. pixPaint.setFont(QFont(font, 15*fontFactor));
  54. // if the version string is to long, reduce size
  55. fm = pixPaint.fontMetrics();
  56. int versionTextWidth = fm.width(versionText);
  57. if(versionTextWidth > titleTextWidth+paddingRight-10) {
  58. pixPaint.setFont(QFont(font, 10*fontFactor));
  59. titleVersionVSpace -= 5;
  60. }
  61. pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
  62. // draw copyright stuff
  63. pixPaint.setFont(QFont(font, 10*fontFactor));
  64. pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
  65. // draw testnet string if testnet is on
  66. if(isTestNet) {
  67. QFont boldFont = QFont(font, 10*fontFactor);
  68. boldFont.setWeight(QFont::Bold);
  69. pixPaint.setFont(boldFont);
  70. fm = pixPaint.fontMetrics();
  71. int testnetAddTextWidth = fm.width(testnetAddText);
  72. pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
  73. }
  74. pixPaint.end();
  75. this->setPixmap(newPixmap);
  76. subscribeToCoreSignals();
  77. }
  78. SplashScreen::~SplashScreen()
  79. {
  80. unsubscribeFromCoreSignals();
  81. }
  82. void SplashScreen::slotFinish(QWidget *mainWin)
  83. {
  84. finish(mainWin);
  85. }
  86. static void InitMessage(SplashScreen *splash, const std::string &message)
  87. {
  88. QMetaObject::invokeMethod(splash, "showMessage",
  89. Qt::QueuedConnection,
  90. Q_ARG(QString, QString::fromStdString(message)),
  91. Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter),
  92. Q_ARG(QColor, QColor(55,55,55)));
  93. }
  94. static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
  95. {
  96. InitMessage(splash, title + strprintf("%d", nProgress) + "%");
  97. }
  98. #ifdef ENABLE_WALLET
  99. static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
  100. {
  101. wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
  102. }
  103. #endif
  104. void SplashScreen::subscribeToCoreSignals()
  105. {
  106. // Connect signals to client
  107. uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
  108. uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
  109. #ifdef ENABLE_WALLET
  110. uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
  111. #endif
  112. }
  113. void SplashScreen::unsubscribeFromCoreSignals()
  114. {
  115. // Disconnect signals from client
  116. uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
  117. uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
  118. #ifdef ENABLE_WALLET
  119. if(pwalletMain)
  120. pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
  121. #endif
  122. }