Added callbacks for cheat search buttons.

This commit is contained in:
Matthew Budd 2020-07-31 20:14:17 -04:00
parent cf54c8d225
commit b6871bc36d
2 changed files with 113 additions and 8 deletions

View File

@ -32,11 +32,14 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
QLabel *lbl; QLabel *lbl;
QGroupBox *groupBox; QGroupBox *groupBox;
QFrame *frame; QFrame *frame;
QFont font;
font.setStyle( QFont::StyleNormal ); font.setStyle( QFont::StyleNormal );
font.setStyleHint( QFont::Monospace ); font.setStyleHint( QFont::Monospace );
QFontMetrics fm(font);
fontCharWidth = fm.boundingRect('0').width();
setWindowTitle("Cheat Search"); setWindowTitle("Cheat Search");
//resize( 512, 512 ); //resize( 512, 512 );
@ -107,7 +110,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->setMaximumWidth( 5 * cheatAddrEntry->fontMetrics().boundingRect('0').width() ); cheatAddrEntry->setMaximumWidth( 5 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
hbox->addWidget( cheatAddrEntry ); hbox->addWidget( cheatAddrEntry );
@ -118,7 +121,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->setMaximumWidth( 3 * cheatValEntry->fontMetrics().boundingRect('0').width() ); cheatValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
hbox->addWidget( cheatValEntry ); hbox->addWidget( cheatValEntry );
@ -129,7 +132,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->setMaximumWidth( 3 * cheatCmpEntry->fontMetrics().boundingRect('0').width() ); cheatCmpEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( lbl ); hbox->addWidget( lbl );
hbox->addWidget( cheatCmpEntry ); hbox->addWidget( cheatCmpEntry );
@ -184,8 +187,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
//srchResults->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); //srchResults->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
srchResults->header()->setSectionResizeMode( QHeaderView::Interactive ); srchResults->header()->setSectionResizeMode( QHeaderView::Interactive );
//srchResults->header()->setSectionResizeMode( QHeaderView::Fixed ); //srchResults->header()->setSectionResizeMode( QHeaderView::Fixed );
srchResults->header()->resizeSection( 0, 10 * fontCharWidth );
srchResults->header()->resizeSection( 1, 6 * fontCharWidth );
srchResults->header()->resizeSection( 2, 6 * fontCharWidth );
//srchResults->header()->setSectionResizeMode( QHeaderView::Stretch ); //srchResults->header()->setSectionResizeMode( QHeaderView::Stretch );
//srchResults->header()->setDefaultSectionSize( 200 ); //srchResults->header()->setDefaultSectionSize( 200 );
//srchResults->header()->setDefaultSectionSize( 200 );
//srchResults->setReadOnly(true); //srchResults->setReadOnly(true);
vbox = new QVBoxLayout(); vbox = new QVBoxLayout();
@ -230,7 +237,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
knownValEntry->setFont( font ); knownValEntry->setFont( font );
knownValEntry->setCursorPosition(0); knownValEntry->setCursorPosition(0);
knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
knownValEntry->setMaximumWidth( 3 * knownValEntry->fontMetrics().boundingRect('0').width() ); knownValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox1->addWidget( lbl, 0, Qt::AlignRight ); hbox1->addWidget( lbl, 0, Qt::AlignRight );
hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft );
@ -270,7 +277,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
neValEntry->setFont( font ); neValEntry->setFont( font );
neValEntry->setCursorPosition(0); neValEntry->setCursorPosition(0);
neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
neValEntry->setMaximumWidth( 3 * neValEntry->fontMetrics().boundingRect('0').width() ); neValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( useNeVal, 0, Qt::AlignRight ); hbox->addWidget( useNeVal, 0, Qt::AlignRight );
hbox->addWidget( neValEntry, 0, Qt::AlignLeft ); hbox->addWidget( neValEntry, 0, Qt::AlignLeft );
@ -297,7 +304,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
grValEntry->setFont( font ); grValEntry->setFont( font );
grValEntry->setCursorPosition(0); grValEntry->setCursorPosition(0);
grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
grValEntry->setMaximumWidth( 3 * grValEntry->fontMetrics().boundingRect('0').width() ); grValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( useGrVal, 0, Qt::AlignRight ); hbox->addWidget( useGrVal, 0, Qt::AlignRight );
hbox->addWidget( grValEntry, 0, Qt::AlignLeft ); hbox->addWidget( grValEntry, 0, Qt::AlignLeft );
@ -324,7 +331,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
ltValEntry->setFont( font ); ltValEntry->setFont( font );
ltValEntry->setCursorPosition(0); ltValEntry->setCursorPosition(0);
ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
ltValEntry->setMaximumWidth( 3 * ltValEntry->fontMetrics().boundingRect('0').width() ); ltValEntry->setMaximumWidth( 3 * fontCharWidth );
hbox->addWidget( useLtVal, 0, Qt::AlignRight ); hbox->addWidget( useLtVal, 0, Qt::AlignRight );
hbox->addWidget( ltValEntry, 0, Qt::AlignLeft ); hbox->addWidget( ltValEntry, 0, Qt::AlignLeft );
@ -341,6 +348,10 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent)
connect( srchResetBtn, SIGNAL(clicked(void)), this, SLOT(resetSearchCallback(void)) ); connect( srchResetBtn, SIGNAL(clicked(void)), this, SLOT(resetSearchCallback(void)) );
connect( knownValBtn , SIGNAL(clicked(void)), this, SLOT(knownValueCallback(void)) ); connect( knownValBtn , SIGNAL(clicked(void)), this, SLOT(knownValueCallback(void)) );
connect( eqValBtn , SIGNAL(clicked(void)), this, SLOT(equalValueCallback(void)) );
connect( neValBtn , SIGNAL(clicked(void)), this, SLOT(notEqualValueCallback(void)) );
connect( ltValBtn , SIGNAL(clicked(void)), this, SLOT(lessThanValueCallback(void)) );
connect( grValBtn , SIGNAL(clicked(void)), this, SLOT(greaterThanValueCallback(void)) );
cheat_search_known_value = 0; cheat_search_known_value = 0;
@ -368,6 +379,10 @@ int GuiCheatsDialog_t::addSearchResult (uint32_t a, uint8_t last, uint8_t curren
sprintf (lastStr, "%02X", last); sprintf (lastStr, "%02X", last);
sprintf (curStr , "%02X", current); sprintf (curStr , "%02X", current);
//item->setFont( 0, font );
//item->setFont( 1, font );
//item->setFont( 2, font );
item->setText( 0, tr(addrStr) ); item->setText( 0, tr(addrStr) );
item->setText( 1, tr(lastStr) ); item->setText( 1, tr(lastStr) );
item->setText( 2, tr(curStr) ); item->setText( 2, tr(curStr) );
@ -430,3 +445,84 @@ void GuiCheatsDialog_t::knownValueCallback(void)
fceuWrapperUnLock(); fceuWrapperUnLock();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void GuiCheatsDialog_t::equalValueCallback(void)
{
//printf("Cheat Search Equal!\n");
fceuWrapperLock();
FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, 0);
showCheatSearchResults();
fceuWrapperUnLock();
}
//----------------------------------------------------------------------------
void GuiCheatsDialog_t::notEqualValueCallback(void)
{
//printf("Cheat Search Not Equal!\n");
int checked = useNeVal->checkState() != Qt::Unchecked;
fceuWrapperLock();
if (checked)
{
cheat_search_neq_value = strtol( neValEntry->text().toStdString().c_str(), NULL, 16 );
FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, cheat_search_neq_value);
}
else
{
FCEUI_CheatSearchEnd (FCEU_SEARCH_ANY_CHANGE, 0, 0);
}
showCheatSearchResults();
fceuWrapperUnLock();
}
//----------------------------------------------------------------------------
void GuiCheatsDialog_t::greaterThanValueCallback(void)
{
//printf("Cheat Search Greater Than!\n");
int checked = useGrVal->checkState() != Qt::Unchecked;
fceuWrapperLock();
if (checked)
{
cheat_search_gt_value = strtol( grValEntry->text().toStdString().c_str(), NULL, 16 );
FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT_KNOWN, 0, cheat_search_gt_value);
}
else
{
FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT, 0, 0);
}
showCheatSearchResults();
fceuWrapperUnLock();
}
//----------------------------------------------------------------------------
void GuiCheatsDialog_t::lessThanValueCallback(void)
{
//printf("Cheat Search Less Than!\n");
int checked = useLtVal->checkState() != Qt::Unchecked;
fceuWrapperLock();
if (checked)
{
cheat_search_lt_value = strtol( ltValEntry->text().toStdString().c_str(), NULL, 16 );
FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT_KNOWN, 0, cheat_search_lt_value);
}
else
{
FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT, 0, 0);
}
showCheatSearchResults();
fceuWrapperUnLock();
}
//----------------------------------------------------------------------------

View File

@ -59,8 +59,13 @@ class GuiCheatsDialog_t : public QDialog
QLineEdit *neValEntry; QLineEdit *neValEntry;
QLineEdit *grValEntry; QLineEdit *grValEntry;
QLineEdit *ltValEntry; QLineEdit *ltValEntry;
QFont font;
int fontCharWidth;
int cheat_search_known_value; int cheat_search_known_value;
int cheat_search_neq_value;
int cheat_search_gt_value;
int cheat_search_lt_value;
private: private:
void showCheatSearchResults(void); void showCheatSearchResults(void);
@ -70,5 +75,9 @@ class GuiCheatsDialog_t : public QDialog
private slots: private slots:
void resetSearchCallback(void); void resetSearchCallback(void);
void knownValueCallback(void); void knownValueCallback(void);
void equalValueCallback(void);
void notEqualValueCallback(void);
void lessThanValueCallback(void);
void greaterThanValueCallback(void);
}; };