From 309f417c6d9fcd8d9da6cc3d4a8c39acff60963a Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Thu, 30 Dec 2021 20:16:25 -0500 Subject: [PATCH] Custom vertical scroll wheel event modifications for robustness. --- src/drivers/Qt/ConsoleDebugger.cpp | 55 ++++++++++++++++++++---------- src/drivers/Qt/ConsoleDebugger.h | 1 + src/drivers/Qt/HexEditor.cpp | 54 +++++++++++++++++++---------- src/drivers/Qt/HexEditor.h | 1 + src/drivers/Qt/RamSearch.cpp | 53 +++++++++++++++++++--------- src/drivers/Qt/RamSearch.h | 7 ++-- 6 files changed, 115 insertions(+), 56 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index c45e7971..9198056b 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -4814,6 +4814,7 @@ QAsmView::QAsmView(QWidget *parent) cursorLineAddr = -1; wheelPixelCounter = 0; + wheelAngleCounter = 0; //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding ); setFocusPolicy(Qt::StrongFocus); @@ -5899,6 +5900,7 @@ void QAsmView::mousePressEvent(QMouseEvent * event) //---------------------------------------------------------------------------- void QAsmView::wheelEvent(QWheelEvent *event) { + int zDelta = 0; QPoint numPixels = event->pixelDelta(); QPoint numDegrees = event->angleDelta(); @@ -5907,42 +5909,59 @@ void QAsmView::wheelEvent(QWheelEvent *event) { wheelPixelCounter -= numPixels.y(); //printf("numPixels: (%i,%i) \n", numPixels.x(), numPixels.y() ); + + if ( wheelPixelCounter >= pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } + else if ( wheelPixelCounter <= -pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } } else if (!numDegrees.isNull()) { + int stepDeg = 120; //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*8); + wheelAngleCounter -= numDegrees.y(); + + if ( wheelAngleCounter <= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } + else if ( wheelAngleCounter >= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } } //printf("Wheel Event: %i\n", wheelPixelCounter); - if ( wheelPixelCounter >= pxLineSpacing ) + if ( zDelta != 0 ) { - lineOffset += (wheelPixelCounter / pxLineSpacing); - - if ( lineOffset > maxLineOffset ) - { - lineOffset = maxLineOffset; - } - vbar->setValue( lineOffset ); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; - } - else if ( wheelPixelCounter <= -pxLineSpacing ) - { - lineOffset += (wheelPixelCounter / pxLineSpacing); + lineOffset += zDelta; if ( lineOffset < 0 ) { lineOffset = 0; } + else if ( lineOffset > maxLineOffset ) + { + lineOffset = maxLineOffset; + } vbar->setValue( lineOffset ); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; } - event->accept(); + event->accept(); } //---------------------------------------------------------------------------- void QAsmView::contextMenuEvent(QContextMenuEvent *event) diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 3dd3baf8..4c4a3978 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -247,6 +247,7 @@ class QAsmView : public QWidget int txtHlgtEndLine; int wheelPixelCounter; + int wheelAngleCounter; dbg_asm_entry_t *asmPC; std::vector asmEntry; diff --git a/src/drivers/Qt/HexEditor.cpp b/src/drivers/Qt/HexEditor.cpp index 37e2f1c5..b58454f4 100644 --- a/src/drivers/Qt/HexEditor.cpp +++ b/src/drivers/Qt/HexEditor.cpp @@ -1963,6 +1963,7 @@ QHexEdit::QHexEdit(QWidget *parent) frzIdx = 0; wheelPixelCounter = 0; + wheelAngleCounter = 0; highLightColor[ 0].setRgb( 0x00, 0x00, 0x00 ); highLightColor[ 1].setRgb( 0x35, 0x40, 0x00 ); @@ -2931,6 +2932,7 @@ void QHexEdit::mouseReleaseEvent(QMouseEvent * event) //---------------------------------------------------------------------------- void QHexEdit::wheelEvent(QWheelEvent *event) { + int zDelta = 0; QPoint numPixels = event->pixelDelta(); QPoint numDegrees = event->angleDelta(); @@ -2939,42 +2941,58 @@ void QHexEdit::wheelEvent(QWheelEvent *event) { wheelPixelCounter -= numPixels.y(); //printf("numPixels: (%i,%i) \n", numPixels.x(), numPixels.y() ); + if ( wheelPixelCounter >= pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } + else if ( wheelPixelCounter <= -pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } } else if (!numDegrees.isNull()) { + int stepDeg = 120; //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*8); + wheelAngleCounter -= numDegrees.y(); + + if ( wheelAngleCounter <= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } + else if ( wheelAngleCounter >= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } } //printf("Wheel Event: %i\n", wheelPixelCounter); - if ( wheelPixelCounter >= pxLineSpacing ) + if ( zDelta != 0 ) { - lineOffset += (wheelPixelCounter / pxLineSpacing); - - if ( lineOffset > maxLineOffset ) - { - lineOffset = maxLineOffset; - } - vbar->setValue( lineOffset ); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; - } - else if ( wheelPixelCounter <= -pxLineSpacing ) - { - lineOffset += (wheelPixelCounter / pxLineSpacing); + lineOffset += zDelta; if ( lineOffset < 0 ) { lineOffset = 0; } + else if ( lineOffset > maxLineOffset ) + { + lineOffset = maxLineOffset; + } vbar->setValue( lineOffset ); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; } - event->accept(); + event->accept(); } //---------------------------------------------------------------------------- void QHexEdit::contextMenuEvent(QContextMenuEvent *event) diff --git a/src/drivers/Qt/HexEditor.h b/src/drivers/Qt/HexEditor.h index 8016bbd1..74fcf37c 100644 --- a/src/drivers/Qt/HexEditor.h +++ b/src/drivers/Qt/HexEditor.h @@ -226,6 +226,7 @@ class QHexEdit : public QWidget int frzRamMode; int frzIdx; int wheelPixelCounter; + int wheelAngleCounter; int txtHlgtAnchorChar; int txtHlgtAnchorLine; int txtHlgtStartChar; diff --git a/src/drivers/Qt/RamSearch.cpp b/src/drivers/Qt/RamSearch.cpp index b14635fe..d76d674d 100644 --- a/src/drivers/Qt/RamSearch.cpp +++ b/src/drivers/Qt/RamSearch.cpp @@ -1614,6 +1614,7 @@ QRamSearchView::QRamSearchView(QWidget *parent) selLine = -1; wheelPixelCounter = 0; + wheelAngleCounter = 0; setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); setFocusPolicy(Qt::StrongFocus); @@ -1772,6 +1773,7 @@ void QRamSearchView::mousePressEvent(QMouseEvent *event) //---------------------------------------------------------------------------- void QRamSearchView::wheelEvent(QWheelEvent *event) { + int zDelta = 0; QPoint numPixels = event->pixelDelta(); QPoint numDegrees = event->angleDelta(); @@ -1780,39 +1782,56 @@ void QRamSearchView::wheelEvent(QWheelEvent *event) { wheelPixelCounter -= numPixels.y(); //printf("numPixels: (%i,%i) \n", numPixels.x(), numPixels.y() ); + + if ( wheelPixelCounter >= pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } + else if ( wheelPixelCounter <= -pxLineSpacing ) + { + zDelta = (wheelPixelCounter / pxLineSpacing); + + wheelPixelCounter = wheelPixelCounter % pxLineSpacing; + } } else if (!numDegrees.isNull()) { + int stepDeg = 120; //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 * 8); + wheelAngleCounter -= numDegrees.y(); + + if ( wheelAngleCounter <= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } + else if ( wheelAngleCounter >= stepDeg ) + { + zDelta = wheelAngleCounter / stepDeg; + + wheelAngleCounter = wheelAngleCounter % stepDeg; + } } //printf("Wheel Event: %i\n", wheelPixelCounter); - if (wheelPixelCounter >= pxLineSpacing) + if (zDelta != 0) { - lineOffset += (wheelPixelCounter / pxLineSpacing); - - if (lineOffset > maxLineOffset) - { - lineOffset = maxLineOffset; - } - vbar->setValue(lineOffset); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; - } - else if (wheelPixelCounter <= -pxLineSpacing) - { - lineOffset += (wheelPixelCounter / pxLineSpacing); + lineOffset += zDelta; if (lineOffset < 0) { lineOffset = 0; } + else if (lineOffset > maxLineOffset) + { + lineOffset = maxLineOffset; + } vbar->setValue(lineOffset); - - wheelPixelCounter = wheelPixelCounter % pxLineSpacing; } event->accept(); diff --git a/src/drivers/Qt/RamSearch.h b/src/drivers/Qt/RamSearch.h index 3e60056d..a8036b19 100644 --- a/src/drivers/Qt/RamSearch.h +++ b/src/drivers/Qt/RamSearch.h @@ -29,7 +29,7 @@ class QRamSearchView : public QWidget void setScrollBars( QScrollBar *hbar, QScrollBar *vbar ); - int getSelAddr(void){ return selAddr; } + int getSelAddr(void){ return selAddr; } protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); @@ -58,9 +58,10 @@ class QRamSearchView : public QWidget int viewLines; int viewWidth; int viewHeight; - int selAddr; - int selLine; + int selAddr; + int selLine; int wheelPixelCounter; + int wheelAngleCounter; }; class RamSearchDialog_t : public QDialog