Added vertical slider logic.
This commit is contained in:
parent
b6b2038c96
commit
b23349e870
|
@ -144,6 +144,7 @@ HexEditorDialog_t::HexEditorDialog_t(QWidget *parent)
|
|||
: QDialog( parent )
|
||||
{
|
||||
QVBoxLayout *mainLayout;
|
||||
QGridLayout *grid;
|
||||
QMenuBar *menuBar;
|
||||
QMenu *fileMenu;
|
||||
QAction *saveROM;
|
||||
|
@ -173,13 +174,28 @@ HexEditorDialog_t::HexEditorDialog_t(QWidget *parent)
|
|||
//-----------------------------------------------------------------------
|
||||
mainLayout = new QVBoxLayout();
|
||||
|
||||
grid = new QGridLayout(this);
|
||||
editor = new QHexEdit( &mb, this);
|
||||
vbar = new QScrollBar( Qt::Vertical, this );
|
||||
hbar = new QScrollBar( Qt::Horizontal, this );
|
||||
|
||||
mainLayout->setMenuBar( menuBar );
|
||||
mainLayout->addWidget( editor );
|
||||
grid->setMenuBar( menuBar );
|
||||
|
||||
grid->addWidget( editor, 0, 0 );
|
||||
grid->addWidget( vbar , 0, 1 );
|
||||
grid->addWidget( hbar , 1, 0 );
|
||||
mainLayout->addLayout( grid );
|
||||
|
||||
setLayout( mainLayout );
|
||||
|
||||
hbar->setMinimum(0);
|
||||
hbar->setMaximum(100);
|
||||
vbar->setMinimum(0);
|
||||
vbar->setMaximum( 0x10000 / 16 );
|
||||
|
||||
//connect( vbar, SIGNAL(sliderMoved(int)), this, SLOT(vbarMoved(int)) );
|
||||
connect( vbar, SIGNAL(valueChanged(int)), this, SLOT(vbarChanged(int)) );
|
||||
|
||||
mode = MODE_NES_RAM;
|
||||
memAccessFunc = getRAM;
|
||||
redraw = false;
|
||||
|
@ -205,6 +221,18 @@ void HexEditorDialog_t::closeWindow(void)
|
|||
done(0);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void HexEditorDialog_t::vbarMoved(int value)
|
||||
{
|
||||
printf("VBar Moved: %i\n", value);
|
||||
editor->setLine( value );
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void HexEditorDialog_t::vbarChanged(int value)
|
||||
{
|
||||
printf("VBar Changed: %i\n", value);
|
||||
editor->setLine( value );
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void HexEditorDialog_t::setMode(int new_mode)
|
||||
{
|
||||
if ( mode != new_mode )
|
||||
|
@ -331,6 +359,7 @@ QHexEdit::QHexEdit(memBlock_t *blkPtr, QWidget *parent)
|
|||
|
||||
calcFontData();
|
||||
|
||||
lineOffset = 0;
|
||||
cursorPosX = 0;
|
||||
cursorPosY = 0;
|
||||
cursorBlink = true;
|
||||
|
@ -352,10 +381,10 @@ void QHexEdit::calcFontData(void)
|
|||
#else
|
||||
pxCharWidth = metrics.width(QLatin1Char('2'));
|
||||
#endif
|
||||
pxCharHeight = metrics.height();
|
||||
pxCharHeight = metrics.height();
|
||||
pxLineSpacing = metrics.lineSpacing() * 1.25;
|
||||
pxLineLead = pxLineSpacing - pxCharHeight;
|
||||
pxXoffset = pxCharHeight;
|
||||
pxXoffset = pxCharWidth;
|
||||
pxYoffset = pxLineSpacing * 2.0;
|
||||
pxHexOffset = pxXoffset + (7*pxCharWidth);
|
||||
pxHexAscii = pxHexOffset + (16*3*pxCharWidth) + (2*pxCharWidth);
|
||||
|
@ -366,6 +395,11 @@ void QHexEdit::calcFontData(void)
|
|||
//_pxSelectionSub = _pxCharHeight / 5;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void QHexEdit::setLine( int newLineOffset )
|
||||
{
|
||||
lineOffset = newLineOffset;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void QHexEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
printf("Hex Window Key Press: 0x%x \n", event->key() );
|
||||
|
@ -381,6 +415,7 @@ void QHexEdit::keyReleaseEvent(QKeyEvent *event)
|
|||
void QHexEdit::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
int x, y, w, h, row, col, nrow, addr;
|
||||
int maxLines, maxLineOffset;
|
||||
char txt[32];
|
||||
QPainter painter(this);
|
||||
|
||||
|
@ -390,7 +425,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
|
|||
|
||||
//painter.fillRect( 0, 0, w, h, QColor("white") );
|
||||
|
||||
nrow = (h / pxLineSpacing) + 1;
|
||||
nrow = (h / pxLineSpacing);
|
||||
|
||||
if ( nrow < 1 ) nrow = 1;
|
||||
|
||||
|
@ -430,8 +465,16 @@ void QHexEdit::paintEvent(QPaintEvent *event)
|
|||
|
||||
painter.setPen( this->palette().color(QPalette::WindowText));
|
||||
|
||||
maxLines = (mb->size() / 16);
|
||||
maxLineOffset = maxLines - nrow + 2;
|
||||
|
||||
if ( lineOffset > maxLineOffset )
|
||||
{
|
||||
lineOffset = maxLineOffset;
|
||||
}
|
||||
|
||||
//painter.setPen( QColor("white") );
|
||||
addr = 0;
|
||||
addr = lineOffset * 16;
|
||||
y = pxYoffset;
|
||||
|
||||
for ( row=0; row < nrow; row++)
|
||||
|
@ -445,11 +488,15 @@ void QHexEdit::paintEvent(QPaintEvent *event)
|
|||
|
||||
for (col=0; col<16; col++)
|
||||
{
|
||||
sprintf( txt, "%02X", mb->buf[addr+col].data );
|
||||
painter.drawText( x, y, txt );
|
||||
if ( addr < mb->size() )
|
||||
{
|
||||
sprintf( txt, "%02X", mb->buf[addr].data );
|
||||
painter.drawText( x, y, txt );
|
||||
}
|
||||
x += (3*pxCharWidth);
|
||||
addr++;
|
||||
}
|
||||
addr += 16;
|
||||
//addr += 16;
|
||||
y += pxLineSpacing;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ class QHexEdit : public QWidget
|
|||
QHexEdit(memBlock_t *blkPtr, QWidget *parent = 0);
|
||||
~QHexEdit(void);
|
||||
|
||||
void setLine( int newLineOffset );
|
||||
void setAddr( int newAddrOffset );
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
@ -57,6 +59,7 @@ class QHexEdit : public QWidget
|
|||
|
||||
memBlock_t *mb;
|
||||
|
||||
int lineOffset;
|
||||
int pxCharWidth;
|
||||
int pxCharHeight;
|
||||
int pxCursorHeight;
|
||||
|
@ -97,8 +100,10 @@ class HexEditorDialog_t : public QDialog
|
|||
int checkMemActivity(void);
|
||||
int calcVisibleRange( int *start_out, int *end_out, int *center_out );
|
||||
|
||||
QHexEdit *editor;
|
||||
QTimer *periodicTimer;
|
||||
QScrollBar *vbar;
|
||||
QScrollBar *hbar;
|
||||
QHexEdit *editor;
|
||||
QTimer *periodicTimer;
|
||||
|
||||
int mode;
|
||||
//int memSize;
|
||||
|
@ -116,5 +121,7 @@ class HexEditorDialog_t : public QDialog
|
|||
void closeWindow(void);
|
||||
private slots:
|
||||
void updatePeriodic(void);
|
||||
void vbarMoved(int value);
|
||||
void vbarChanged(int value);
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue