Fix LcdFloatSpinBox mouse behavior and negative values (#6923)
* Fix LcdFloatSpinBox mouse behavior and negative values
This commit is contained in:
@@ -49,6 +49,12 @@ public:
|
||||
}
|
||||
|
||||
void setLabel(const QString &label) { m_label = label; }
|
||||
|
||||
void setSeamless(bool left, bool right)
|
||||
{
|
||||
m_wholeDisplay.setSeamless(left, true);
|
||||
m_fractionDisplay.setSeamless(true, right);
|
||||
}
|
||||
|
||||
public slots:
|
||||
virtual void update();
|
||||
|
||||
@@ -49,8 +49,9 @@ public:
|
||||
|
||||
~LcdWidget() override;
|
||||
|
||||
void setValue( int value );
|
||||
void setLabel( const QString& label );
|
||||
void setValue(int value);
|
||||
void setValue(float value);
|
||||
void setLabel(const QString& label);
|
||||
|
||||
void addTextForValue( int value, const QString& text )
|
||||
{
|
||||
|
||||
@@ -109,11 +109,16 @@ void LcdFloatSpinBox::layoutSetup(const QString &style)
|
||||
|
||||
void LcdFloatSpinBox::update()
|
||||
{
|
||||
const int whole = static_cast<int>(model()->value());
|
||||
const float fraction = model()->value() - whole;
|
||||
const int intFraction = fraction * std::pow(10.f, m_fractionDisplay.numDigits());
|
||||
m_wholeDisplay.setValue(whole);
|
||||
m_fractionDisplay.setValue(intFraction);
|
||||
const int digitValue = std::pow(10.f, m_fractionDisplay.numDigits());
|
||||
float value = model()->value();
|
||||
int fraction = std::abs(std::round((value - static_cast<int>(value)) * digitValue));
|
||||
if (fraction == digitValue)
|
||||
{
|
||||
value += std::copysign(1, value);
|
||||
fraction = 0;
|
||||
}
|
||||
m_wholeDisplay.setValue(value);
|
||||
m_fractionDisplay.setValue(fraction);
|
||||
|
||||
QWidget::update();
|
||||
}
|
||||
@@ -129,6 +134,9 @@ void LcdFloatSpinBox::contextMenuEvent(QContextMenuEvent* event)
|
||||
|
||||
void LcdFloatSpinBox::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
// switch between integer and fractional step based on cursor position
|
||||
m_intStep = event->x() < m_wholeDisplay.width();
|
||||
|
||||
if (event->button() == Qt::LeftButton &&
|
||||
!(event->modifiers() & Qt::ControlModifier) &&
|
||||
event->y() < m_wholeDisplay.cellHeight() + 2)
|
||||
@@ -152,10 +160,6 @@ void LcdFloatSpinBox::mousePressEvent(QMouseEvent* event)
|
||||
|
||||
void LcdFloatSpinBox::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
// switch between integer and fractional step based on cursor position
|
||||
if (event->x() < m_wholeDisplay.width()) { m_intStep = true; }
|
||||
else { m_intStep = false; }
|
||||
|
||||
if (m_mouseMoving)
|
||||
{
|
||||
int dy = event->globalY() - m_origMousePos.y();
|
||||
|
||||
@@ -94,6 +94,22 @@ void LcdWidget::setValue(int value)
|
||||
update();
|
||||
}
|
||||
|
||||
void LcdWidget::setValue(float value)
|
||||
{
|
||||
if (value < 0 && value > -1)
|
||||
{
|
||||
QString s = QString::number(static_cast<int>(value));
|
||||
s.prepend('-');
|
||||
|
||||
m_display = s;
|
||||
update();
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(static_cast<int>(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user