Browse Source

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.
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
cfc5cfb0f0
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 3
      src/qt/bitcoin.cpp
  2. 9
      src/qt/splashscreen.cpp
  3. 7
      src/qt/splashscreen.h
  4. 26
      src/qt/utilitydialog.cpp
  5. 6
      src/qt/utilitydialog.h

3
src/qt/bitcoin.cpp

@ -339,6 +339,9 @@ void BitcoinApplication::createWindow(bool isaTestNet)
void BitcoinApplication::createSplashScreen(bool isaTestNet) void BitcoinApplication::createSplashScreen(bool isaTestNet)
{ {
SplashScreen *splash = new SplashScreen(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(); splash->show();
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*))); connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
} }

9
src/qt/splashscreen.cpp

@ -14,8 +14,9 @@
#endif #endif
#include <QApplication> #include <QApplication>
#include <QPainter> #include <QCloseEvent>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QPainter>
SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) : SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
QWidget(0, f), curAlignment(0) QWidget(0, f), curAlignment(0)
@ -113,7 +114,6 @@ SplashScreen::~SplashScreen()
void SplashScreen::slotFinish(QWidget *mainWin) void SplashScreen::slotFinish(QWidget *mainWin)
{ {
hide(); hide();
deleteLater();
} }
static void InitMessage(SplashScreen *splash, const std::string &message) static void InitMessage(SplashScreen *splash, const std::string &message)
@ -175,3 +175,8 @@ void SplashScreen::paintEvent(QPaintEvent *event)
painter.drawText(r, curAlignment, curMessage); painter.drawText(r, curAlignment, curMessage);
} }
void SplashScreen::closeEvent(QCloseEvent *event)
{
event->ignore();
}

7
src/qt/splashscreen.h

@ -7,7 +7,11 @@
#include <QSplashScreen> #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 class SplashScreen : public QWidget
{ {
@ -19,6 +23,7 @@ public:
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void closeEvent(QCloseEvent *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 */

26
src/qt/utilitydialog.cpp

@ -15,6 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <QCloseEvent>
#include <QLabel> #include <QLabel>
#include <QRegExp> #include <QRegExp>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -106,18 +107,26 @@ void HelpMessageDialog::on_okButton_accepted()
/** "Shutdown" window */ /** "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) void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
{ {
if (!window) if (!window)
return; return;
// Show a simple window indicating shutdown status // Show a simple window indicating shutdown status
QWidget *shutdownWindow = new QWidget(); QWidget *shutdownWindow = new ShutdownWindow();
QVBoxLayout *layout = new QVBoxLayout(); // We don't hold a direct pointer to the shutdown window after creation, so use
layout->addWidget(new QLabel( // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
tr("Bitcoin Core is shutting down...") + "<br /><br />" + shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
tr("Do not shut down the computer until this window disappears.")));
shutdownWindow->setLayout(layout);
shutdownWindow->setWindowTitle(window->windowTitle()); shutdownWindow->setWindowTitle(window->windowTitle());
// Center shutdown window at where main window was // 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->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
shutdownWindow->show(); shutdownWindow->show();
} }
void ShutdownWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
}

6
src/qt/utilitydialog.h

@ -37,12 +37,16 @@ private slots:
/** "Shutdown" window */ /** "Shutdown" window */
class ShutdownWindow : public QObject class ShutdownWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0);
static void showShutdownWindow(BitcoinGUI *window); static void showShutdownWindow(BitcoinGUI *window);
protected:
void closeEvent(QCloseEvent *event);
}; };
#endif // UTILITYDIALOG_H #endif // UTILITYDIALOG_H

Loading…
Cancel
Save