diff --git a/examples/iotdashboard/LightDisplay.cpp b/examples/iotdashboard/LightDisplay.cpp index 0e349197..7627fde7 100644 --- a/examples/iotdashboard/LightDisplay.cpp +++ b/examples/iotdashboard/LightDisplay.cpp @@ -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;