Skip to content

Commit

Permalink
Add "natural" scrolling support for trackpads (#5510)
Browse files Browse the repository at this point in the history
Adds QWheelEvent::inverted() support to spinboxes, knobs, sliders
  • Loading branch information
tresf authored and Rossmaxx committed May 21, 2024
1 parent cf766b0 commit 8c62b22
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,16 @@ void MidiClipView::wheelEvent(QWheelEvent * we)
}

Note * n = m_clip->noteAtStep( step );
if(!n && we->angleDelta().y() > 0)
const int direction = (we->angleDelta().y() > 0 ? 1 : -1) * (we->inverted() ? -1 : 1);
if(!n && direction > 0)
{
n = m_clip->addStepNote( step );
n->setVolume( 0 );
}
if( n != nullptr )
{
int vol = n->getVolume();

if(we->angleDelta().y() > 0)
if(direction > 0)
{
n->setVolume( qMin( 100, vol + 5 ) );
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3785,7 +3785,8 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
}
if( nv.size() > 0 )
{
const int step = we->angleDelta().y() > 0 ? 1 : -1;
const int step = (we->angleDelta().y() > 0 ? 1 : -1) * (we->inverted() ? -1 : 1);

if( m_noteEditMode == NoteEditMode::Volume )
{
for ( Note * n : nv )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ void ComboBox::wheelEvent( QWheelEvent* event )
{
if( model() )
{
model()->setInitValue(model()->value() + ((event->angleDelta().y() < 0) ? 1 : -1));
const int direction = (event->angleDelta().y() < 0 ? 1 : -1) * (event->inverted() ? -1 : 1);
model()->setInitValue(model()->value() + direction);
update();
event->accept();
}
Expand Down
10 changes: 2 additions & 8 deletions src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,9 @@ void Fader::mouseReleaseEvent(QMouseEvent* mouseEvent)
void Fader::wheelEvent (QWheelEvent* ev)
{
ev->accept();
const int direction = (ev->angleDelta().y() > 0 ? 1 : -1) * (ev->inverted() ? -1 : 1);

if (ev->angleDelta().y() > 0)
{
model()->incValue(1);
}
else
{
model()->incValue(-1);
}
model()->incValue(direction);
updateTextFloat();
s_textFloat->setVisibilityTimeOut(1000);
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
}
}

// Handle "natural" scrolling, which is common on trackpads and touch devices
if (we->inverted()) {
direction = -direction;
}

// Compute the number of steps but make sure that we always do at least one step
const float stepMult = std::max(range / numberOfStepsForFullSweep / step, 1.f);
const int inc = direction * stepMult;
Expand Down
4 changes: 3 additions & 1 deletion src/gui/widgets/LcdSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ void LcdSpinBox::mouseReleaseEvent(QMouseEvent*)
void LcdSpinBox::wheelEvent(QWheelEvent * we)
{
we->accept();
model()->setValue(model()->value() + ((we->angleDelta().y() > 0) ? 1 : -1) * model()->step<int>());
const int direction = (we->angleDelta().y() > 0 ? 1 : -1) * (we->inverted() ? -1 : 1);

model()->setValue(model()->value() + direction * model()->step<int>());
emit manualChange();
}

Expand Down

0 comments on commit 8c62b22

Please sign in to comment.