First successful test of Qt iNES header editor.
This commit is contained in:
parent
bcef387bb0
commit
9f10a1fb20
|
@ -189,3 +189,64 @@ int parseFilepath( const char *filepath, char *dir, char *base, char *suffix )
|
|||
return end;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// FCEU Data Entry Custom Validators
|
||||
//---------------------------------------------------------------------------
|
||||
fceuDecIntValidtor::fceuDecIntValidtor( int min, int max, QObject *parent)
|
||||
: QValidator(parent)
|
||||
{
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
QValidator::State fceuDecIntValidtor::validate(QString &input, int &pos) const
|
||||
{
|
||||
int i, v;
|
||||
//printf("Validate: %i '%s'\n", input.size(), input.toStdString().c_str() );
|
||||
|
||||
if ( input.size() == 0 )
|
||||
{
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
std::string s = input.toStdString();
|
||||
i=0;
|
||||
|
||||
if (s[i] == '-')
|
||||
{
|
||||
if ( min >= 0 )
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else if ( s[i] == '+' )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( s[i] == 0 )
|
||||
{
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
if ( isdigit(s[i]) )
|
||||
{
|
||||
while ( isdigit(s[i]) ) i++;
|
||||
|
||||
if ( s[i] == 0 )
|
||||
{
|
||||
v = strtol( s.c_str(), NULL, 0 );
|
||||
|
||||
if ( v < min )
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
else if ( v > max )
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
}
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// ConsoleUtilities.h
|
||||
#include <QValidator>
|
||||
|
||||
int getDirFromFile( const char *path, char *dir );
|
||||
|
||||
|
@ -7,3 +8,15 @@ const char *getRomFile( void );
|
|||
int getFileBaseName( const char *filepath, char *base, char *suffix = NULL );
|
||||
|
||||
int parseFilepath( const char *filepath, char *dir, char *base, char *suffix = NULL );
|
||||
|
||||
|
||||
class fceuDecIntValidtor : public QValidator
|
||||
{
|
||||
public:
|
||||
fceuDecIntValidtor( int min, int max, QObject *parent);
|
||||
|
||||
QValidator::State validate(QString &input, int &pos) const;
|
||||
private:
|
||||
int min;
|
||||
int max;
|
||||
};
|
||||
|
|
|
@ -137,6 +137,8 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent)
|
|||
: QDialog( parent )
|
||||
{
|
||||
int i;
|
||||
int fontCharWidth;
|
||||
fceuDecIntValidtor *validator;
|
||||
QVBoxLayout *mainLayout, *hdrLayout;
|
||||
QVBoxLayout *vbox, *vbox1, *vbox2, *vbox3, *vbox4, *vbox5;
|
||||
QHBoxLayout *hbox, *hbox1, *hbox2, *hbox3;
|
||||
|
@ -146,6 +148,17 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent)
|
|||
|
||||
initOK = false;
|
||||
|
||||
font.setFamily("Courier New");
|
||||
font.setStyle( QFont::StyleNormal );
|
||||
font.setStyleHint( QFont::Monospace );
|
||||
QFontMetrics fm(font);
|
||||
|
||||
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
|
||||
fontCharWidth = fm.horizontalAdvance(QLatin1Char('2'));
|
||||
#else
|
||||
fontCharWidth = fm.width(QLatin1Char('2'));
|
||||
#endif
|
||||
|
||||
setWindowTitle("iNES Header Editor");
|
||||
|
||||
//resize( 512, 512 );
|
||||
|
@ -185,6 +198,14 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent)
|
|||
hbox->addWidget( mapperSubLbl = new QLabel( tr("Sub #:") ) );
|
||||
hbox->addWidget( mapperSubEdit );
|
||||
|
||||
validator = new fceuDecIntValidtor(0, 15, this);
|
||||
|
||||
mapperSubEdit->setFont( font );
|
||||
mapperSubEdit->setMaxLength( 2 );
|
||||
mapperSubEdit->setValidator( validator );
|
||||
mapperSubEdit->setAlignment(Qt::AlignCenter);
|
||||
mapperSubEdit->setMaximumWidth( 4 * fontCharWidth );
|
||||
|
||||
for (i = 0; bmap[i].init; ++i)
|
||||
{
|
||||
sprintf(stmp, "%d %s", bmap[i].number, bmap[i].name);
|
||||
|
@ -403,10 +424,18 @@ iNesHeaderEditor_t::iNesHeaderEditor_t(QWidget *parent)
|
|||
inputDevBox = new QComboBox();
|
||||
miscRomsEdit = new QLineEdit();
|
||||
hdrLayout->addLayout( hbox );
|
||||
hbox->addWidget( miscRomsEdit );
|
||||
hbox->addWidget( miscRomsLbl = new QLabel( tr("Misc. ROM(s)") ) );
|
||||
hbox->addWidget( inputDevLbl = new QLabel( tr("Input Device:") ) );
|
||||
hbox->addWidget( inputDevBox );
|
||||
hbox->addWidget( miscRomsEdit, 1, Qt::AlignLeft );
|
||||
hbox->addWidget( miscRomsLbl = new QLabel( tr("Misc. ROM(s)") ), 10, Qt::AlignLeft);
|
||||
hbox->addWidget( inputDevLbl = new QLabel( tr("Input Device:") ), 1, Qt::AlignRight );
|
||||
hbox->addWidget( inputDevBox, 10, Qt::AlignLeft );
|
||||
|
||||
validator = new fceuDecIntValidtor(0, 3, this);
|
||||
|
||||
miscRomsEdit->setFont( font );
|
||||
miscRomsEdit->setMaxLength( 1 );
|
||||
miscRomsEdit->setValidator( validator );
|
||||
miscRomsEdit->setAlignment(Qt::AlignCenter);
|
||||
miscRomsEdit->setMaximumWidth( 3 * fontCharWidth );
|
||||
|
||||
grid = new QGridLayout();
|
||||
restoreBtn = new QPushButton( tr("Restore") );
|
||||
|
@ -588,11 +617,6 @@ bool iNesHeaderEditor_t::loadHeader(iNES_HEADER* header)
|
|||
|
||||
FCEUFILE* fp = FCEU_fopen(LoadedRomFName, NULL, "rb", NULL);
|
||||
|
||||
//if (!GameInfo)
|
||||
//{
|
||||
// strcpy(LoadedRomFName, fp->fullFilename.c_str());
|
||||
//}
|
||||
|
||||
if (fp)
|
||||
{
|
||||
if (FCEU_fread(header, 1, sizeof(iNES_HEADER), fp) == sizeof(iNES_HEADER) && !memcmp(header, "NES\x1A", 4))
|
||||
|
@ -848,7 +872,7 @@ void iNesHeaderEditor_t::setHeaderData(iNES_HEADER* header)
|
|||
// Sub Mapper
|
||||
sprintf(buf, "%d", ines20 ? header->ROM_type3 >> 4 : 0);
|
||||
|
||||
mapperSubEdit->setText( buf );
|
||||
mapperSubEdit->setText( tr(buf) );
|
||||
|
||||
// PRG ROM
|
||||
int prg_rom = header->ROM_size;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QLabel>
|
||||
#include <QFrame>
|
||||
#include <QGroupBox>
|
||||
#include <QFont>
|
||||
|
||||
#include "Qt/main.h"
|
||||
|
||||
|
@ -32,6 +33,7 @@ class iNesHeaderEditor_t : public QDialog
|
|||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
QFont font;
|
||||
QRadioButton *iNes1Btn;
|
||||
QRadioButton *iNes2Btn;
|
||||
QComboBox *mapperComboBox;
|
||||
|
|
Loading…
Reference in New Issue