Add "natural" scrolling support for trackpads (#5510)
Adds QWheelEvent::inverted() support to spinboxes, knobs, sliders
This commit is contained in:
@@ -332,7 +332,8 @@ 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 );
|
||||
@@ -340,8 +341,7 @@ void MidiClipView::wheelEvent(QWheelEvent * we)
|
||||
if( n != nullptr )
|
||||
{
|
||||
int vol = n->getVolume();
|
||||
|
||||
if(we->angleDelta().y() > 0)
|
||||
if(direction > 0)
|
||||
{
|
||||
n->setVolume( qMin( 100, vol + 5 ) );
|
||||
}
|
||||
|
||||
@@ -3774,7 +3774,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 )
|
||||
|
||||
@@ -220,7 +220,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();
|
||||
}
|
||||
|
||||
@@ -193,15 +193,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);
|
||||
}
|
||||
|
||||
@@ -326,6 +326,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;
|
||||
|
||||
@@ -141,7 +141,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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user