From 0112782eabe5bd89c4e8411047be2d3539e811df Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 26 Jul 2020 14:07:28 -0400 Subject: [PATCH 1/3] Added logic to change color of changed button mapping to red until they are save to a profile. Also, added a warning message to inform user of unsaved mappings. --- src/drivers/Qt/GamePadConf.cpp | 150 ++++++++++++++++++++++++++++++-- src/drivers/Qt/GamePadConf.h | 1 + src/drivers/Qt/sdl-joystick.cpp | 7 +- 3 files changed, 148 insertions(+), 10 deletions(-) diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index eee64188..ec1b7515 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -2,6 +2,7 @@ // #include #include +#include #include "Qt/GamePadConf.h" #include "Qt/main.h" @@ -12,6 +13,29 @@ #include "Qt/sdl-joystick.h" #include "Qt/fceuWrapper.h" +struct GamePadConfigLocalData_t +{ + std::string guid; + std::string profile; + + struct { + + char needsSave; + + } btn[GAMEPAD_NUM_BUTTONS]; + + GamePadConfigLocalData_t(void) + { + for (int i=0; iisConnected() ) { - char stmp[128]; sprintf( stmp, "%i: %s", i, js->getName() ); devSel->addItem( tr(stmp), i ); - } } } @@ -236,6 +260,16 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) inputTimer->start( 33 ); // 30hz + for (int i=0; igetOption(prefix + "Profile", &lcl[i].profile ); + + lcl[i].guid.assign( GamePad[i].getGUID() ); + } + loadMapList(); } @@ -345,7 +379,17 @@ void GamePadConfDialog_t::updateCntrlrDpy(void) { strcpy( keyNameStr, ButtonName( &GamePad[portNum].bmap[i] ) ); } + keyName[i]->setText( tr(keyNameStr) ); + + //if ( lcl[portNum].btn[i].needsSave ) + //{ + // keyName[i]->setStyleSheet("color: red;"); + //} + //else + //{ + // keyName[i]->setStyleSheet("color: black;"); + //} } } //---------------------------------------------------- @@ -387,6 +431,9 @@ void GamePadConfDialog_t::deviceSelect(int index) } GamePad[portNum].setDeviceIndex( devIdx ); + lcl[portNum].guid.assign( GamePad[portNum].getGUID() ); + lcl[portNum].profile.assign("default"); + loadMapList(); updateCntrlrDpy(); @@ -429,6 +476,7 @@ void GamePadConfDialog_t::changeButton(int padNo, int x) keyName[x]->setText( keyNameStr ); button[x]->setText("Change"); + lcl[padNo].btn[x].needsSave = 1; ButtonConfigEnd (); @@ -440,11 +488,15 @@ void GamePadConfDialog_t::clearButton( int padNo, int x ) GamePad[padNo].bmap[x].ButtonNum = -1; keyName[x]->setText(""); + + lcl[padNo].btn[x].needsSave = 1; } //---------------------------------------------------- void GamePadConfDialog_t::closeEvent(QCloseEvent *event) { - //printf("GamePad Close Window Event\n"); + promptToSave(); + + printf("GamePad Close Window Event\n"); buttonConfigStatus = 0; done(0); event->accept(); @@ -452,7 +504,9 @@ void GamePadConfDialog_t::closeEvent(QCloseEvent *event) //---------------------------------------------------- void GamePadConfDialog_t::closeWindow(void) { - //printf("Close Window\n"); + promptToSave(); + + printf("Close Window\n"); buttonConfigStatus = 0; done(0); } @@ -567,6 +621,7 @@ void GamePadConfDialog_t::clearAllCallback(void) //---------------------------------------------------- void GamePadConfDialog_t::saveConfig(void) { + int i; char stmp[256]; std::string prefix, mapName; @@ -577,15 +632,27 @@ void GamePadConfDialog_t::saveConfig(void) g_config->setOption(prefix + "DeviceGUID", GamePad[portNum].getGUID() ); g_config->setOption(prefix + "Profile" , mapName.c_str() ); + + for (i=0; iaddItem( tr(name) ); + + mapSel->setCurrentIndex( mapSel->count() - 1 ); + saveConfig(); + + sprintf( stmp, "Mapping Created: %s/%s \n", GamePad[portNum].getGUID(), name ); + mapMsg->setText( tr(stmp) ); } //---------------------------------------------------- void GamePadConfDialog_t::newProfileCallback(void) @@ -689,6 +756,70 @@ void GamePadConfDialog_t::deleteProfileCallback(void) loadMapList(); } //---------------------------------------------------- +void GamePadConfDialog_t::promptToSave(void) +{ + int i,j,n; + std::string msg; + QMessageBox msgBox(this); + char saveRequired = 0; + char padNeedsSave[GAMEPAD_NUM_DEVICES]; + char stmp[256]; + + n=0; + for (i=0; i 1) ? 's':' '); + + msg.assign( stmp ); + + j=n; + for (i=0; i 1 ) + { + msg.append(", "); + } + else if ( j == 1 ) + { + msg.append(" and "); + } + } + } + msg.append("."); + + msgBox.setText( tr(msg.c_str()) ); + + msgBox.show(); + //msgBox.resize( 512, 128 ); + msgBox.exec(); +} +//---------------------------------------------------- void GamePadConfDialog_t::updatePeriodic(void) { for (int i=0; isetText( tr(txt) ); keyState[i]->setStyleSheet( style ); + + if ( lcl[portNum].btn[i].needsSave ) + { + keyName[i]->setStyleSheet("color: red;"); + } + else + { + keyName[i]->setStyleSheet("color: black;"); + } } } //---------------------------------------------------- diff --git a/src/drivers/Qt/GamePadConf.h b/src/drivers/Qt/GamePadConf.h index ba24b463..5efafeb3 100644 --- a/src/drivers/Qt/GamePadConf.h +++ b/src/drivers/Qt/GamePadConf.h @@ -62,6 +62,7 @@ class GamePadConfDialog_t : public QDialog void createNewProfile( const char *name ); void loadMapList(void); void saveConfig(void); + void promptToSave(void); public slots: void closeWindow(void); diff --git a/src/drivers/Qt/sdl-joystick.cpp b/src/drivers/Qt/sdl-joystick.cpp index 57c2f616..8e0ddcd3 100644 --- a/src/drivers/Qt/sdl-joystick.cpp +++ b/src/drivers/Qt/sdl-joystick.cpp @@ -742,7 +742,6 @@ int GamePad_t::saveMappingToFile( const char *filename, const char *txtMap ) //******************************************************************************** int GamePad_t::createProfile( const char *name ) { - char txtMap[256]; const char *guid = NULL; const char *baseDir = FCEUI_GetBaseDirectory(); std::string path; @@ -771,13 +770,11 @@ int GamePad_t::createProfile( const char *name ) dir.mkpath( QString::fromStdString(path) ); //printf("DIR: '%s'\n", path.c_str() ); - path += "/" + std::string(name) + ".txt"; + //path += "/" + std::string(name) + ".txt"; //printf("File: '%s'\n", path.c_str() ); - getDefaultMap( txtMap, guid ); - - saveMappingToFile( path.c_str(), txtMap ); + saveCurrentMapToFile( name ); return 0; } From e918f8562a0afafad9a90de8872182e9f645d580 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 26 Jul 2020 21:31:32 -0400 Subject: [PATCH 2/3] Added an error message window to the GUI. Added About Qt window to GUI. --- src/drivers/Qt/ConsoleWindow.cpp | 54 ++++++++++++++++++++++++++++++-- src/drivers/Qt/ConsoleWindow.h | 12 +++++++ src/drivers/Qt/GamePadConf.cpp | 3 +- src/drivers/Qt/fceuWrapper.cpp | 6 ++-- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 89c75483..51f3e724 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "../../fceu.h" #include "../../fds.h" @@ -35,10 +37,13 @@ consoleWin_t::consoleWin_t(QWidget *parent) { int use_SDL_video = false; + errorMsgBox = QErrorMessage::qtHandler(); + createMainMenu(); g_config->getOption( "SDL.VideoDriver", &use_SDL_video ); + errorMsgValid = false; viewport_GL = NULL; viewport_SDL = NULL; @@ -72,6 +77,7 @@ consoleWin_t::consoleWin_t(QWidget *parent) emulatorThread->start(); gamePadConfWin = NULL; + } consoleWin_t::~consoleWin_t(void) @@ -116,6 +122,26 @@ void consoleWin_t::setCyclePeriodms( int ms ) //printf("Period Set to: %i ms \n", ms ); } +void consoleWin_t::showErrorMsgWindow() +{ + //QErrorMessage msgBox; + + fceuWrapperLock(); + //msgBox.setIcon( QMessageBox::Warning ); + //msgBox.showMessage( tr(errorMsg.c_str()) ); + qWarning( errorMsg.c_str() ); + errorMsg.clear(); + fceuWrapperUnLock(); + //msgBox.exec(); +} + +void consoleWin_t::QueueErrorMsgWindow( const char *msg ) +{ + errorMsg.append( msg ); + errorMsg.append("\n"); + errorMsgValid = true; +} + void consoleWin_t::closeEvent(QCloseEvent *event) { //printf("Main Window Close Event\n"); @@ -489,12 +515,20 @@ void consoleWin_t::createMainMenu(void) //----------------------------------------------------------------------- // Help helpMenu = menuBar()->addMenu(tr("Help")); - - aboutAct = new QAction(tr("About"), this); + + // Help -> About FCEUX + aboutAct = new QAction(tr("About FCEUX"), this); aboutAct->setStatusTip(tr("About FCEUX")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(aboutFCEUX(void)) ); helpMenu->addAction(aboutAct); + + // Help -> About Qt + aboutActQt = new QAction(tr("About Qt"), this); + aboutActQt->setStatusTip(tr("About Qt")); + connect(aboutActQt, SIGNAL(triggered()), this, SLOT(aboutQt(void)) ); + + helpMenu->addAction(aboutActQt); }; //--------------------------------------------------------------------------- void consoleWin_t::closeApp(void) @@ -1331,6 +1365,16 @@ void consoleWin_t::aboutFCEUX(void) return; } +void consoleWin_t::aboutQt(void) +{ + //printf("About Qt Window\n"); + + QMessageBox::aboutQt(this); + + //printf("About Qt Destroyed\n"); + return; +} + void consoleWin_t::syncActionConfig( QAction *act, const char *property ) { if ( act->isCheckable() ) @@ -1373,6 +1417,12 @@ void consoleWin_t::updatePeriodic(void) } } + if ( errorMsgValid ) + { + showErrorMsgWindow(); + errorMsgValid = false; + } + return; } diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index c20c1aff..a2b64585 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -46,6 +47,8 @@ class consoleWin_t : public QMainWindow QMutex *mutex; + void QueueErrorMsgWindow( const char *msg ); + protected: QMenu *fileMenu; QMenu *optMenu; @@ -72,6 +75,7 @@ class consoleWin_t : public QMainWindow QAction *autoResume; QAction *fullscreen; QAction *aboutAct; + QAction *aboutActQt; QAction *state[10]; QAction *powerAct; QAction *resetAct; @@ -88,16 +92,23 @@ class consoleWin_t : public QMainWindow QAction *recMovAct; QAction *recAsMovAct; + QErrorMessage *errorMsgBox; + QTimer *gameTimer; + emulatorThread_t *emulatorThread; GamePadConfDialog_t *gamePadConfWin; + std::string errorMsg; + bool errorMsgValid; + protected: void closeEvent(QCloseEvent *event); void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); void syncActionConfig( QAction *act, const char *property ); + void showErrorMsgWindow(void); private: void createMainMenu(void); @@ -112,6 +123,7 @@ class consoleWin_t : public QMainWindow void quickSave(void); void closeROMCB(void); void aboutFCEUX(void); + void aboutQt(void); void openGamePadConfWin(void); void openGameSndConfWin(void); void openGameVideoConfWin(void); diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index ec1b7515..efd908ee 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -262,7 +262,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) for (int i=0; igetOption(prefix + "Profile", &lcl[i].profile ); @@ -813,6 +813,7 @@ void GamePadConfDialog_t::promptToSave(void) } msg.append("."); + msgBox.setIcon( QMessageBox::Warning ); msgBox.setText( tr(msg.c_str()) ); msgBox.show(); diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 0d5f18a7..25b506d0 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -80,20 +80,22 @@ int mutecapture = 0; void FCEUD_Message(const char *text) { fputs(text, stdout); - fprintf(stdout, "\n"); + //fprintf(stdout, "\n"); } /** * Shows an error message in a message box. * (For now: prints to stderr.) * -* If running in GTK mode, display a dialog message box of the error. +* If running in Qt mode, display a dialog message box of the error. * * @param errormsg Text of the error message. **/ void FCEUD_PrintError(const char *errormsg) { fprintf(stderr, "%s\n", errormsg); + + consoleWindow->QueueErrorMsgWindow( errormsg ); } /** From 3528adea30e1baac912163ce451b0dbee623a4f5 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 26 Jul 2020 22:04:31 -0400 Subject: [PATCH 3/3] Changed error message window to use QMessageBox instead of QErrorMessage to have more control over display image. --- src/drivers/Qt/ConsoleWindow.cpp | 13 +++++-------- src/drivers/Qt/ConsoleWindow.h | 3 --- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 51f3e724..f4798adc 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "../../fceu.h" #include "../../fds.h" @@ -37,8 +36,6 @@ consoleWin_t::consoleWin_t(QWidget *parent) { int use_SDL_video = false; - errorMsgBox = QErrorMessage::qtHandler(); - createMainMenu(); g_config->getOption( "SDL.VideoDriver", &use_SDL_video ); @@ -124,15 +121,15 @@ void consoleWin_t::setCyclePeriodms( int ms ) void consoleWin_t::showErrorMsgWindow() { - //QErrorMessage msgBox; + QMessageBox msgBox(this); fceuWrapperLock(); - //msgBox.setIcon( QMessageBox::Warning ); - //msgBox.showMessage( tr(errorMsg.c_str()) ); - qWarning( errorMsg.c_str() ); + msgBox.setIcon( QMessageBox::Critical ); + msgBox.setText( tr(errorMsg.c_str()) ); errorMsg.clear(); fceuWrapperUnLock(); - //msgBox.exec(); + msgBox.show(); + msgBox.exec(); } void consoleWin_t::QueueErrorMsgWindow( const char *msg ) diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index a2b64585..1ce854c5 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -92,8 +91,6 @@ class consoleWin_t : public QMainWindow QAction *recMovAct; QAction *recAsMovAct; - QErrorMessage *errorMsgBox; - QTimer *gameTimer; emulatorThread_t *emulatorThread;