aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/bitcoin.cpp8
-rw-r--r--src/qt/splashscreen.cpp60
-rw-r--r--src/qt/splashscreen.h22
-rw-r--r--src/qt/utilitydialog.cpp26
-rw-r--r--src/qt/utilitydialog.h6
5 files changed, 96 insertions, 26 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index d9ca423015..bd686041c1 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -341,7 +341,9 @@ void BitcoinApplication::createWindow(bool isaTestNet)
void BitcoinApplication::createSplashScreen(bool isaTestNet)
{
- SplashScreen *splash = new SplashScreen(QPixmap(), 0, isaTestNet);
+ SplashScreen *splash = new SplashScreen(0, isaTestNet);
+ // We don't hold a direct pointer to the splash screen after creation, so use
+ // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
splash->setAttribute(Qt::WA_DeleteOnClose);
splash->show();
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
@@ -426,8 +428,6 @@ void BitcoinApplication::initializeResult(int retval)
}
#endif
- emit splashFinished(window);
-
// If -min option passed, start window minimized.
if(GetBoolArg("-min", false))
{
@@ -437,6 +437,8 @@ void BitcoinApplication::initializeResult(int retval)
{
window->show();
}
+ emit splashFinished(window);
+
#ifdef ENABLE_WALLET
// Now that initialization/startup is done, process any command-line
// bitcoin: URIs or payment requests:
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index feb0f3350f..673e984691 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -15,12 +15,14 @@
#endif
#include <QApplication>
+#include <QCloseEvent>
+#include <QDesktopWidget>
#include <QPainter>
-SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
- QSplashScreen(pixmap, f)
+SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
+ QWidget(0, f), curAlignment(0)
{
- setAutoFillBackground(true);
+ //setAutoFillBackground(true);
// set reference point, paddings
int paddingRight = 50;
@@ -39,15 +41,14 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
QString font = "Arial";
// load the bitmap for writing some text over it
- QPixmap newPixmap;
if(isTestNet) {
- newPixmap = QPixmap(":/images/splash_testnet");
+ pixmap = QPixmap(":/images/splash_testnet");
}
else {
- newPixmap = QPixmap(":/images/splash");
+ pixmap = QPixmap(":/images/splash");
}
- QPainter pixPaint(&newPixmap);
+ QPainter pixPaint(&pixmap);
pixPaint.setPen(QColor(100,100,100));
// check font size and drawing with
@@ -62,7 +63,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
pixPaint.setFont(QFont(font, 33*fontFactor));
fm = pixPaint.fontMetrics();
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));
@@ -73,11 +74,11 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
pixPaint.setFont(QFont(font, 10*fontFactor));
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
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
if(isTestNet) {
@@ -86,12 +87,22 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTest
pixPaint.setFont(boldFont);
fm = pixPaint.fontMetrics();
int testnetAddTextWidth = fm.width(testnetAddText);
- pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
+ pixPaint.drawText(pixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
}
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();
}
@@ -103,7 +114,7 @@ SplashScreen::~SplashScreen()
void SplashScreen::slotFinish(QWidget *mainWin)
{
- finish(mainWin);
+ hide();
}
static void InitMessage(SplashScreen *splash, const std::string &message)
@@ -147,3 +158,26 @@ void SplashScreen::unsubscribeFromCoreSignals()
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)
+{
+ event->ignore();
+}
+
diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h
index d79038d81d..89c21e6457 100644
--- a/src/qt/splashscreen.h
+++ b/src/qt/splashscreen.h
@@ -7,25 +7,41 @@
#include <QSplashScreen>
-/** class for the splashscreen with information of the running client
+/** Class for the splashscreen with information of the running client.
+ *
+ * @note this is intentionally not a QSplashScreen. Bitcoin Core initialization
+ * can take a long time, and in that case a progress window that cannot be
+ * moved around and minimized has turned out to be frustrating to the user.
*/
-class SplashScreen : public QSplashScreen
+class SplashScreen : public QWidget
{
Q_OBJECT
public:
- explicit SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet);
+ explicit SplashScreen(Qt::WindowFlags f, bool isTestNet);
~SplashScreen();
+protected:
+ void paintEvent(QPaintEvent *event);
+ void closeEvent(QCloseEvent *event);
+
public slots:
/** Slot to call finish() method as it's not defined as slot */
void slotFinish(QWidget *mainWin);
+ /** Show message and progress */
+ void showMessage(const QString &message, int alignment, const QColor &color);
+
private:
/** Connect core signals to splash screen */
void subscribeToCoreSignals();
/** Disconnect core signals to splash screen */
void unsubscribeFromCoreSignals();
+
+ QPixmap pixmap;
+ QString curMessage;
+ QColor curColor;
+ int curAlignment;
};
#endif // SPLASHSCREEN_H
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index 7df9d1bc2d..84f88dff5a 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -15,6 +15,7 @@
#include <stdio.h>
+#include <QCloseEvent>
#include <QLabel>
#include <QRegExp>
#include <QVBoxLayout>
@@ -106,18 +107,26 @@ void HelpMessageDialog::on_okButton_accepted()
/** "Shutdown" window */
+ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
+ QWidget(parent, f)
+{
+ QVBoxLayout *layout = new QVBoxLayout();
+ layout->addWidget(new QLabel(
+ tr("Bitcoin Core is shutting down...") + "<br /><br />" +
+ tr("Do not shut down the computer until this window disappears.")));
+ setLayout(layout);
+}
+
void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
{
if (!window)
return;
// Show a simple window indicating shutdown status
- QWidget *shutdownWindow = new QWidget();
- QVBoxLayout *layout = new QVBoxLayout();
- layout->addWidget(new QLabel(
- tr("Bitcoin Core is shutting down...") + "<br /><br />" +
- tr("Do not shut down the computer until this window disappears.")));
- shutdownWindow->setLayout(layout);
+ QWidget *shutdownWindow = new ShutdownWindow();
+ // We don't hold a direct pointer to the shutdown window after creation, so use
+ // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
+ shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
shutdownWindow->setWindowTitle(window->windowTitle());
// Center shutdown window at where main window was
@@ -125,3 +134,8 @@ void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
shutdownWindow->show();
}
+
+void ShutdownWindow::closeEvent(QCloseEvent *event)
+{
+ event->ignore();
+}
diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h
index 154bb70b8b..ae5045cca9 100644
--- a/src/qt/utilitydialog.h
+++ b/src/qt/utilitydialog.h
@@ -37,12 +37,16 @@ private slots:
/** "Shutdown" window */
-class ShutdownWindow : public QObject
+class ShutdownWindow : public QWidget
{
Q_OBJECT
public:
+ ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0);
static void showShutdownWindow(BitcoinGUI *window);
+
+protected:
+ void closeEvent(QCloseEvent *event);
};
#endif // UTILITYDIALOG_H