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

Fix Logarithmic Model Dragging Behavior #7647

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
39 changes: 9 additions & 30 deletions src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,41 +346,20 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)

void FloatModelEditorBase::setPosition(const QPoint & p)
{
const float value = getValue(p) + m_leftOver;
const float valueOffset = getValue(p) + m_leftOver;
const float currentValue = model()->value();
const float scaledValueOffset = currentValue - model()->scaledValue(model()->inverseScaledValue(currentValue) - valueOffset);
const auto step = model()->step<float>();
const float oldValue = model()->value();
const float roundedValue = std::round((currentValue - scaledValueOffset) / step) * step;

if (model()->isScaleLogarithmic()) // logarithmic code
if (roundedValue != currentValue)
{
const float pos = model()->minValue() < 0
? oldValue / qMax(qAbs(model()->maxValue()), qAbs(model()->minValue()))
: (oldValue - model()->minValue()) / model()->range();
const float ratio = 0.1f + qAbs(pos) * 15.f;
float newValue = value * ratio;
if (qAbs(newValue) >= step)
{
float roundedValue = qRound((oldValue - value) / step) * step;
model()->setValue(roundedValue);
m_leftOver = 0.0f;
}
else
{
m_leftOver = value;
}
model()->setValue(roundedValue);
m_leftOver = 0.0f;
}

else // linear code
else
{
if (qAbs(value) >= step)
{
float roundedValue = qRound((oldValue - value) / step) * step;
model()->setValue(roundedValue);
m_leftOver = 0.0f;
}
else
{
m_leftOver = value;
}
m_leftOver = valueOffset;
}
}

Expand Down
Loading