Anoncoin  0.9.4
P2P Digital Currency
splashscreen.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2013-2015 The Anoncoin Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 // Many builder specific things set in the config file, ENABLE_WALLET is a good example. Don't forget to include it this way in your source files.
7 #if defined(HAVE_CONFIG_H)
9 #endif
10 
11 #include "splashscreen.h"
12 
13 #include "clientversion.h"
14 #include "init.h"
15 #include "ui_interface.h"
16 #include "util.h"
17 #ifdef ENABLE_WALLET
18 #include "wallet.h"
19 #endif
20 
21 #include <QApplication>
22 #include <QPainter>
23 
24 SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
25  QSplashScreen(pixmap, f)
26 {
27  setAutoFillBackground(true);
28 
29  // set reference point, paddings
30  int paddingTop = 236;
31  int paddingCopyrightTop = 18;
32 
33  // define text to place
34  QString versionText = QString("VERSION %1").arg(QString::fromStdString(FormatFullVersion()));
35  QString copyrightText1 = QChar(0xA9)+QString(" 2013-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("ANONCOIN CORE DEVELOPERS"));
36  //QString testnetAddText = QString(tr("[testnet]")); // This string is already included in the background image
37 
38  // load the bitmap for writing some text over it
39  QPixmap newPixmap;
40  if(isTestNet) {
41  newPixmap = QPixmap(":/images/splash_testnet");
42  }
43  else {
44  newPixmap = QPixmap(":/images/splash");
45  }
46 
47  QFont initfont;
48  initfont.setFamily("Courier New,Courier,Monaco,Andale Mono,Arial");
49  initfont.setPixelSize(12);
50 
51  QPainter pixPaint(&newPixmap);
52  pixPaint.setPen(QColor(250,250,250));
53  pixPaint.setFont(initfont);
54 
55  QFontMetrics fm = pixPaint.fontMetrics();
56 
57  // draw version
58  pixPaint.drawText(newPixmap.width()/2-fm.width(versionText)/2,paddingTop,versionText);
59 
60  // draw copyright stuff
61  pixPaint.setFont(initfont);
62  pixPaint.drawText(newPixmap.width()/2-fm.width(copyrightText1)/2,paddingTop+paddingCopyrightTop,copyrightText1);
63 
64  // draw testnet string if testnet is on. This is no longer necessary as this is included in the background image
65  //if(isTestNet) {
66  // QFont boldFont = QFont(font, 10);
67  // boldFont.setWeight(QFont::Bold);
68  // pixPaint.setFont(boldFont);
69  // fm = pixPaint.fontMetrics();
70  // int testnetAddTextWidth = fm.width(testnetAddText);
71  // pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
72  //}
73 
74  pixPaint.end();
75 
76  this->setPixmap(newPixmap);
77 
79 }
80 
82 {
84 }
85 
86 void SplashScreen::slotFinish(QWidget *mainWin)
87 {
88  finish(mainWin);
89 }
90 
91 static void InitMessage(SplashScreen *splash, const std::string &message)
92 {
93  QFont initfont;
94  initfont.setFamily("Courier New,Courier,Monaco,Andale Mono,Arial");
95  initfont.setPixelSize(12);
96  initfont.setCapitalization(initfont.AllUppercase);
97  splash->setFont(initfont);
98 
99  std::string message_cr;
100  message_cr = message + "\n";
101 
102  QMetaObject::invokeMethod(splash, "showMessage",
103  Qt::QueuedConnection,
104  Q_ARG(QString, QString::fromStdString(message_cr)),
105  Q_ARG(int, Qt::AlignBottom|Qt::AlignHCenter),
106  Q_ARG(QColor, QColor(0,0,0)));
107 }
108 
109 static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
110 {
111  InitMessage(splash, title + strprintf("%d", nProgress) + "%");
112 }
113 
114 #ifdef ENABLE_WALLET
115 static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
116 {
117  wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
118 }
119 #endif
120 
122 {
123  // Connect signals to client
124  uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
125 #ifdef ENABLE_WALLET
126  uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
127 #endif
128 }
129 
131 {
132  // Disconnect signals from client
133  uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
134 #ifdef ENABLE_WALLET
135  if(pwalletMain)
136  pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
137 #endif
138 }
CClientUIInterface uiInterface
Definition: util.cpp:100
void unsubscribeFromCoreSignals()
Disconnect core signals to splash screen.
class for the splashscreen with information of the running client
Definition: splashscreen.h:13
#define strprintf
Definition: tinyformat.h:1011
void subscribeToCoreSignals()
Connect core signals to splash screen.
SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet)
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
A wallet has been loaded.
Definition: ui_interface.h:102
#define COPYRIGHT_YEAR
Copyright year (2013-this) Todo: update this when changing our copyright comments in the source...
Definition: clientversion.h:36
std::string FormatFullVersion()
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it's not defined as slot.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:101
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:408
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
Definition: ui_interface.h:84
CWallet * pwalletMain