Merge pull request #146 from mjbudd77/master

QT SDL cheat window minor update.
This commit is contained in:
mjbudd77 2020-08-03 22:03:44 -04:00 committed by GitHub
commit 06352de68a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 3 deletions

View File

@ -37,12 +37,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
QGroupBox *groupBox; QGroupBox *groupBox;
QFrame *frame; QFrame *frame;
QScreen *screen = QGuiApplication::primaryScreen(); QScreen *screen = QGuiApplication::primaryScreen();
int devPixRatio = 1; double devPixRatio = 1.0f;
if ( screen != NULL ) if ( screen != NULL )
{ {
devPixRatio = (int)( screen->devicePixelRatio() + 0.50f); devPixRatio = (int)( screen->devicePixelRatio() + 0.50f);
printf("Pix Ratio: %i \n", devPixRatio ); //printf("Pix Ratio: %f \n", devPixRatio );
} }
font.setStyle( QFont::StyleNormal ); font.setStyle( QFont::StyleNormal );
@ -50,7 +50,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
QFontMetrics fm(font); QFontMetrics fm(font);
fontCharWidth = fm.boundingRect('0').width() * devPixRatio; fontCharWidth = fm.boundingRect('X').width() * devPixRatio;
setWindowTitle("Cheat Search"); setWindowTitle("Cheat Search");
@ -124,6 +124,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
cheatAddrEntry->setInputMask( ">HHHH;0" ); cheatAddrEntry->setInputMask( ">HHHH;0" );
cheatAddrEntry->setFont( font ); cheatAddrEntry->setFont( font );
cheatAddrEntry->setCursorPosition(0); cheatAddrEntry->setCursorPosition(0);
cheatAddrEntry->setAlignment(Qt::AlignCenter);
cheatAddrEntry->setMaximumWidth( 5 * fontCharWidth ); cheatAddrEntry->setMaximumWidth( 5 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
@ -135,6 +136,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
cheatValEntry->setInputMask( ">HH;0" ); cheatValEntry->setInputMask( ">HH;0" );
cheatValEntry->setFont( font ); cheatValEntry->setFont( font );
cheatValEntry->setCursorPosition(0); cheatValEntry->setCursorPosition(0);
cheatValEntry->setAlignment(Qt::AlignCenter);
cheatValEntry->setMaximumWidth( 3 * fontCharWidth ); cheatValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
@ -146,6 +148,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
cheatCmpEntry->setInputMask( ">HH;X" ); cheatCmpEntry->setInputMask( ">HH;X" );
cheatCmpEntry->setFont( font ); cheatCmpEntry->setFont( font );
cheatCmpEntry->setCursorPosition(0); cheatCmpEntry->setCursorPosition(0);
cheatCmpEntry->setAlignment(Qt::AlignCenter);
cheatCmpEntry->setMaximumWidth( 3 * fontCharWidth ); cheatCmpEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
@ -253,6 +256,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
knownValEntry->setCursorPosition(0); knownValEntry->setCursorPosition(0);
knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
knownValEntry->setMaximumWidth( 3 * fontCharWidth ); knownValEntry->setMaximumWidth( 3 * fontCharWidth );
knownValEntry->setAlignment(Qt::AlignCenter);
knownValEntry->setEnabled(false); knownValEntry->setEnabled(false);
hbox1->addWidget( lbl, 0, Qt::AlignRight ); hbox1->addWidget( lbl, 0, Qt::AlignRight );
hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft );
@ -297,6 +301,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
neValEntry->setCursorPosition(0); neValEntry->setCursorPosition(0);
neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
neValEntry->setMaximumWidth( 3 * fontCharWidth ); neValEntry->setMaximumWidth( 3 * fontCharWidth );
neValEntry->setAlignment(Qt::AlignCenter);
neValEntry->setEnabled(false); neValEntry->setEnabled(false);
hbox->addWidget( useNeVal, 0, Qt::AlignRight ); hbox->addWidget( useNeVal, 0, Qt::AlignRight );
@ -327,6 +332,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
grValEntry->setCursorPosition(0); grValEntry->setCursorPosition(0);
grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
grValEntry->setMaximumWidth( 3 * fontCharWidth ); grValEntry->setMaximumWidth( 3 * fontCharWidth );
grValEntry->setAlignment(Qt::AlignCenter);
grValEntry->setEnabled(false); grValEntry->setEnabled(false);
hbox->addWidget( useGrVal, 0, Qt::AlignRight ); hbox->addWidget( useGrVal, 0, Qt::AlignRight );
@ -357,6 +363,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
ltValEntry->setCursorPosition(0); ltValEntry->setCursorPosition(0);
ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
ltValEntry->setMaximumWidth( 3 * fontCharWidth ); ltValEntry->setMaximumWidth( 3 * fontCharWidth );
ltValEntry->setAlignment(Qt::AlignCenter);
ltValEntry->setEnabled(false); ltValEntry->setEnabled(false);
hbox->addWidget( useLtVal, 0, Qt::AlignRight ); hbox->addWidget( useLtVal, 0, Qt::AlignRight );
@ -394,6 +401,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
connect( pauseBox , SIGNAL(stateChanged(int)), this, SLOT(pauseWindowState(int)) ); connect( pauseBox , SIGNAL(stateChanged(int)), this, SLOT(pauseWindowState(int)) );
connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) );
connect( exportCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(saveCheatFile(void)) );
showActiveCheatList(true); showActiveCheatList(true);
} }
@ -716,6 +724,93 @@ void GuiCheatsDialog_t::openCheatFile(void)
return; return;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void GuiCheatsDialog_t::saveCheatFile(void)
{
FILE *fp;
int ret, useNativeFileDialogVal;
QString filename;
char dir[512];
QFileDialog dialog(this, tr("Save Cheat File") );
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter(tr("Cheat files (*.cht *.CHT) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Save") );
if ( GameInfo )
{
char *_filename;
if ((_filename = strrchr(GameInfo->filename, '\\')) || (_filename = strrchr(GameInfo->filename, '/')))
{
strcpy( dir, _filename + 1);
}
else
{
strcpy( dir, GameInfo->filename);
}
_filename = strrchr( dir, '.');
if (_filename)
{
strcpy(_filename, ".cht");
}
else
{
strcat( dir, ".cht");
}
dialog.selectFile( dir );
}
sprintf( dir, "%s/cheats", FCEUI_GetBaseDirectory() );
dialog.setDirectory( tr(dir) );
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
dialog.show();
ret = dialog.exec();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
if ( filename.isNull() )
{
return;
}
qDebug() << "selected file path : " << filename.toUtf8();
//g_config->setOption ("SDL.LastOpenFile", filename.toStdString().c_str() );
fceuWrapperLock();
fp = FCEUD_UTF8fopen (filename.toStdString().c_str(), "wb");
if (fp != NULL)
{
FCEU_SaveGameCheats (fp);
fclose (fp);
}
fceuWrapperUnLock();
showActiveCheatList(true);
return;
}
//----------------------------------------------------------------------------
void GuiCheatsDialog_t::addActvCheat(void) void GuiCheatsDialog_t::addActvCheat(void)
{ {
uint32 a = 0; uint32 a = 0;

View File

@ -86,6 +86,7 @@ class GuiCheatsDialog_t : public QDialog
void lessThanValueCallback(void); void lessThanValueCallback(void);
void greaterThanValueCallback(void); void greaterThanValueCallback(void);
void openCheatFile(void); void openCheatFile(void);
void saveCheatFile(void);
void addActvCheat(void); void addActvCheat(void);
void deleteActvCheat(void); void deleteActvCheat(void);
void updateCheatParameters(void); void updateCheatParameters(void);