aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-09-22 10:08:47 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-09-22 10:13:52 +0200
commitcfc5cfb0f0d074774b17adcb88aaed11e6847c92 (patch)
treee2e45db192bc450888caadb3ab2241f10404f30c /src
parent6b09bc45b12465dc8511f1e84791e3b4db5400b8 (diff)
qt: Make splash and shutdown window ignore close events
It's strange to be able to close these windows while there is work in progress. Also set Qt::WA_DeleteOnClose on both windows to make sure that they are deleted eventually, no matter what happens.
Diffstat (limited to 'src')
-rw-r--r--src/qt/bitcoin.cpp3
-rw-r--r--src/qt/splashscreen.cpp9
-rw-r--r--src/qt/splashscreen.h9
-rw-r--r--src/qt/utilitydialog.cpp26
-rw-r--r--src/qt/utilitydialog.h6
5 files changed, 42 insertions, 11 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 676f218f20..fd629ccd2c 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -339,6 +339,9 @@ void BitcoinApplication::createWindow(bool isaTestNet)
void BitcoinApplication::createSplashScreen(bool 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*)));
}
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index b6443d47ff..382f0e67b6 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -14,8 +14,9 @@
#endif
#include <QApplication>
-#include <QPainter>
+#include <QCloseEvent>
#include <QDesktopWidget>
+#include <QPainter>
SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
QWidget(0, f), curAlignment(0)
@@ -113,7 +114,6 @@ SplashScreen::~SplashScreen()
void SplashScreen::slotFinish(QWidget *mainWin)
{
hide();
- deleteLater();
}
static void InitMessage(SplashScreen *splash, const std::string &message)
@@ -175,3 +175,8 @@ void SplashScreen::paintEvent(QPaintEvent *event)
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 1151d6c111..89c21e6457 100644
--- a/src/qt/splashscreen.h
+++ b/src/qt/splashscreen.h
@@ -7,7 +7,11 @@
#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 QWidget
{
@@ -18,7 +22,8 @@ public:
~SplashScreen();
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void closeEvent(QCloseEvent *event);
public slots:
/** Slot to call finish() method as it's not defined as slot */
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