From f0d971fc2a8bb21b24a30f21b4b5912b653a59bb Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 31 Dec 2021 01:53:46 -0800 Subject: [PATCH] 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. --- win/Qt/qt_bind.cpp | 96 +++++++++++++++++++++++++--------------------- win/Qt/qt_bind.h | 1 + 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index 047368ac2..5f6a193fe 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -77,49 +77,9 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) : QApplication(argc,argv) #endif { - QPixmap pm("nhsplash.xpm"); - if ( iflags.wc_splash_screen && !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); - 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; - } + splash = 0; + if (iflags.wc_splash_screen) + NetHackQtBind::qt_Splash(); // show something while starting up // these used to be in MainWindow but we want them before QtSettings // which we want before MainWindow... @@ -128,7 +88,7 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) : QCoreApplication::setApplicationName("NetHack-Qt"); // Qt NetHack { char cvers[BUFSZ]; - QString qvers = version_string(cvers); + QString qvers = QString(::version_string(cvers)); QCoreApplication::setApplicationVersion(qvers); } #ifdef MACOS @@ -146,6 +106,54 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) : 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) { iflags.menu_tab_sep = true; diff --git a/win/Qt/qt_bind.h b/win/Qt/qt_bind.h index aff4170b6..f00f86440 100644 --- a/win/Qt/qt_bind.h +++ b/win/Qt/qt_bind.h @@ -35,6 +35,7 @@ private: static NetHackQtMainWindow* main; public: + static void qt_Splash(); static void qt_init_nhwindows(int* argc, char** argv); static void qt_player_selection(); static void qt_askname();