From 43f87541b6e25b401e4f209cd629b0d34a47401b Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 13 Nov 2020 13:31:04 -0500 Subject: [PATCH] Added mouse wheel scrolling capability for Qt debugger ASM viewer. --- src/drivers/Qt/ConsoleDebugger.cpp | 52 ++++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleDebugger.h | 3 ++ 2 files changed, 55 insertions(+) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index ddb28ba1..5653410d 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -2837,6 +2837,8 @@ QAsmView::QAsmView(QWidget *parent) selAddrValue = -1; memset( selAddrText, 0, sizeof(selAddrText) ); + wheelPixelCounter = 0; + //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding ); setFocusPolicy(Qt::StrongFocus); @@ -3251,6 +3253,8 @@ void QAsmView::mousePressEvent(QMouseEvent * event) line = lineOffset + c.y(); + //printf("Mouse Button Pressed: 0x%x (%i,%i)\n", event->button(), c.x(), c.y() ); + if ( event->button() == Qt::LeftButton ) { //printf("Left Button Pressed: (%i,%i)\n", c.x(), c.y() ); @@ -3399,6 +3403,54 @@ void QAsmView::mousePressEvent(QMouseEvent * event) } } //---------------------------------------------------------------------------- +void QAsmView::wheelEvent(QWheelEvent *event) +{ + + QPoint numPixels = event->pixelDelta(); + QPoint numDegrees = event->angleDelta() / 8; + + if (!numPixels.isNull()) + { + wheelPixelCounter += numPixels.y(); + //printf("numPixels: (%i,%i) \n", numPixels.x(), numPixels.y() ); + } + else if (!numDegrees.isNull()) + { + //QPoint numSteps = numDegrees / 15; + //printf("numSteps: (%i,%i) \n", numSteps.x(), numSteps.y() ); + //printf("numDegrees: (%i,%i) %i\n", numDegrees.x(), numDegrees.y(), pxLineSpacing ); + wheelPixelCounter += (pxLineSpacing * numDegrees.y()) / 15; + } + //printf("Wheel Event: %i\n", wheelPixelCounter); + + if ( wheelPixelCounter >= pxLineSpacing ) + { + lineOffset += (wheelPixelCounter / pxLineSpacing); + + if ( lineOffset > maxLineOffset ) + { + lineOffset = maxLineOffset; + } + vbar->setValue( lineOffset ); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } + else if ( wheelPixelCounter <= -pxLineSpacing ) + { + lineOffset += (wheelPixelCounter / pxLineSpacing); + + if ( lineOffset < 0 ) + { + lineOffset = 0; + } + vbar->setValue( lineOffset ); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } + + event->accept(); +} +//---------------------------------------------------------------------------- void QAsmView::contextMenuEvent(QContextMenuEvent *event) { int line; diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index f8b51a07..e35e1c03 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -120,6 +120,7 @@ class QAsmView : public QWidget void mouseReleaseEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event); void resizeEvent(QResizeEvent *event); + void wheelEvent(QWheelEvent *event); void contextMenuEvent(QContextMenuEvent *event); void loadHighlightToClipboard(void); @@ -167,6 +168,8 @@ class QAsmView : public QWidget int txtHlgtEndChar; int txtHlgtEndLine; + int wheelPixelCounter; + dbg_asm_entry_t *asmPC; std::vector asmEntry;