Skip to content

Commit

Permalink
freqctrl: accumulate small scroll events
Browse files Browse the repository at this point in the history
For computers with smooth scrolling that issue frequent scroll wheel
events with small deltas.
  • Loading branch information
sultanqasim committed Aug 13, 2023
1 parent 3d633a2 commit d0556d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/qtgui/freqctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ CFreqCtrl::CFreqCtrl(QWidget *parent) :
m_InvertScrolling = false;
m_UnitsFont = QFont("Arial", 12, QFont::Normal);
m_DigitFont = QFont("Arial", 12, QFont::Normal);
m_CumWheelDelta = 0;

setStatusTip(tr(STATUS_TIP));
}
Expand Down Expand Up @@ -492,9 +493,14 @@ void CFreqCtrl::wheelEvent(QWheelEvent *event)
QPointF pt = event->position();
#endif
int delta = m_InvertScrolling ? -event->angleDelta().y() : event->angleDelta().y();
int numDegrees = delta / 8;
m_CumWheelDelta += delta;
int numDegrees = m_CumWheelDelta / 8;
int numSteps = numDegrees / 15;

// accumulate enough wheel deltas to reach at least one step
if (abs(numSteps) == 0)
return;

for (int i = m_DigStart; i < m_NumDigits; i++)
{
if (inRect(m_DigitInfo[i].dQRect, pt)) // if in i'th digit
Expand All @@ -505,6 +511,8 @@ void CFreqCtrl::wheelEvent(QWheelEvent *event)
decFreq();
}
}

m_CumWheelDelta = 0;
}

void CFreqCtrl::keyPressEvent(QKeyEvent *event)
Expand Down
1 change: 1 addition & 0 deletions src/qtgui/freqctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public slots:
int m_LastEditDigit;
int m_DecPos;
int m_NumSeps;
int m_CumWheelDelta;

qint64 m_MinStep;
qint64 m_freq;
Expand Down

0 comments on commit d0556d5

Please sign in to comment.