qskinny/src/controls/QskBoundedValueInput.cpp

75 lines
1.6 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskBoundedValueInput.h"
2017-07-21 18:21:34 +02:00
#include "QskFunctions.h"
QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
2020-07-25 14:19:14 +02:00
: QskBoundedInput( parent )
2017-07-21 18:21:34 +02:00
{
}
QskBoundedValueInput::~QskBoundedValueInput()
2017-07-21 18:21:34 +02:00
{
}
2020-07-25 14:19:14 +02:00
void QskBoundedValueInput::alignInput()
{
2020-07-25 18:46:04 +02:00
auto value = alignedValue( m_value );
value = fixupValue( value );
2017-07-21 18:21:34 +02:00
2020-07-25 18:46:04 +02:00
setValueInternal( value );
2017-07-21 18:21:34 +02:00
}
qreal QskBoundedValueInput::fixupValue( qreal value ) const
2017-07-21 18:21:34 +02:00
{
return value;
2017-07-21 18:21:34 +02:00
}
void QskBoundedValueInput::setValueAsRatio( qreal ratio )
2017-07-21 18:21:34 +02:00
{
ratio = qBound( 0.0, ratio, 1.0 );
2020-07-25 14:19:14 +02:00
setValue( minimum() + ratio * boundaryLength() );
}
qreal QskBoundedValueInput::valueAsRatio() const
{
2020-07-25 14:19:14 +02:00
return ( m_value - minimum() ) / boundaryLength();
2017-07-21 18:21:34 +02:00
}
void QskBoundedValueInput::setValue( qreal value )
2017-07-21 18:21:34 +02:00
{
if ( isComponentComplete() )
{
2020-07-25 14:19:14 +02:00
value = alignedValue( value );
2020-07-25 18:46:04 +02:00
value = fixupValue( value );
2017-07-21 18:21:34 +02:00
}
2020-07-25 18:46:04 +02:00
setValueInternal( value );
2017-07-21 18:21:34 +02:00
}
qreal QskBoundedValueInput::value() const
2017-07-21 18:21:34 +02:00
{
2020-07-25 14:19:14 +02:00
return m_value;
2017-07-21 18:21:34 +02:00
}
2020-07-25 14:19:14 +02:00
void QskBoundedValueInput::increment( qreal offset )
2017-07-21 18:21:34 +02:00
{
2020-07-25 14:19:14 +02:00
setValue( m_value + offset );
2017-07-21 18:21:34 +02:00
}
2020-07-25 18:46:04 +02:00
void QskBoundedValueInput::setValueInternal( qreal value )
{
if ( !qskFuzzyCompare( value, m_value ) )
{
m_value = value;
Q_EMIT valueChanged( value );
update();
}
}
#include "moc_QskBoundedValueInput.cpp"