move tolerance in mouse handlinge code

This commit is contained in:
Peter Hartmann 2021-12-03 10:46:20 +01:00
parent 5a98558292
commit 65db642d17
1 changed files with 10 additions and 20 deletions

View File

@ -110,31 +110,24 @@ void LightDisplay::mouseMoveEvent( QMouseEvent* event )
const auto rect = subControlRect( ColdAndWarmArc );
bool arcContainsMousePos = arcContainsPoint( rect, mousePos );
const QskArcMetrics metrics = arcMetricsHint( ColdAndWarmArc );
qreal angle = angleFromPoint( rect, mousePos );
const int tolerance = 20;
if( !arcContainsMousePos )
bool arcWithinStartAngleTolerance = ( angleDiff( angle, metrics.startAngle() ) < tolerance );
bool arcWithinEndAngleTolerance = ( angleDiff( angle, metrics.endAngle() ) < tolerance );
if( !( arcContainsMousePos || arcWithinStartAngleTolerance || arcWithinEndAngleTolerance ) )
{
setSkinStateFlag( Pressed, false );
return;
}
const QskArcMetrics metrics = arcMetricsHint( ColdAndWarmArc );
qreal angle = angleFromPoint( rect, mousePos );
const int tolerance = 20;
if( !angleInRange( metrics, angle ) )
if( !arcContainsMousePos )
{
// we're slightly outside the range, but don't want to give up
// the Pressed state
if( angleDiff( angle, metrics.startAngle() ) < tolerance )
{
angle = metrics.startAngle();
}
else if( angleDiff( angle, metrics.endAngle() ) < tolerance )
{
angle = metrics.endAngle();
}
angle = arcWithinStartAngleTolerance ? metrics.startAngle() : metrics.endAngle();
}
qreal ratio = ( metrics.spanAngle() - angle ) / metrics.spanAngle();
@ -169,10 +162,7 @@ bool LightDisplay::arcContainsPoint( const QRectF& rect, const QPointF& point )
rect.center().y() - point.y() );
const qreal angle = angleFromPoint( rect, point );
const bool angleWithinRange = angleInRange( metrics, angle )
|| angleDiff( angle, metrics.startAngle() ) <= tolerance
|| angleDiff( angle, metrics.endAngle() ) <= tolerance;
const bool angleWithinRange = angleInRange( metrics, angle );
// 2. check whether point is on arc
const qreal radiusMax = rect.width() / 2;