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.

This commit is contained in:
mjbudd77 2022-01-16 11:12:13 -05:00
parent 47098b2b8c
commit cb5bb3446d
6 changed files with 132 additions and 18 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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();
}
}

View File

@ -0,0 +1,28 @@
// SplashScreen.h
//
#pragma once
#include <QTimer>
#include <QPixmap>
#include <QCloseEvent>
#include <QSplashScreen>
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);
};

View File

@ -21,10 +21,12 @@
#include <stdlib.h>
#include <QApplication>
#include <QSplashScreen>
#include <QSettings>
//#include <QProxyStyle>
#include "Qt/ConsoleWindow.h"
#include "Qt/fceuWrapper.h"
#include "Qt/SplashScreen.h"
#ifdef WIN32
#include <QtPlatformHeaders/QWindowsWindowFunctions>
@ -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();