Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "natural" scrolling support for trackpads #5510

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,22 @@ void MidiClipView::wheelEvent(QWheelEvent * we)
}

Note * n = m_clip->noteAtStep( step );
if(!n && we->angleDelta().y() > 0)
int direction = we->angleDelta().y() > 0 ? 1 : -1;
#if QT_VERSION >= 0x050700
if (we->inverted()) {
tresf marked this conversation as resolved.
Show resolved Hide resolved
// Handle "natural" scrolling, which is common on trackpads and touch devices
direction = -direction;
}
#endif
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
9 changes: 8 additions & 1 deletion src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3774,7 +3774,14 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
}
if( nv.size() > 0 )
{
const int step = we->angleDelta().y() > 0 ? 1 : -1;
int step = we->angleDelta().y() > 0 ? 1 : -1;
#if QT_VERSION >= 0x050700
if (we->inverted()) {
tresf marked this conversation as resolved.
Show resolved Hide resolved
// Handle "natural" scrolling, which is common on trackpads and touch devices
step = -step;
}
#endif

if( m_noteEditMode == NoteEditMode::Volume )
{
for ( Note * n : nv )
Expand Down
9 changes: 8 additions & 1 deletion src/gui/widgets/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ void ComboBox::wheelEvent( QWheelEvent* event )
{
if( model() )
{
model()->setInitValue(model()->value() + ((event->angleDelta().y() < 0) ? 1 : -1));
int direction = event->angleDelta().y() < 0 ? 1 : -1;
#if QT_VERSION >= 0x050700
tresf marked this conversation as resolved.
Show resolved Hide resolved
if (event->inverted()) {
// Handle "natural" scrolling, which is common on trackpads and touch devices
direction = -direction;
}
#endif
model()->setInitValue(model()->value() + direction);
update();
event->accept();
}
Expand Down
15 changes: 8 additions & 7 deletions src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,16 @@ void Fader::mouseReleaseEvent(QMouseEvent* mouseEvent)
void Fader::wheelEvent (QWheelEvent* ev)
{
ev->accept();
int direction = ev->angleDelta().y() > 0 ? 1 : -1;

if (ev->angleDelta().y() > 0)
{
model()->incValue(1);
}
else
{
model()->incValue(-1);
#if QT_VERSION >= 0x050700
tresf marked this conversation as resolved.
Show resolved Hide resolved
if (ev->inverted()) {
// Handle "natural" scrolling, which is common on trackpads and touch devices
direction = -direction;
}
#endif

model()->incValue(direction);
updateTextFloat();
s_textFloat->setVisibilityTimeOut(1000);
}
Expand Down
7 changes: 7 additions & 0 deletions src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
}
}

#if QT_VERSION >= 0x050700
tresf marked this conversation as resolved.
Show resolved Hide resolved
// Handle "natural" scrolling, which is common on trackpads and touch devices
if (we->inverted()) {
direction = -direction;
}
#endif

// 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
11 changes: 10 additions & 1 deletion src/gui/widgets/LcdSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ void LcdSpinBox::mouseReleaseEvent(QMouseEvent*)
void LcdSpinBox::wheelEvent(QWheelEvent * we)
{
we->accept();
model()->setValue(model()->value() + ((we->angleDelta().y() > 0) ? 1 : -1) * model()->step<int>());
int direction = we->angleDelta().y() > 0 ? 1 : -1;

tresf marked this conversation as resolved.
Show resolved Hide resolved
#if QT_VERSION >= 0x050700
if (we->inverted()) {
// Handle "natural" scrolling, which is common on trackpads and touch devices
direction = -direction;
}
#endif

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

Expand Down
Loading