@@ -329,7 +329,10 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
329329 }
330330
331331 // Compute the number of steps but make sure that we always do at least one step
332- const float stepMult = std::max (range / numberOfStepsForFullSweep / step, 1 .f );
332+ const float currentValue = model ()->value ();
333+ const float valueOffset = range / numberOfStepsForFullSweep;
334+ const float scaledValueOffset = model ()->scaledValue (model ()->inverseScaledValue (currentValue) + valueOffset) - currentValue;
335+ const float stepMult = std::max (scaledValueOffset / step, 1 .f );
333336 const int inc = direction * stepMult;
334337 model ()->incValue (inc);
335338
@@ -343,40 +346,26 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
343346
344347void FloatModelEditorBase::setPosition (const QPoint & p)
345348{
346- const float value = getValue (p) + m_leftOver;
349+ const float valueOffset = getValue (p) + m_leftOver;
350+ const float currentValue = model ()->value ();
351+ const float scaledValueOffset = currentValue - model ()->scaledValue (model ()->inverseScaledValue (currentValue) - valueOffset);
347352 const auto step = model ()->step <float >();
348- const float oldValue = model ()-> value () ;
353+ const float roundedValue = std::round ((currentValue - scaledValueOffset) / step) * step ;
349354
350- if (model ()-> isScaleLogarithmic ()) // logarithmic code
355+ if (! approximatelyEqual (roundedValue, currentValue))
351356 {
352- const float pos = model ()->minValue () < 0
353- ? oldValue / qMax (qAbs (model ()->maxValue ()), qAbs (model ()->minValue ()))
354- : (oldValue - model ()->minValue ()) / model ()->range ();
355- const float ratio = 0 .1f + qAbs (pos) * 15 .f ;
356- float newValue = value * ratio;
357- if (qAbs (newValue) >= step)
358- {
359- float roundedValue = qRound ((oldValue - value) / step) * step;
360- model ()->setValue (roundedValue);
361- m_leftOver = 0 .0f ;
362- }
363- else
364- {
365- m_leftOver = value;
366- }
357+ model ()->setValue (roundedValue);
358+ m_leftOver = 0 .0f ;
367359 }
368-
369- else // linear code
360+ else
370361 {
371- if (qAbs (value) >= step )
362+ if (valueOffset > 0 && approximatelyEqual (currentValue, model ()-> minValue ()) )
372363 {
373- float roundedValue = qRound ((oldValue - value) / step) * step;
374- model ()->setValue (roundedValue);
375364 m_leftOver = 0 .0f ;
376365 }
377366 else
378367 {
379- m_leftOver = value ;
368+ m_leftOver = valueOffset ;
380369 }
381370 }
382371}
0 commit comments