Fixed inverted vertical scroll on Qt Trace logger. Added page up/down key shortcuts for Trace logger viewport.

This commit is contained in:
mjbudd77 2022-01-15 20:06:10 -05:00
parent 77c946734a
commit bb4b88d00e
2 changed files with 89 additions and 1 deletions

View File

@ -39,6 +39,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QShortcut>
#include <QPainter> #include <QPainter>
#include <QGuiApplication> #include <QGuiApplication>
@ -152,6 +153,7 @@ TraceLoggerDialog_t::TraceLoggerDialog_t(QWidget *parent)
QAction *act; QAction *act;
QLabel *lbl; QLabel *lbl;
int opt, useNativeMenuBar; int opt, useNativeMenuBar;
QShortcut *shortcut;
if (recBufMax == 0) if (recBufMax == 0)
{ {
@ -198,6 +200,12 @@ TraceLoggerDialog_t::TraceLoggerDialog_t(QWidget *parent)
connect(hbar, SIGNAL(valueChanged(int)), this, SLOT(hbarChanged(int))); connect(hbar, SIGNAL(valueChanged(int)), this, SLOT(hbarChanged(int)));
connect(vbar, SIGNAL(valueChanged(int)), this, SLOT(vbarChanged(int))); connect(vbar, SIGNAL(valueChanged(int)), this, SLOT(vbarChanged(int)));
connect(vbar, SIGNAL(actionTriggered(int)), this, SLOT(vbarActionTriggered(int)));
shortcut = new QShortcut( QKeySequence("Page Up"), this );
connect( shortcut, SIGNAL(activated(void)), this, SLOT(pageUpActivated(void)) );
shortcut = new QShortcut( QKeySequence("Page Down"), this );
connect( shortcut, SIGNAL(activated(void)), this, SLOT(pageDnActivated(void)) );
traceView->setScrollBars(hbar, vbar); traceView->setScrollBars(hbar, vbar);
traceView->setMinimumHeight(256); traceView->setMinimumHeight(256);
@ -619,6 +627,81 @@ void TraceLoggerDialog_t::vbarChanged(int val)
traceView->update(); traceView->update();
} }
//---------------------------------------------------- //----------------------------------------------------
void TraceLoggerDialog_t::vbarActionTriggered(int act)
{
int val = vbar->value();
int max = vbar->maximum();
if ( act == QAbstractSlider::SliderSingleStepAdd )
{
val = val - vbar->singleStep();
if ( val < 0 )
{
val = 0;
}
vbar->setSliderPosition(val);
}
else if ( act == QAbstractSlider::SliderSingleStepSub )
{
val = val + vbar->singleStep();
if ( val > max )
{
val = max;
}
vbar->setSliderPosition(val);
}
else if ( act == QAbstractSlider::SliderPageStepAdd )
{
val = val - vbar->pageStep();
if ( val < 0 )
{
val = 0;
}
vbar->setSliderPosition(val);
}
else if ( act == QAbstractSlider::SliderPageStepSub )
{
val = val + vbar->pageStep();
if ( val > max )
{
val = max;
}
vbar->setSliderPosition(val);
}
//printf("ACT:%i\n", act);
}
//----------------------------------------------------
void TraceLoggerDialog_t::pageUpActivated(void)
{
int val = vbar->value();
int max = vbar->maximum();
val = val + vbar->pageStep();
if ( val > max )
{
val = max;
}
vbar->setSliderPosition(val);
}
//----------------------------------------------------
void TraceLoggerDialog_t::pageDnActivated(void)
{
int val = vbar->value();
val = val - vbar->pageStep();
if ( val < 0 )
{
val = 0;
}
vbar->setSliderPosition(val);
}
//----------------------------------------------------
void TraceLoggerDialog_t::logToFileStateChanged(int state) void TraceLoggerDialog_t::logToFileStateChanged(int state)
{ {
g_config->setOption("SDL.TraceLogSaveToFile", state != Qt::Unchecked ); g_config->setOption("SDL.TraceLogSaveToFile", state != Qt::Unchecked );
@ -2220,7 +2303,9 @@ void QTraceLogView::paintEvent(QPaintEvent *event)
nrow = (viewHeight / pxLineSpacing); nrow = (viewHeight / pxLineSpacing);
if (nrow < 1) if (nrow < 1)
{
nrow = 1; nrow = 1;
}
viewLines = nrow; viewLines = nrow;
@ -2237,7 +2322,7 @@ void QTraceLogView::paintEvent(QPaintEvent *event)
else else
{ {
vbar->setMaximum( recBufNum - viewLines ); vbar->setMaximum( recBufNum - viewLines );
vbar->setPageStep( viewLines ); vbar->setPageStep( (viewLines*7)/8 );
vbar->show(); vbar->show();
} }

View File

@ -221,6 +221,9 @@ private slots:
void logMaxLinesChanged(int index); void logMaxLinesChanged(int index);
void hbarChanged(int value); void hbarChanged(int value);
void vbarChanged(int value); void vbarChanged(int value);
void vbarActionTriggered(int value);
void pageUpActivated(void);
void pageDnActivated(void);
void openLogFile(void); void openLogFile(void);
void clearLog(void); void clearLog(void);
}; };