From 0fdf8cec1414ffd34c27a557c50d52f9099f6de2 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Mon, 3 Aug 2020 20:20:48 -0400 Subject: [PATCH 1/4] Changed character used for width to be an X instead of 0 --- src/drivers/Qt/CheatsConf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 29f9bdaf..868fc5e4 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -37,12 +37,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) QGroupBox *groupBox; QFrame *frame; QScreen *screen = QGuiApplication::primaryScreen(); - int devPixRatio = 1; + double devPixRatio = 1.0f; if ( screen != NULL ) { devPixRatio = (int)( screen->devicePixelRatio() + 0.50f); - printf("Pix Ratio: %i \n", devPixRatio ); + printf("Pix Ratio: %f \n", devPixRatio ); } font.setStyle( QFont::StyleNormal ); @@ -50,7 +50,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) QFontMetrics fm(font); - fontCharWidth = fm.boundingRect('0').width() * devPixRatio; + fontCharWidth = fm.boundingRect('X').width() * devPixRatio; setWindowTitle("Cheat Search"); From 4a494f8dc1ea468f713aa2f0c50924ad8f94e4f6 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 3 Aug 2020 20:30:45 -0400 Subject: [PATCH 2/4] Added code to center text inside numerical entry fields on the cheat window. --- src/drivers/Qt/CheatsConf.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 868fc5e4..1b455157 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -124,6 +124,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatAddrEntry->setInputMask( ">HHHH;0" ); cheatAddrEntry->setFont( font ); cheatAddrEntry->setCursorPosition(0); + cheatAddrEntry->setAlignment(Qt::AlignCenter); cheatAddrEntry->setMaximumWidth( 5 * fontCharWidth ); hbox->addWidget( lbl ); @@ -135,6 +136,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatValEntry->setInputMask( ">HH;0" ); cheatValEntry->setFont( font ); cheatValEntry->setCursorPosition(0); + cheatValEntry->setAlignment(Qt::AlignCenter); cheatValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( lbl ); @@ -146,6 +148,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatCmpEntry->setInputMask( ">HH;X" ); cheatCmpEntry->setFont( font ); cheatCmpEntry->setCursorPosition(0); + cheatCmpEntry->setAlignment(Qt::AlignCenter); cheatCmpEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( lbl ); @@ -253,6 +256,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) knownValEntry->setCursorPosition(0); knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); knownValEntry->setMaximumWidth( 3 * fontCharWidth ); + knownValEntry->setAlignment(Qt::AlignCenter); knownValEntry->setEnabled(false); hbox1->addWidget( lbl, 0, Qt::AlignRight ); hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); @@ -297,6 +301,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) neValEntry->setCursorPosition(0); neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); neValEntry->setMaximumWidth( 3 * fontCharWidth ); + neValEntry->setAlignment(Qt::AlignCenter); neValEntry->setEnabled(false); hbox->addWidget( useNeVal, 0, Qt::AlignRight ); @@ -327,6 +332,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) grValEntry->setCursorPosition(0); grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); grValEntry->setMaximumWidth( 3 * fontCharWidth ); + grValEntry->setAlignment(Qt::AlignCenter); grValEntry->setEnabled(false); hbox->addWidget( useGrVal, 0, Qt::AlignRight ); @@ -357,6 +363,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) ltValEntry->setCursorPosition(0); ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); ltValEntry->setMaximumWidth( 3 * fontCharWidth ); + ltValEntry->setAlignment(Qt::AlignCenter); ltValEntry->setEnabled(false); hbox->addWidget( useLtVal, 0, Qt::AlignRight ); From bbd0fe44701f9067b1e1eed1ad2d247dc23f5c2d Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 3 Aug 2020 21:04:58 -0400 Subject: [PATCH 3/4] Added cheat save file logic to cheat window export button. --- src/drivers/Qt/CheatsConf.cpp | 88 +++++++++++++++++++++++++++++++++++ src/drivers/Qt/CheatsConf.h | 1 + 2 files changed, 89 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 1b455157..31a380a1 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -401,6 +401,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( pauseBox , SIGNAL(stateChanged(int)), this, SLOT(pauseWindowState(int)) ); connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); + connect( exportCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(saveCheatFile(void)) ); showActiveCheatList(true); } @@ -723,6 +724,93 @@ void GuiCheatsDialog_t::openCheatFile(void) 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) { uint32 a = 0; diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 1adb7b82..d687cb70 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -86,6 +86,7 @@ class GuiCheatsDialog_t : public QDialog void lessThanValueCallback(void); void greaterThanValueCallback(void); void openCheatFile(void); + void saveCheatFile(void); void addActvCheat(void); void deleteActvCheat(void); void updateCheatParameters(void); From b7067cc1da344ff4d20247e1cb24be9bde45686c Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 3 Aug 2020 21:12:54 -0400 Subject: [PATCH 4/4] Removed debug print statement. --- src/drivers/Qt/CheatsConf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 31a380a1..2f1de97d 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -42,7 +42,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) if ( screen != NULL ) { devPixRatio = (int)( screen->devicePixelRatio() + 0.50f); - printf("Pix Ratio: %f \n", devPixRatio ); + //printf("Pix Ratio: %f \n", devPixRatio ); } font.setStyle( QFont::StyleNormal );