Merge pull request #141 from mjbudd77/master
Qt SDL GUI Message Dialog Updates
This commit is contained in:
commit
42df5f6171
|
@ -4,6 +4,7 @@
|
|||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "../../fceu.h"
|
||||
#include "../../fds.h"
|
||||
|
@ -39,6 +40,7 @@ consoleWin_t::consoleWin_t(QWidget *parent)
|
|||
|
||||
g_config->getOption( "SDL.VideoDriver", &use_SDL_video );
|
||||
|
||||
errorMsgValid = false;
|
||||
viewport_GL = NULL;
|
||||
viewport_SDL = NULL;
|
||||
|
||||
|
@ -72,6 +74,7 @@ consoleWin_t::consoleWin_t(QWidget *parent)
|
|||
emulatorThread->start();
|
||||
|
||||
gamePadConfWin = NULL;
|
||||
|
||||
}
|
||||
|
||||
consoleWin_t::~consoleWin_t(void)
|
||||
|
@ -116,6 +119,26 @@ void consoleWin_t::setCyclePeriodms( int ms )
|
|||
//printf("Period Set to: %i ms \n", ms );
|
||||
}
|
||||
|
||||
void consoleWin_t::showErrorMsgWindow()
|
||||
{
|
||||
QMessageBox msgBox(this);
|
||||
|
||||
fceuWrapperLock();
|
||||
msgBox.setIcon( QMessageBox::Critical );
|
||||
msgBox.setText( tr(errorMsg.c_str()) );
|
||||
errorMsg.clear();
|
||||
fceuWrapperUnLock();
|
||||
msgBox.show();
|
||||
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 +512,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 +1362,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 +1414,12 @@ void consoleWin_t::updatePeriodic(void)
|
|||
}
|
||||
}
|
||||
|
||||
if ( errorMsgValid )
|
||||
{
|
||||
showErrorMsgWindow();
|
||||
errorMsgValid = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ class consoleWin_t : public QMainWindow
|
|||
|
||||
QMutex *mutex;
|
||||
|
||||
void QueueErrorMsgWindow( const char *msg );
|
||||
|
||||
protected:
|
||||
QMenu *fileMenu;
|
||||
QMenu *optMenu;
|
||||
|
@ -72,6 +74,7 @@ class consoleWin_t : public QMainWindow
|
|||
QAction *autoResume;
|
||||
QAction *fullscreen;
|
||||
QAction *aboutAct;
|
||||
QAction *aboutActQt;
|
||||
QAction *state[10];
|
||||
QAction *powerAct;
|
||||
QAction *resetAct;
|
||||
|
@ -89,15 +92,20 @@ class consoleWin_t : public QMainWindow
|
|||
QAction *recAsMovAct;
|
||||
|
||||
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 +120,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);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//
|
||||
#include <QDir>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#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; i<GAMEPAD_NUM_BUTTONS; i++)
|
||||
{
|
||||
btn[i].needsSave = 0;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static GamePadConfigLocalData_t lcl[GAMEPAD_NUM_DEVICES];
|
||||
|
||||
//----------------------------------------------------
|
||||
GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
||||
: QDialog( parent )
|
||||
|
@ -29,6 +53,8 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
QPushButton *clearAllButton;
|
||||
QPushButton *closebutton;
|
||||
QPushButton *clearButton[GAMEPAD_NUM_BUTTONS];
|
||||
std::string prefix;
|
||||
char stmp[256];
|
||||
|
||||
InitJoysticks();
|
||||
|
||||
|
@ -71,10 +97,8 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
{
|
||||
if ( js->isConnected() )
|
||||
{
|
||||
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; i<GAMEPAD_NUM_DEVICES; i++)
|
||||
{
|
||||
sprintf( stmp, "SDL.Input.GamePad.%i.", i );
|
||||
prefix = stmp;
|
||||
|
||||
g_config->getOption(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; i<GAMEPAD_NUM_BUTTONS; i++)
|
||||
{
|
||||
lcl[portNum].btn[i].needsSave = 0;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------
|
||||
void GamePadConfDialog_t::createNewProfile( const char *name )
|
||||
{
|
||||
printf("Creating: %s \n", name );
|
||||
char stmp[256];
|
||||
//printf("Creating: %s \n", name );
|
||||
|
||||
GamePad[portNum].createProfile(name);
|
||||
|
||||
mapSel->addItem( 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,71 @@ 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<GAMEPAD_NUM_DEVICES; i++)
|
||||
{
|
||||
padNeedsSave[i] = 0;
|
||||
|
||||
for (j=0; j<GAMEPAD_NUM_BUTTONS; j++)
|
||||
{
|
||||
if ( lcl[i].btn[j].needsSave )
|
||||
{
|
||||
padNeedsSave[i] = 1;
|
||||
saveRequired = 1;
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !saveRequired )
|
||||
{
|
||||
return;
|
||||
}
|
||||
sprintf( stmp, "Warning: Gamepad mappings have not been saved for port%c ", (n > 1) ? 's':' ');
|
||||
|
||||
msg.assign( stmp );
|
||||
|
||||
j=n;
|
||||
for (i=0; i<GAMEPAD_NUM_DEVICES; i++)
|
||||
{
|
||||
if ( padNeedsSave[i] )
|
||||
{
|
||||
sprintf( stmp, "%i", i+1 );
|
||||
|
||||
msg.append(stmp);
|
||||
|
||||
j--;
|
||||
|
||||
if ( j > 1 )
|
||||
{
|
||||
msg.append(", ");
|
||||
}
|
||||
else if ( j == 1 )
|
||||
{
|
||||
msg.append(" and ");
|
||||
}
|
||||
}
|
||||
}
|
||||
msg.append(".");
|
||||
|
||||
msgBox.setIcon( QMessageBox::Warning );
|
||||
msgBox.setText( tr(msg.c_str()) );
|
||||
|
||||
msgBox.show();
|
||||
//msgBox.resize( 512, 128 );
|
||||
msgBox.exec();
|
||||
}
|
||||
//----------------------------------------------------
|
||||
void GamePadConfDialog_t::updatePeriodic(void)
|
||||
{
|
||||
for (int i=0; i<GAMEPAD_NUM_BUTTONS; i++)
|
||||
|
@ -706,6 +838,15 @@ void GamePadConfDialog_t::updatePeriodic(void)
|
|||
}
|
||||
keyState[i]->setText( tr(txt) );
|
||||
keyState[i]->setStyleSheet( style );
|
||||
|
||||
if ( lcl[portNum].btn[i].needsSave )
|
||||
{
|
||||
keyName[i]->setStyleSheet("color: red;");
|
||||
}
|
||||
else
|
||||
{
|
||||
keyName[i]->setStyleSheet("color: black;");
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue