Added sizing logic to Qt debugger stack view to resize to display needs.

This commit is contained in:
mjbudd77 2021-07-09 14:15:45 -04:00
parent 1efe2de1f7
commit 37abb7305b
2 changed files with 79 additions and 25 deletions

View File

@ -4831,13 +4831,51 @@ debuggerBookmark_t *debuggerBookmarkManager_t::getAddr( int addr )
DebuggerStackDisplay::DebuggerStackDisplay(QWidget *parent) DebuggerStackDisplay::DebuggerStackDisplay(QWidget *parent)
: QPlainTextEdit(parent) : QPlainTextEdit(parent)
{ {
QFontMetrics fm(font());
stackBytesPerLine = 4; stackBytesPerLine = 4;
showAddrs = true; showAddrs = true;
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
pxCharWidth = fm.horizontalAdvance(QLatin1Char('2'));
#else
pxCharWidth = fm.width(QLatin1Char('2'));
#endif
pxLineSpacing = fm.lineSpacing();
recalcCharsPerLine();
setMinimumWidth( pxCharWidth * charsPerLine );
setMinimumHeight( pxLineSpacing * 5 );
setMaximumHeight( pxLineSpacing * 20 );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DebuggerStackDisplay::~DebuggerStackDisplay(void) DebuggerStackDisplay::~DebuggerStackDisplay(void)
{ {
}
//----------------------------------------------------------------------------
void DebuggerStackDisplay::setFont( const QFont &font )
{
QFontMetrics fm(font);
QPlainTextEdit::setFont(font);
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
pxCharWidth = fm.horizontalAdvance(QLatin1Char('2'));
#else
pxCharWidth = fm.width(QLatin1Char('2'));
#endif
pxLineSpacing = fm.lineSpacing();
setMinimumWidth( pxCharWidth * charsPerLine );
setMinimumHeight( pxLineSpacing * 5 );
setMaximumHeight( pxLineSpacing * 20 );
}
//----------------------------------------------------------------------------
void DebuggerStackDisplay::recalcCharsPerLine(void)
{
charsPerLine = (showAddrs ? 5 : 1) + (stackBytesPerLine*3);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void DebuggerStackDisplay::keyPressEvent(QKeyEvent *event) void DebuggerStackDisplay::keyPressEvent(QKeyEvent *event)
@ -4847,11 +4885,14 @@ void DebuggerStackDisplay::keyPressEvent(QKeyEvent *event)
if ( (event->key() >= Qt::Key_1) && ( (event->key() < Qt::Key_9) ) ) if ( (event->key() >= Qt::Key_1) && ( (event->key() < Qt::Key_9) ) )
{ {
stackBytesPerLine = event->key() - Qt::Key_0; stackBytesPerLine = event->key() - Qt::Key_0;
recalcCharsPerLine();
updateText(); updateText();
} }
else if ( event->key() == Qt::Key_A ) else if ( event->key() == Qt::Key_A )
{ {
showAddrs = !showAddrs; showAddrs = !showAddrs;
recalcCharsPerLine();
updateText(); updateText();
} }
} }
@ -4902,6 +4943,7 @@ void DebuggerStackDisplay::contextMenuEvent(QContextMenuEvent *event)
void DebuggerStackDisplay::toggleShowAddr(void) void DebuggerStackDisplay::toggleShowAddr(void)
{ {
showAddrs = !showAddrs; showAddrs = !showAddrs;
recalcCharsPerLine();
updateText(); updateText();
} }
@ -4909,24 +4951,28 @@ void DebuggerStackDisplay::toggleShowAddr(void)
void DebuggerStackDisplay::sel1BytePerLine(void) void DebuggerStackDisplay::sel1BytePerLine(void)
{ {
stackBytesPerLine = 1; stackBytesPerLine = 1;
recalcCharsPerLine();
updateText(); updateText();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void DebuggerStackDisplay::sel2BytesPerLine(void) void DebuggerStackDisplay::sel2BytesPerLine(void)
{ {
stackBytesPerLine = 2; stackBytesPerLine = 1;
recalcCharsPerLine();
updateText(); updateText();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void DebuggerStackDisplay::sel3BytesPerLine(void) void DebuggerStackDisplay::sel3BytesPerLine(void)
{ {
stackBytesPerLine = 3; stackBytesPerLine = 3;
recalcCharsPerLine();
updateText(); updateText();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void DebuggerStackDisplay::sel4BytesPerLine(void) void DebuggerStackDisplay::sel4BytesPerLine(void)
{ {
stackBytesPerLine = 4; stackBytesPerLine = 4;
recalcCharsPerLine();
updateText(); updateText();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -4946,7 +4992,7 @@ void DebuggerStackDisplay::updateText(void)
} }
else else
{ {
sprintf( stmp, " %02X", GetMem(stackPtr) ); sprintf( stmp, "%02X", GetMem(stackPtr) );
} }
stackLine.assign( stmp ); stackLine.assign( stmp );
@ -4968,7 +5014,7 @@ void DebuggerStackDisplay::updateText(void)
} }
else else
{ {
sprintf( stmp, "\n %02X", GetMem(stackPtr) ); sprintf( stmp, "\n%02X", GetMem(stackPtr) );
} }
} }
else else
@ -4987,5 +5033,8 @@ void DebuggerStackDisplay::updateText(void)
} }
setPlainText( tr(stackLine.c_str()) ); setPlainText( tr(stackLine.c_str()) );
setMinimumWidth( pxCharWidth * charsPerLine );
setMinimumHeight( pxLineSpacing * 5 );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -204,15 +204,20 @@ class DebuggerStackDisplay : public QPlainTextEdit
~DebuggerStackDisplay(void); ~DebuggerStackDisplay(void);
void updateText(void); void updateText(void);
void setFont( const QFont &font );
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
void recalcCharsPerLine(void);
int pxCharWidth;
int pxLineSpacing;
int charsPerLine;
int stackBytesPerLine; int stackBytesPerLine;
bool showAddrs; bool showAddrs;
private slots: public slots:
void toggleShowAddr(void); void toggleShowAddr(void);
void sel1BytePerLine(void); void sel1BytePerLine(void);
void sel2BytesPerLine(void); void sel2BytesPerLine(void);