QskSlider::tracking fixed
This commit is contained in:
parent
fe66b99057
commit
4ebd07390f
@ -140,4 +140,10 @@ qreal QskBoundedControl::valueAsRatio( qreal value ) const
|
|||||||
return ( value - m_minimum ) / ( m_maximum - m_minimum );
|
return ( value - m_minimum ) / ( m_maximum - m_minimum );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal QskBoundedControl::valueFromRatio( qreal ratio ) const
|
||||||
|
{
|
||||||
|
ratio = qBound( 0.0, ratio, 1.0 );
|
||||||
|
return m_minimum + ratio * ( m_maximum - m_minimum );
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_QskBoundedControl.cpp"
|
#include "moc_QskBoundedControl.cpp"
|
||||||
|
@ -33,7 +33,9 @@ class QSK_EXPORT QskBoundedControl : public QskControl
|
|||||||
QskIntervalF boundaries() const;
|
QskIntervalF boundaries() const;
|
||||||
|
|
||||||
qreal boundedValue( qreal ) const;
|
qreal boundedValue( qreal ) const;
|
||||||
|
|
||||||
qreal valueAsRatio( qreal ) const;
|
qreal valueAsRatio( qreal ) const;
|
||||||
|
qreal valueFromRatio( qreal ) const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setMinimum( qreal );
|
void setMinimum( qreal );
|
||||||
|
@ -17,6 +17,12 @@ QSK_SYSTEM_STATE( QskSlider, Pressed, QskAspect::FirstSystemState << 2 )
|
|||||||
QSK_SYSTEM_STATE( QskSlider, Minimum, QskAspect::FirstSystemState << 3 )
|
QSK_SYSTEM_STATE( QskSlider, Minimum, QskAspect::FirstSystemState << 3 )
|
||||||
QSK_SYSTEM_STATE( QskSlider, Maximum, QskAspect::FirstSystemState << 4 )
|
QSK_SYSTEM_STATE( QskSlider, Maximum, QskAspect::FirstSystemState << 4 )
|
||||||
|
|
||||||
|
static inline QskAspect::Aspect qskAspectPosition( const QskSlider* slider )
|
||||||
|
{
|
||||||
|
using namespace QskAspect;
|
||||||
|
return slider->effectiveSubcontrol( QskSlider::Handle ) | Position | Metric;
|
||||||
|
}
|
||||||
|
|
||||||
class QskSlider::PrivateData
|
class QskSlider::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -105,9 +111,7 @@ bool QskSlider::isTracking() const
|
|||||||
|
|
||||||
void QskSlider::aboutToShow()
|
void QskSlider::aboutToShow()
|
||||||
{
|
{
|
||||||
const auto subControl = effectiveSubcontrol( QskSlider::Handle );
|
setMetric( qskAspectPosition( this ), valueAsRatio() );
|
||||||
setMetric( subControl | QskAspect::Position, valueAsRatio() );
|
|
||||||
|
|
||||||
Inherited::aboutToShow();
|
Inherited::aboutToShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,14 +165,6 @@ void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
|||||||
if ( !isPressed() )
|
if ( !isPressed() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !m_data->tracking )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
// if tracking is false we need to update the position only
|
|
||||||
// without changing the value TODO..
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto r = subControlRect( Scale );
|
const auto r = subControlRect( Scale );
|
||||||
|
|
||||||
qreal newValue;
|
qreal newValue;
|
||||||
@ -184,7 +180,14 @@ void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
|||||||
newValue = m_data->pressedValue - distance / r.height() * boundaryLength();
|
newValue = m_data->pressedValue - distance / r.height() * boundaryLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue( newValue );
|
if ( m_data->tracking )
|
||||||
|
{
|
||||||
|
setValue( newValue );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updatePosition( newValue, QskAnimationHint() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::mouseReleaseEvent( QMouseEvent* event )
|
void QskSlider::mouseReleaseEvent( QMouseEvent* event )
|
||||||
@ -217,22 +220,34 @@ void QskSlider::mouseReleaseEvent( QMouseEvent* event )
|
|||||||
else
|
else
|
||||||
pageDown();
|
pageDown();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !m_data->tracking )
|
||||||
|
{
|
||||||
|
const auto pos = metric( qskAspectPosition( this ) );
|
||||||
|
setValue( valueFromRatio( pos ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setSkinStateFlag( Pressed, false );
|
setSkinStateFlag( Pressed, false );
|
||||||
Q_EMIT pressedChanged( false );
|
Q_EMIT pressedChanged( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::updatePosition()
|
void QskSlider::updatePosition()
|
||||||
|
{
|
||||||
|
const auto hint = animation( qskAspectPosition( this ) | skinState() );
|
||||||
|
updatePosition( value(), hint );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskSlider::updatePosition( qreal value, const QskAnimationHint& hint )
|
||||||
{
|
{
|
||||||
using namespace QskAspect;
|
using namespace QskAspect;
|
||||||
|
|
||||||
setSkinStateFlag( QskSlider::Minimum, value() <= minimum() );
|
setSkinStateFlag( QskSlider::Minimum, value <= minimum() );
|
||||||
setSkinStateFlag( QskSlider::Maximum, value() >= maximum() );
|
setSkinStateFlag( QskSlider::Maximum, value >= maximum() );
|
||||||
|
|
||||||
const auto aspect = effectiveSubcontrol( QskSlider::Handle ) | Position | Metric;
|
const auto aspect = qskAspectPosition( this );
|
||||||
|
const qreal pos = valueAsRatio( value );
|
||||||
const auto hint = animation( aspect | skinState() );
|
|
||||||
const qreal pos = valueAsRatio();
|
|
||||||
|
|
||||||
if ( hint.duration > 0 )
|
if ( hint.duration > 0 )
|
||||||
{
|
{
|
||||||
|
@ -62,6 +62,7 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
void updatePosition( qreal value, const QskAnimationHint& );
|
||||||
|
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
std::unique_ptr< PrivateData > m_data;
|
std::unique_ptr< PrivateData > m_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user