qt: Change splash screen to normal window
Makes it possible to move, minimize, unminimize the window while Bitcoin Core is initializing.
This commit is contained in:
parent
7fd8813675
commit
a49f11d9ed
3 changed files with 58 additions and 19 deletions
|
@ -338,8 +338,7 @@ void BitcoinApplication::createWindow(bool isaTestNet)
|
||||||
|
|
||||||
void BitcoinApplication::createSplashScreen(bool isaTestNet)
|
void BitcoinApplication::createSplashScreen(bool isaTestNet)
|
||||||
{
|
{
|
||||||
SplashScreen *splash = new SplashScreen(QPixmap(), 0, isaTestNet);
|
SplashScreen *splash = new SplashScreen(0, isaTestNet);
|
||||||
splash->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
splash->show();
|
splash->show();
|
||||||
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
|
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
|
||||||
}
|
}
|
||||||
|
@ -423,8 +422,6 @@ void BitcoinApplication::initializeResult(int retval)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
emit splashFinished(window);
|
|
||||||
|
|
||||||
// If -min option passed, start window minimized.
|
// If -min option passed, start window minimized.
|
||||||
if(GetBoolArg("-min", false))
|
if(GetBoolArg("-min", false))
|
||||||
{
|
{
|
||||||
|
@ -434,6 +431,8 @@ void BitcoinApplication::initializeResult(int retval)
|
||||||
{
|
{
|
||||||
window->show();
|
window->show();
|
||||||
}
|
}
|
||||||
|
emit splashFinished(window);
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
// Now that initialization/startup is done, process any command-line
|
// Now that initialization/startup is done, process any command-line
|
||||||
// bitcoin: URIs or payment requests:
|
// bitcoin: URIs or payment requests:
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
|
SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
|
||||||
QSplashScreen(pixmap, f)
|
QWidget(0, f), curAlignment(0)
|
||||||
{
|
{
|
||||||
setAutoFillBackground(true);
|
//setAutoFillBackground(true);
|
||||||
|
|
||||||
// set reference point, paddings
|
// set reference point, paddings
|
||||||
int paddingRight = 50;
|
int paddingRight = 50;
|
||||||
|
@ -38,15 +39,14 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
|
||||||
QString font = "Arial";
|
QString font = "Arial";
|
||||||
|
|
||||||
// load the bitmap for writing some text over it
|
// load the bitmap for writing some text over it
|
||||||
QPixmap newPixmap;
|
|
||||||
if(isTestNet) {
|
if(isTestNet) {
|
||||||
newPixmap = QPixmap(":/images/splash_testnet");
|
pixmap = QPixmap(":/images/splash_testnet");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newPixmap = QPixmap(":/images/splash");
|
pixmap = QPixmap(":/images/splash");
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainter pixPaint(&newPixmap);
|
QPainter pixPaint(&pixmap);
|
||||||
pixPaint.setPen(QColor(100,100,100));
|
pixPaint.setPen(QColor(100,100,100));
|
||||||
|
|
||||||
// check font size and drawing with
|
// check font size and drawing with
|
||||||
|
@ -61,7 +61,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
|
||||||
pixPaint.setFont(QFont(font, 33*fontFactor));
|
pixPaint.setFont(QFont(font, 33*fontFactor));
|
||||||
fm = pixPaint.fontMetrics();
|
fm = pixPaint.fontMetrics();
|
||||||
titleTextWidth = fm.width(titleText);
|
titleTextWidth = fm.width(titleText);
|
||||||
pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);
|
pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);
|
||||||
|
|
||||||
pixPaint.setFont(QFont(font, 15*fontFactor));
|
pixPaint.setFont(QFont(font, 15*fontFactor));
|
||||||
|
|
||||||
|
@ -72,11 +72,11 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
|
||||||
pixPaint.setFont(QFont(font, 10*fontFactor));
|
pixPaint.setFont(QFont(font, 10*fontFactor));
|
||||||
titleVersionVSpace -= 5;
|
titleVersionVSpace -= 5;
|
||||||
}
|
}
|
||||||
pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
|
pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
|
||||||
|
|
||||||
// draw copyright stuff
|
// draw copyright stuff
|
||||||
pixPaint.setFont(QFont(font, 10*fontFactor));
|
pixPaint.setFont(QFont(font, 10*fontFactor));
|
||||||
pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
|
pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
|
||||||
|
|
||||||
// draw testnet string if testnet is on
|
// draw testnet string if testnet is on
|
||||||
if(isTestNet) {
|
if(isTestNet) {
|
||||||
|
@ -85,12 +85,22 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
|
||||||
pixPaint.setFont(boldFont);
|
pixPaint.setFont(boldFont);
|
||||||
fm = pixPaint.fontMetrics();
|
fm = pixPaint.fontMetrics();
|
||||||
int testnetAddTextWidth = fm.width(testnetAddText);
|
int testnetAddTextWidth = fm.width(testnetAddText);
|
||||||
pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
|
pixPaint.drawText(pixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixPaint.end();
|
pixPaint.end();
|
||||||
|
|
||||||
this->setPixmap(newPixmap);
|
// Set window title
|
||||||
|
if(isTestNet)
|
||||||
|
setWindowTitle(titleText + " " + testnetAddText);
|
||||||
|
else
|
||||||
|
setWindowTitle(titleText);
|
||||||
|
|
||||||
|
// 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();
|
subscribeToCoreSignals();
|
||||||
}
|
}
|
||||||
|
@ -102,7 +112,8 @@ SplashScreen::~SplashScreen()
|
||||||
|
|
||||||
void SplashScreen::slotFinish(QWidget *mainWin)
|
void SplashScreen::slotFinish(QWidget *mainWin)
|
||||||
{
|
{
|
||||||
finish(mainWin);
|
hide();
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitMessage(SplashScreen *splash, const std::string &message)
|
static void InitMessage(SplashScreen *splash, const std::string &message)
|
||||||
|
@ -146,3 +157,21 @@ void SplashScreen::unsubscribeFromCoreSignals()
|
||||||
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,23 +9,34 @@
|
||||||
|
|
||||||
/** class for the splashscreen with information of the running client
|
/** class for the splashscreen with information of the running client
|
||||||
*/
|
*/
|
||||||
class SplashScreen : public QSplashScreen
|
class SplashScreen : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet);
|
explicit SplashScreen(Qt::WindowFlags f, bool isTestNet);
|
||||||
~SplashScreen();
|
~SplashScreen();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/** Slot to call finish() method as it's not defined as slot */
|
/** Slot to call finish() method as it's not defined as slot */
|
||||||
void slotFinish(QWidget *mainWin);
|
void slotFinish(QWidget *mainWin);
|
||||||
|
|
||||||
|
/** Show message and progress */
|
||||||
|
void showMessage(const QString &message, int alignment, const QColor &color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Connect core signals to splash screen */
|
/** Connect core signals to splash screen */
|
||||||
void subscribeToCoreSignals();
|
void subscribeToCoreSignals();
|
||||||
/** Disconnect core signals to splash screen */
|
/** Disconnect core signals to splash screen */
|
||||||
void unsubscribeFromCoreSignals();
|
void unsubscribeFromCoreSignals();
|
||||||
|
|
||||||
|
QPixmap pixmap;
|
||||||
|
QString curMessage;
|
||||||
|
QColor curColor;
|
||||||
|
int curAlignment;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPLASHSCREEN_H
|
#endif // SPLASHSCREEN_H
|
||||||
|
|
Loading…
Reference in a new issue