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 ); const auto rect = subControlRect( ColdAndWarmArc );
bool arcContainsMousePos = arcContainsPoint( rect, mousePos ); 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 ); setSkinStateFlag( Pressed, false );
return; return;
} }
const QskArcMetrics metrics = arcMetricsHint( ColdAndWarmArc ); if( !arcContainsMousePos )
qreal angle = angleFromPoint( rect, mousePos );
const int tolerance = 20;
if( !angleInRange( metrics, angle ) )
{ {
// we're slightly outside the range, but don't want to give up // we're slightly outside the range, but don't want to give up
// the Pressed state // the Pressed state
angle = arcWithinStartAngleTolerance ? metrics.startAngle() : metrics.endAngle();
if( angleDiff( angle, metrics.startAngle() ) < tolerance )
{
angle = metrics.startAngle();
}
else if( angleDiff( angle, metrics.endAngle() ) < tolerance )
{
angle = metrics.endAngle();
}
} }
qreal ratio = ( metrics.spanAngle() - angle ) / metrics.spanAngle(); 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() ); rect.center().y() - point.y() );
const qreal angle = angleFromPoint( rect, point ); const qreal angle = angleFromPoint( rect, point );
const bool angleWithinRange = angleInRange( metrics, angle );
const bool angleWithinRange = angleInRange( metrics, angle )
|| angleDiff( angle, metrics.startAngle() ) <= tolerance
|| angleDiff( angle, metrics.endAngle() ) <= tolerance;
// 2. check whether point is on arc // 2. check whether point is on arc
const qreal radiusMax = rect.width() / 2; const qreal radiusMax = rect.width() / 2;