From cb5bb3446d29d53acf1eea5387b95b50d9150471 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 16 Jan 2022 11:12:13 -0500 Subject: [PATCH] Made custom Qt GUI splashscreen that fades out when initialization is finished. Showing splash screen at startup is now a configuration parameter and defaults to off. Can be turned on in GUI config dialog. --- src/CMakeLists.txt | 1 + src/drivers/Qt/GuiConf.cpp | 14 ++++++++ src/drivers/Qt/GuiConf.h | 2 ++ src/drivers/Qt/SplashScreen.cpp | 60 +++++++++++++++++++++++++++++++++ src/drivers/Qt/SplashScreen.h | 28 +++++++++++++++ src/drivers/Qt/main.cpp | 45 +++++++++++++++---------- 6 files changed, 132 insertions(+), 18 deletions(-) create mode 100644 src/drivers/Qt/SplashScreen.cpp create mode 100644 src/drivers/Qt/SplashScreen.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 113aa82e..4144feb8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -513,6 +513,7 @@ set(SRC_DRIVERS_SDL ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/iNesHeaderEditor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/SplashScreen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/TraceLogger.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/AboutWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/fceuWrapper.cpp diff --git a/src/drivers/Qt/GuiConf.cpp b/src/drivers/Qt/GuiConf.cpp index 22b9ba5c..f2318eff 100644 --- a/src/drivers/Qt/GuiConf.cpp +++ b/src/drivers/Qt/GuiConf.cpp @@ -63,6 +63,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent) QGroupBox *frame, *qssFrame; QFrame *hline; std::string qssFile, qpalFile; + QSettings settings; //resize( 512, 600 ); //printf("Style: %s \n", style()->objectName().toStdString().c_str() ); @@ -128,16 +129,19 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent) useNativeMenuBar = new QCheckBox(tr("Use Native OS Menu Bar")); pauseOnMenuAccess = new QCheckBox(tr("Pause On Main Menu Access")); ctxMenuEnable = new QCheckBox(tr("Context Menu Enable")); + showSplashScreen = new QCheckBox(tr("Show Splash Screen at Startup")); useNativeFileDialog->setChecked(useNativeFileDialogVal); useNativeMenuBar->setChecked(useNativeMenuBarVal); pauseOnMenuAccess->setChecked(pauseOnMenuAccessVal); ctxMenuEnable->setChecked(contextMenuEnable); + showSplashScreen->setChecked( settings.value("mainWindow/showSplashScreen", false).toBool() ); connect(useNativeFileDialog, SIGNAL(stateChanged(int)), this, SLOT(useNativeFileDialogChanged(int))); connect(useNativeMenuBar , SIGNAL(stateChanged(int)), this, SLOT(useNativeMenuBarChanged(int))); connect(pauseOnMenuAccess , SIGNAL(stateChanged(int)), this, SLOT(pauseOnMenuAccessChanged(int))); connect(ctxMenuEnable , SIGNAL(stateChanged(int)), this, SLOT(contextMenuEnableChanged(int))); + connect(showSplashScreen , SIGNAL(stateChanged(int)), this, SLOT(showSplashScreenChanged(int))); styleComboBox = new QComboBox(); @@ -239,6 +243,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent) vbox1->addWidget(useNativeMenuBar, 1); vbox1->addWidget(pauseOnMenuAccess, 1); vbox1->addWidget(ctxMenuEnable, 1); + vbox1->addWidget(showSplashScreen, 1); vbox1->addStretch(10); closeButton = new QPushButton( tr("Close") ); @@ -310,6 +315,15 @@ void GuiConfDialog_t::contextMenuEnableChanged(int state) consoleWindow->setContextMenuEnable( value ); } //---------------------------------------------------- +void GuiConfDialog_t::showSplashScreenChanged(int state) +{ + QSettings settings; + bool value = (state == Qt::Unchecked) ? 0 : 1; + + settings.setValue("mainWindow/showSplashScreen", value ); + settings.sync(); +} +//---------------------------------------------------- void GuiConfDialog_t::useCustomStyleChanged(int state) { int value = (state == Qt::Unchecked) ? 0 : 1; diff --git a/src/drivers/Qt/GuiConf.h b/src/drivers/Qt/GuiConf.h index d27affa5..9aa0acbc 100644 --- a/src/drivers/Qt/GuiConf.h +++ b/src/drivers/Qt/GuiConf.h @@ -144,6 +144,7 @@ protected: QCheckBox *useNativeMenuBar; QCheckBox *pauseOnMenuAccess; QCheckBox *ctxMenuEnable; + QCheckBox *showSplashScreen; QCheckBox *useCustomStyle; QCheckBox *useCustomPalette; QComboBox *styleComboBox; @@ -158,6 +159,7 @@ private slots: void useNativeMenuBarChanged(int v); void pauseOnMenuAccessChanged(int v); void contextMenuEnableChanged(int v); + void showSplashScreenChanged(int v); void useCustomQPaletteChanged(int v); void useCustomStyleChanged(int v); void styleChanged(int index); diff --git a/src/drivers/Qt/SplashScreen.cpp b/src/drivers/Qt/SplashScreen.cpp new file mode 100644 index 00000000..31194481 --- /dev/null +++ b/src/drivers/Qt/SplashScreen.cpp @@ -0,0 +1,60 @@ +// SplashScreen.cpp +#include "Qt/SplashScreen.h" + +fceuSplashScreen::fceuSplashScreen(void) + : QSplashScreen( QPixmap(":/fceux1.png") ) +{ + + alpha = 255; + + showMessage("Initializing GUI..."); + updateTimer = new QTimer(this); + + connect(updateTimer, &QTimer::timeout, this, &fceuSplashScreen::periodicUpdate); +} + +fceuSplashScreen::~fceuSplashScreen(void) +{ + //printf("SplashScreen Detroyed\n"); + updateTimer->stop(); +} + +void fceuSplashScreen::closeEvent(QCloseEvent *event) +{ + //printf("Splash CloseEvent\n"); + + if ( alpha > 0 ) + { + if ( !updateTimer->isActive() ) + { + updateTimer->start(33); + } + event->ignore(); + } + else + { + updateTimer->stop(); + QSplashScreen::closeEvent(event); + } +} + +void fceuSplashScreen::periodicUpdate(void) +{ + if ( alpha > 0 ) + { + alpha -= 20; + + if ( alpha < 0 ) + { + alpha = 0; + } + setWindowOpacity( (double)alpha / 255.0 ); + update(); + } + else + { + close(); + deleteLater(); + updateTimer->stop(); + } +} diff --git a/src/drivers/Qt/SplashScreen.h b/src/drivers/Qt/SplashScreen.h new file mode 100644 index 00000000..67cc94a2 --- /dev/null +++ b/src/drivers/Qt/SplashScreen.h @@ -0,0 +1,28 @@ +// SplashScreen.h +// +#pragma once + +#include +#include +#include +#include + +class fceuSplashScreen : public QSplashScreen +{ + Q_OBJECT + + public: + fceuSplashScreen(void); + ~fceuSplashScreen(void); + + protected: + void closeEvent(QCloseEvent *event); + + private: + QTimer *updateTimer; + int alpha; + + private slots: + void periodicUpdate(void); + +}; diff --git a/src/drivers/Qt/main.cpp b/src/drivers/Qt/main.cpp index 5cad1dae..0c2f1f69 100644 --- a/src/drivers/Qt/main.cpp +++ b/src/drivers/Qt/main.cpp @@ -21,10 +21,12 @@ #include #include #include +#include //#include #include "Qt/ConsoleWindow.h" #include "Qt/fceuWrapper.h" +#include "Qt/SplashScreen.h" #ifdef WIN32 #include @@ -81,28 +83,35 @@ static void MessageOutput(QtMsgType type, const QMessageLogContext &context, con #undef main // undef main in case SDL_Main -//#define SPLASH_SCREEN_ENABLE +static bool showSplashScreen(void) +{ + bool show = false; + QSettings settings; + + show = settings.value("mainWindow/showSplashScreen", false).toBool(); + + return show; +} int main( int argc, char *argv[] ) { int retval; qInstallMessageHandler(MessageOutput); QApplication app(argc, argv); -#ifdef SPLASH_SCREEN_ENABLE - QSplashScreen *splash; - QPixmap pixmap(":/fceux1.png"); - - splash = new QSplashScreen( pixmap ); - splash->show(); - splash->showMessage("Initializing GUI..."); - app.processEvents(); -#endif - - QCoreApplication::setOrganizationName("TasVideos"); - QCoreApplication::setOrganizationDomain("TasVideos.org"); + QCoreApplication::setOrganizationName("TasEmulators"); + QCoreApplication::setOrganizationDomain("TasEmulators.org"); QCoreApplication::setApplicationName("fceux"); + fceuSplashScreen *splash = NULL; + + if ( showSplashScreen() ) + { + splash = new fceuSplashScreen(); + splash->show(); + app.processEvents(); + } + #ifdef WIN32 if (AttachConsole(ATTACH_PARENT_PROCESS)) { @@ -148,11 +157,11 @@ int main( int argc, char *argv[] ) QWindowsWindowFunctions::setHasBorderInFullScreen( consoleWindow->windowHandle(), true); #endif -#ifdef SPLASH_SCREEN_ENABLE - splash->finish( consoleWindow ); - - delete splash; -#endif + if ( splash ) + { + splash->finish( consoleWindow ); + //delete splash; this is handled by Qt event loop + } retval = app.exec();