Qt splash code

Move the handling for the Qt interface's splash window into its own
routine to unclutter the constructor for QtBind.  Also, don't load
nhsplash.xpm if OPTIONS=!splash has been specified.
This commit is contained in:
PatR
2021-12-31 01:53:46 -08:00
parent 5ac71e66d5
commit f0d971fc2a
2 changed files with 53 additions and 44 deletions

View File

@@ -77,49 +77,9 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
QApplication(argc,argv) QApplication(argc,argv)
#endif #endif
{ {
QPixmap pm("nhsplash.xpm"); splash = 0;
if ( iflags.wc_splash_screen && !pm.isNull() ) { if (iflags.wc_splash_screen)
splash = new QFrame(NULL, (Qt::FramelessWindowHint NetHackQtBind::qt_Splash(); // show something while starting up
| Qt::X11BypassWindowManagerHint
| Qt::WindowStaysOnTopHint));
QVBoxLayout *vb = new QVBoxLayout(splash);
QLabel *lsplash = new QLabel(splash);
vb->addWidget(lsplash);
lsplash->setAlignment(Qt::AlignCenter);
lsplash->setPixmap(pm);
QLabel* capt = new QLabel("Loading...",splash);
vb->addWidget(capt);
capt->setAlignment(Qt::AlignCenter);
if ( !pm.isNull() ) {
lsplash->setFixedSize(pm.size());
lsplash->setMask(QBitmap(pm));
}
#if QT_VERSION < 0x060000
QSize screensize = QApplication::desktop()->size();
#else
QSize screensize = splash->screen()->size();
#endif
splash->move((screensize.width()-pm.width())/2,
(screensize.height()-pm.height())/2);
//splash->setGeometry(0,0,100,100);
if ( qt_compact_mode ) {
splash->showMaximized();
} else {
splash->setFrameStyle(QFrame::WinPanel|QFrame::Raised);
splash->setLineWidth(10);
splash->adjustSize();
splash->show();
}
// force content refresh outside event loop
splash->repaint();
lsplash->repaint();
capt->repaint();
qApp->processEvents();
} else {
splash = 0;
}
// these used to be in MainWindow but we want them before QtSettings // these used to be in MainWindow but we want them before QtSettings
// which we want before MainWindow... // which we want before MainWindow...
@@ -128,7 +88,7 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
QCoreApplication::setApplicationName("NetHack-Qt"); // Qt NetHack QCoreApplication::setApplicationName("NetHack-Qt"); // Qt NetHack
{ {
char cvers[BUFSZ]; char cvers[BUFSZ];
QString qvers = version_string(cvers); QString qvers = QString(::version_string(cvers));
QCoreApplication::setApplicationVersion(qvers); QCoreApplication::setApplicationVersion(qvers);
} }
#ifdef MACOS #ifdef MACOS
@@ -146,6 +106,54 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
msgs_saved = false; msgs_saved = false;
} }
// before the game windows have been rendered, display a small, centered
// window showing a red dragon with caption "Loading..."
void
NetHackQtBind::qt_Splash()
{
QPixmap pm("nhsplash.xpm"); // load splash image from a file in HACKDIR
if (!pm.isNull()) {
splash = new QFrame(NULL, (Qt::FramelessWindowHint
| Qt::X11BypassWindowManagerHint
| Qt::WindowStaysOnTopHint));
QVBoxLayout *vb = new QVBoxLayout(splash);
QLabel *lsplash = new QLabel(splash);
vb->addWidget(lsplash);
lsplash->setAlignment(Qt::AlignCenter);
lsplash->setPixmap(pm);
QLabel *capt = new QLabel("Loading...", splash);
vb->addWidget(capt);
capt->setAlignment(Qt::AlignCenter);
lsplash->setFixedSize(pm.size());
lsplash->setMask(QBitmap(pm));
#if QT_VERSION < 0x060000
QSize screensize = QApplication::desktop()->size();
#else
QSize screensize = splash->screen()->size();
#endif
splash->move((screensize.width() - pm.width()) / 2,
(screensize.height() - pm.height()) / 2);
//splash->setGeometry(0,0,100,100);
if (qt_compact_mode) {
splash->showMaximized();
} else {
splash->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
splash->setLineWidth(10);
splash->adjustSize();
splash->show();
}
// force content refresh outside event loop
splash->repaint();
lsplash->repaint();
capt->repaint();
qApp->processEvents();
} else {
splash = 0; // caller has alrady done this...
}
}
void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv) void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv)
{ {
iflags.menu_tab_sep = true; iflags.menu_tab_sep = true;

View File

@@ -35,6 +35,7 @@ private:
static NetHackQtMainWindow* main; static NetHackQtMainWindow* main;
public: public:
static void qt_Splash();
static void qt_init_nhwindows(int* argc, char** argv); static void qt_init_nhwindows(int* argc, char** argv);
static void qt_player_selection(); static void qt_player_selection();
static void qt_askname(); static void qt_askname();