For Qt GUI nametable viewer: added option to have click or hover tile focus policy. Fixed a few screen refresh issues when emulator is paused. Fixed a few sync issues between window state and indicated menu settings.

This commit is contained in:
mjbudd77 2021-01-30 14:16:31 -05:00
parent ec9da639f5
commit 8bf49b193d
2 changed files with 129 additions and 15 deletions

View File

@ -120,7 +120,7 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent)
QGroupBox *frame;
QMenuBar *menuBar;
QMenu *viewMenu, *colorMenu, *subMenu;
QAction *act, *zoomAct[4], *rateAct[5];
QAction *act;
QActionGroup *group;
QLabel *lbl;
QFont font;
@ -158,17 +158,28 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent)
viewMenu->addAction(act);
// View -> Show Grid Lines
// View -> Show Tile Grid
act = new QAction(tr("Show Tile Grid"), this);
//act->setShortcut(QKeySequence::Open);
act->setCheckable(true);
act->setChecked(drawTileGridLines);
act->setStatusTip(tr("Show Tile Grid"));
connect(act, SIGNAL(triggered(bool)), this, SLOT(menuGridLinesChanged(bool)) );
connect(act, SIGNAL(triggered(bool)), this, SLOT(menuTileGridLinesChanged(bool)) );
showTileGridAct = act;
viewMenu->addAction(act);
// View -> Show Attr Grid
act = new QAction(tr("Show Attr Grid"), this);
//act->setShortcut(QKeySequence::Open);
act->setCheckable(true);
act->setChecked(drawAttrGridLines);
act->setStatusTip(tr("Show Attr Grid"));
connect(act, SIGNAL(triggered(bool)), this, SLOT(menuAttrGridLinesChanged(bool)) );
showAttrGridAct = act;
viewMenu->addAction(act);
// View -> Show Attributes
act = new QAction(tr("Show Attributes"), this);
//act->setShortcut(QKeySequence::Open);
@ -218,6 +229,27 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent)
viewMenu->addSeparator();
// View -> Tile Focus
subMenu = viewMenu->addMenu( tr("Tile Focus"));
group = new QActionGroup(this);
group->setExclusive(true);
focusAct[0] = new QAction(tr("Click"), this);
focusAct[0]->setCheckable(true);
group->addAction(focusAct[0]);
subMenu->addAction(focusAct[0]);
connect(focusAct[0], SIGNAL(triggered()), this, SLOT(setClickFocus(void)) );
focusAct[1] = new QAction(tr("Hover"), this);
focusAct[1]->setCheckable(true);
focusAct[1]->setChecked(false);
group->addAction(focusAct[1]);
subMenu->addAction(focusAct[1]);
connect(focusAct[1], SIGNAL(triggered()), this, SLOT(setHoverFocus(void)) );
viewMenu->addSeparator();
// View -> Refresh
act = new QAction(tr("Refresh"), this);
act->setShortcut( QKeySequence(tr("F5") ) );
@ -295,6 +327,8 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent)
// End Menu
//-----------------------------------------------------------------------
cycleCount = 0;
setWindowTitle( tr("Name Table Viewer") );
mainLayout = new QHBoxLayout();
@ -452,7 +486,7 @@ ppuNameTableViewerDialog_t::ppuNameTableViewerDialog_t(QWidget *parent)
updateTimer->start( 33 ); // 30hz
updateMirrorText();
updateVisibility();
refreshMenuSelections();
}
//----------------------------------------------------
ppuNameTableViewerDialog_t::~ppuNameTableViewerDialog_t(void)
@ -480,9 +514,11 @@ void ppuNameTableViewerDialog_t::closeWindow(void)
//----------------------------------------------------
void ppuNameTableViewerDialog_t::periodicUpdate(void)
{
cycleCount = (cycleCount + 1) % 30;
updateMirrorText();
if ( redrawtables )
if ( redrawtables || (cycleCount == 0) )
{
this->scrollArea->viewport()->update();
@ -493,21 +529,39 @@ void ppuNameTableViewerDialog_t::periodicUpdate(void)
void ppuNameTableViewerDialog_t::changeZoom1x(void)
{
ntView->setViewScale(1);
refreshMenuSelections();
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::changeZoom2x(void)
{
ntView->setViewScale(2);
refreshMenuSelections();
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::changeZoom3x(void)
{
ntView->setViewScale(3);
refreshMenuSelections();
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::changeZoom4x(void)
{
ntView->setViewScale(4);
refreshMenuSelections();
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::setClickFocus(void)
{
ntView->setHoverFocus(false);
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::setHoverFocus(void)
{
ntView->setHoverFocus(true);
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::changeRate( int divider )
@ -558,9 +612,21 @@ void ppuNameTableViewerDialog_t::forceRefresh(void)
FCEUD_UpdateNTView( -1, true);
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::updateVisibility(void)
void ppuNameTableViewerDialog_t::refreshMenuSelections(void)
{
focusAct[0]->setChecked( !ntView->getHoverFocus() );
focusAct[1]->setChecked( ntView->getHoverFocus() );
zoomAct[0]->setChecked( ntView->getViewScale() == 1 );
zoomAct[1]->setChecked( ntView->getViewScale() == 2 );
zoomAct[2]->setChecked( ntView->getViewScale() == 3 );
zoomAct[3]->setChecked( ntView->getViewScale() == 4 );
rateAct[0]->setChecked( NTViewRefresh == 0 );
rateAct[1]->setChecked( NTViewRefresh == 1 );
rateAct[2]->setChecked( NTViewRefresh == 3 );
rateAct[3]->setChecked( NTViewRefresh == 7 );
rateAct[4]->setChecked( NTViewRefresh == 19 );
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::setPropertyLabels( int TileID, int TileX, int TileY, int NameTable, int PPUAddress, int AttAddress, int Attrib, int palAddr )
@ -653,13 +719,20 @@ void ppuNameTableViewerDialog_t::menuScrollLinesChanged(bool checked)
showScrollLineCbox->setChecked( checked );
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::menuGridLinesChanged(bool checked)
void ppuNameTableViewerDialog_t::menuTileGridLinesChanged(bool checked)
{
drawTileGridLines = checked;
showTileGridCbox->setChecked( checked );
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::menuAttrGridLinesChanged(bool checked)
{
drawAttrGridLines = checked;
showAttrGridCbox->setChecked( checked );
}
//----------------------------------------------------
void ppuNameTableViewerDialog_t::menuAttributesChanged(bool checked)
{
attview = checked;
@ -729,7 +802,7 @@ void ppuNameTableViewerDialog_t::showAttrGridChanged(int state)
{
drawAttrGridLines = (state != Qt::Unchecked);
//showAttrGridAct->setChecked( drawAttrGridLines );
showAttrGridAct->setChecked( drawAttrGridLines );
redrawtables = true;
}
@ -755,7 +828,7 @@ ppuNameTableView_t::ppuNameTableView_t(QWidget *parent)
this->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
this->setFocusPolicy(Qt::StrongFocus);
this->setMouseTracking(true);
viewScale = 2;
viewScale = 1;
viewWidth = 256 * 2 * viewScale;
viewHeight = 240 * 2 * viewScale;
setMinimumWidth( viewWidth );
@ -766,8 +839,9 @@ ppuNameTableView_t::ppuNameTableView_t(QWidget *parent)
viewRect= QRect(0, 0, 512, 480);
selTable = 0;
scrollArea = NULL;
selTable = 0;
scrollArea = NULL;
hover2Focus = false;
tileSelColor.setRgb(255,255,255);
tileGridColor.setRgb(255, 0, 0);
@ -784,6 +858,11 @@ void ppuNameTableView_t::setScrollPointer( QScrollArea *sa )
scrollArea = sa;
}
//----------------------------------------------------
void ppuNameTableView_t::setHoverFocus( bool hoverFocus )
{
hover2Focus = hoverFocus;
}
//----------------------------------------------------
void ppuNameTableView_t::setViewScale( int reqScale )
{
int prevScale;
@ -944,16 +1023,20 @@ void ppuNameTableView_t::computeNameTableProperties( int NameTable, int TileX, i
//----------------------------------------------------
void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
{
if ( event->key() == Qt::Key_Minus )
if ( (event->key() == Qt::Key_Minus) || (event->key() == Qt::Key_Underscore) )
{
setViewScale( viewScale-1 );
parent->refreshMenuSelections();
event->accept();
}
else if ( event->key() == Qt::Key_Plus )
else if ( (event->key() == Qt::Key_Plus) || (event->key() == Qt::Key_Equal) )
{
setViewScale( viewScale+1 );
parent->refreshMenuSelections();
event->accept();
}
else if ( event->key() == Qt::Key_Up )
@ -979,6 +1062,7 @@ void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
computeNameTableProperties( selTable, selTile.x(), selTile.y() );
ensureVis = true;
redrawtables = true;
event->accept();
}
@ -1005,6 +1089,7 @@ void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
computeNameTableProperties( selTable, selTile.x(), selTile.y() );
ensureVis = true;
redrawtables = true;
event->accept();
}
@ -1031,6 +1116,7 @@ void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
computeNameTableProperties( selTable, selTile.x(), selTile.y() );
ensureVis = true;
redrawtables = true;
event->accept();
}
@ -1057,6 +1143,7 @@ void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
computeNameTableProperties( selTable, selTile.x(), selTile.y() );
ensureVis = true;
redrawtables = true;
event->accept();
}
@ -1064,6 +1151,20 @@ void ppuNameTableView_t::keyPressEvent(QKeyEvent *event)
//----------------------------------------------------
void ppuNameTableView_t::mouseMoveEvent(QMouseEvent *event)
{
if ( hover2Focus )
{
int tIdx, tx, ty;
convertXY2TableTile( event->pos().x(), event->pos().y(), &tIdx, &tx, &ty );
selTable = tIdx;
selTile.setX( tx );
selTile.setY( ty );
computeNameTableProperties( tIdx, tx, ty );
redrawtables = true;
}
//printf("MouseMove: (%i,%i) \n", event->pos().x(), event->pos().y() );
}
//----------------------------------------------------------------------------
@ -1085,6 +1186,7 @@ void ppuNameTableView_t::mousePressEvent(QMouseEvent * event)
else if ( event->button() == Qt::RightButton )
{
}
redrawtables = true;
}
//----------------------------------------------------
void ppuNameTableView_t::paintEvent(QPaintEvent *event)

View File

@ -56,6 +56,8 @@ class ppuNameTableView_t : public QWidget
int getViewScale( void ){ return viewScale; };
void setScrollPointer( QScrollArea *sa );
void setHoverFocus( bool hoverFocus );
bool getHoverFocus( void ){ return hover2Focus; };
QColor tileSelColor;
QColor tileGridColor;
@ -81,6 +83,7 @@ class ppuNameTableView_t : public QWidget
QScrollArea *scrollArea;
bool ensureVis;
bool hover2Focus;
};
class ppuNameTableViewerDialog_t : public QDialog
@ -117,16 +120,22 @@ class ppuNameTableViewerDialog_t : public QDialog
QLineEdit *palAddrLbl;
QAction *showScrollLineAct;
QAction *showTileGridAct;
QAction *showAttrGridAct;
QAction *showAttributesAct;
QAction *ignPalAct;
QAction *zoomAct[4];
QAction *rateAct[5];
QAction *focusAct[2];
QLabel *mirrorLbl;
int cycleCount;
public slots:
void closeWindow(void);
void refreshMenuSelections(void);
private slots:
void periodicUpdate(void);
void updateMirrorText(void);
void updateVisibility(void);
void showAttrbChanged(int state);
void ignorePaletteChanged(int state);
void showTileGridChanged(int state);
@ -134,12 +143,15 @@ class ppuNameTableViewerDialog_t : public QDialog
void showScrollLinesChanged(int state);
void scanLineChanged( const QString &txt );
void menuScrollLinesChanged( bool checked );
void menuGridLinesChanged( bool checked );
void menuTileGridLinesChanged( bool checked );
void menuAttrGridLinesChanged( bool checked );
void menuAttributesChanged( bool checked );
void menuIgnPalChanged( bool checked );
void setTileSelectorColor(void);
void setTileGridColor(void);
void setAttrGridColor(void);
void setClickFocus(void);
void setHoverFocus(void);
void changeZoom1x(void);
void changeZoom2x(void);
void changeZoom3x(void);