slider changes on press
This commit is contained in:
parent
59b88ffd7c
commit
77731954eb
@ -1458,6 +1458,8 @@ void Editor::setupSliderMetrics()
|
|||||||
setFlag( Q::Tick | A::Option, Qsk::Maybe );
|
setFlag( Q::Tick | A::Option, Qsk::Maybe );
|
||||||
setStrutSize( Q::Tick | A::Horizontal, 1_px, -1 );
|
setStrutSize( Q::Tick | A::Horizontal, 1_px, -1 );
|
||||||
setStrutSize( Q::Tick | A::Vertical, -1, 1_px );
|
setStrutSize( Q::Tick | A::Vertical, -1, 1_px );
|
||||||
|
|
||||||
|
setAnimation( Q::Handle | A::Metric | A::Position, 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupSliderColors(
|
void Editor::setupSliderColors(
|
||||||
|
@ -846,9 +846,7 @@ void Editor::setupSlider()
|
|||||||
QskRgb::lighter( rgb, 102 ) );
|
QskRgb::lighter( rgb, 102 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the handle smoothly, when using keys
|
|
||||||
setAnimation( Q::Handle | A::Metric | A::Position, 2 * qskDuration );
|
setAnimation( Q::Handle | A::Metric | A::Position, 2 * qskDuration );
|
||||||
setAnimation( Q::Handle | A::Metric | A::Position | Q::Pressed, 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupSpinBox()
|
void Editor::setupSpinBox()
|
||||||
|
@ -966,9 +966,7 @@ void Editor::setupSlider()
|
|||||||
const auto disabledColor = flattenedColor( m_pal.onSurface, m_pal.background, 0.38 );
|
const auto disabledColor = flattenedColor( m_pal.onSurface, m_pal.background, 0.38 );
|
||||||
setGradient( Q::Handle | Q::Disabled, disabledColor );
|
setGradient( Q::Handle | Q::Disabled, disabledColor );
|
||||||
|
|
||||||
// move the handle smoothly when using keys
|
|
||||||
setAnimation( Q::Handle | A::Metric | A::Position, 2 * qskDuration );
|
setAnimation( Q::Handle | A::Metric | A::Position, 2 * qskDuration );
|
||||||
setAnimation( Q::Handle | A::Metric | A::Position | Q::Pressed, 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupSpinBox()
|
void Editor::setupSpinBox()
|
||||||
|
@ -36,12 +36,39 @@ static QRectF qskHandleSelectionRect( const QskSlider* slider )
|
|||||||
return rect.marginsAdded( { w, h, w, h } );
|
return rect.marginsAdded( { w, h, w, h } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QRectF qskSliderSelectionRect( const QskSlider* slider )
|
||||||
|
{
|
||||||
|
const qreal margin = 10.0;
|
||||||
|
|
||||||
|
const auto scaleRect = slider->subControlRect( QskSlider::Scale );
|
||||||
|
const auto handleRect = qskHandleSelectionRect( slider );
|
||||||
|
|
||||||
|
auto r = slider->subControlRect( QskSlider::Panel );
|
||||||
|
if ( slider->orientation() == Qt::Horizontal )
|
||||||
|
{
|
||||||
|
r.setTop( qMin( r.top(), handleRect.top() ) );
|
||||||
|
r.setBottom( qMax( r.bottom(), handleRect.bottom() ) );
|
||||||
|
r.setLeft( scaleRect.left() - margin );
|
||||||
|
r.setRight( scaleRect.right() + margin );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.setLeft( qMin( r.left(), handleRect.left() ) );
|
||||||
|
r.setRight( qMax( r.right(), handleRect.right() ) );
|
||||||
|
r.setTop( scaleRect.top() - margin );
|
||||||
|
r.setBottom( scaleRect.bottom() + margin );
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
class QskSlider::PrivateData
|
class QskSlider::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrivateData( Qt::Orientation orientation )
|
PrivateData( Qt::Orientation orientation )
|
||||||
: pressedValue( 0 )
|
: pressedValue( 0 )
|
||||||
, tracking( true )
|
, tracking( true )
|
||||||
|
, moving( false )
|
||||||
, orientation( orientation )
|
, orientation( orientation )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -49,6 +76,7 @@ class QskSlider::PrivateData
|
|||||||
QPointF pressedPos;
|
QPointF pressedPos;
|
||||||
qreal pressedValue;
|
qreal pressedValue;
|
||||||
bool tracking : 1;
|
bool tracking : 1;
|
||||||
|
bool moving : 1;
|
||||||
uint orientation : 2;
|
uint orientation : 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -147,26 +175,32 @@ void QskSlider::aboutToShow()
|
|||||||
|
|
||||||
void QskSlider::mousePressEvent( QMouseEvent* event )
|
void QskSlider::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
if ( qskHandleSelectionRect( this ).contains( event->pos() ) )
|
const auto pos = qskMousePosition( event );
|
||||||
|
if ( !qskHandleSelectionRect( this ).contains( pos ) )
|
||||||
{
|
{
|
||||||
// Case 1: press started in the handle, start sliding
|
const auto r = qskSliderSelectionRect( this );
|
||||||
|
if ( !r.contains( pos ) )
|
||||||
|
{
|
||||||
|
Inherited::mousePressEvent( event );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ratio;
|
||||||
|
|
||||||
|
const auto scaleRect = subControlRect( Scale );
|
||||||
|
if ( m_data->orientation == Qt::Horizontal )
|
||||||
|
ratio = ( pos.x() - scaleRect.left() ) / scaleRect.width();
|
||||||
|
else
|
||||||
|
ratio = ( scaleRect.bottom() - pos.y() ) / scaleRect.height();
|
||||||
|
|
||||||
|
setValue( valueFromRatio( ratio ) );
|
||||||
|
}
|
||||||
|
|
||||||
m_data->pressedPos = event->pos();
|
|
||||||
m_data->pressedValue = value();
|
|
||||||
setSkinStateFlag( Pressed );
|
setSkinStateFlag( Pressed );
|
||||||
Q_EMIT pressedChanged( true );
|
Q_EMIT pressedChanged( true );
|
||||||
}
|
|
||||||
else if ( pageSteps() == 0 )
|
m_data->pressedPos = pos;
|
||||||
{
|
m_data->pressedValue = value();
|
||||||
// Case 2: pageSize is not used, we're done here
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Case 3: pressed outside of the handle, page the scroller in
|
|
||||||
// the direction of the press requires an auto-repeat behavior
|
|
||||||
// until the slider reaches the destination, or it simply jumps
|
|
||||||
// there (configurable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
||||||
@ -192,52 +226,21 @@ void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
if ( m_data->tracking )
|
if ( m_data->tracking )
|
||||||
{
|
{
|
||||||
|
m_data->moving = true;
|
||||||
setValue( newValue );
|
setValue( newValue );
|
||||||
|
m_data->moving = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// moving the handle without changing the value
|
||||||
moveHandleTo( newValue, QskAnimationHint() );
|
moveHandleTo( newValue, QskAnimationHint() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::mouseReleaseEvent( QMouseEvent* event )
|
void QskSlider::mouseReleaseEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
if ( !isPressed() ) // Page event
|
if ( !m_data->tracking && ( m_data->pressedValue != value() ) )
|
||||||
{
|
Q_EMIT valueChanged( value() );
|
||||||
const auto mousePos = qskMousePosition( event );
|
|
||||||
|
|
||||||
const auto szHandle = qskHandleSelectionRect( this ).size();
|
|
||||||
const auto rect = contentsRect();
|
|
||||||
|
|
||||||
bool up;
|
|
||||||
if ( m_data->orientation == Qt::Horizontal )
|
|
||||||
{
|
|
||||||
const qreal w = szHandle.width();
|
|
||||||
|
|
||||||
const qreal x = ( mousePos.x() - rect.x() - w * 0.5 ) / ( rect.width() - w );
|
|
||||||
up = x > valueAsRatio();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const qreal h = szHandle.height();
|
|
||||||
|
|
||||||
const qreal y = ( mousePos.y() - rect.y() - h * 0.5 ) / ( rect.height() - h );
|
|
||||||
up = y < 1.0 - valueAsRatio();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( up )
|
|
||||||
pageUp();
|
|
||||||
else
|
|
||||||
pageDown();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( !m_data->tracking )
|
|
||||||
{
|
|
||||||
const auto pos = handlePosition();
|
|
||||||
setValue( valueFromRatio( pos ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setSkinStateFlag( Pressed, false );
|
setSkinStateFlag( Pressed, false );
|
||||||
Q_EMIT pressedChanged( false );
|
Q_EMIT pressedChanged( false );
|
||||||
@ -249,9 +252,15 @@ qreal QskSlider::handlePosition() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::moveHandle()
|
void QskSlider::moveHandle()
|
||||||
|
{
|
||||||
|
QskAnimationHint hint;
|
||||||
|
if ( !m_data->moving )
|
||||||
{
|
{
|
||||||
const auto aspect = Handle | QskAspect::Metric | QskAspect::Position;
|
const auto aspect = Handle | QskAspect::Metric | QskAspect::Position;
|
||||||
moveHandleTo( value(), animationHint( aspect | skinStates() ) );
|
hint = animationHint( aspect | skinStates() );
|
||||||
|
}
|
||||||
|
|
||||||
|
moveHandleTo( value(), hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSlider::moveHandleTo( qreal value, const QskAnimationHint& hint )
|
void QskSlider::moveHandleTo( qreal value, const QskAnimationHint& hint )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user