better painter paths for >= 360°

This commit is contained in:
Uwe Rathmann 2024-01-22 14:10:46 +01:00
parent 02d76b199a
commit 83432af799
1 changed files with 36 additions and 22 deletions

View File

@ -119,10 +119,6 @@ QskArcMetrics QskArcMetrics::toAbsolute( qreal radius ) const noexcept
QPainterPath QskArcMetrics::painterPath( const QRectF& ellipseRect ) const QPainterPath QskArcMetrics::painterPath( const QRectF& ellipseRect ) const
{ {
/*
We might want to have no connecting line between inner and
outer border. F.e. for 360° arcs. TODO ...
*/
const auto sz = qMin( ellipseRect.width(), ellipseRect.height() ); const auto sz = qMin( ellipseRect.width(), ellipseRect.height() );
qreal t = m_thickness; qreal t = m_thickness;
@ -141,31 +137,49 @@ QPainterPath QskArcMetrics::painterPath( const QRectF& ellipseRect ) const
if ( innerRect.isEmpty() ) if ( innerRect.isEmpty() )
{ {
// a pie if ( qAbs( m_spanAngle ) >= 360.0 )
{
path.arcMoveTo( ellipseRect, m_startAngle ); path.addEllipse( ellipseRect );
path.arcTo( ellipseRect, m_startAngle, m_spanAngle ); }
path.lineTo( ellipseRect.center() ); else
{
// pie
path.arcMoveTo( ellipseRect, m_startAngle );
path.arcTo( ellipseRect, m_startAngle, m_spanAngle );
path.lineTo( ellipseRect.center() );
path.closeSubpath();
}
} }
else else
{ {
/* if ( qAbs( m_spanAngle ) >= 360.0 )
We need the end point of the inner arc to add the line that connects {
the inner/outer arcs. As QPainterPath does not offer such a method path.addEllipse( ellipseRect );
we insert a dummy arcMoveTo and grab the calculated position.
*/
path.arcMoveTo( innerRect, m_startAngle + m_spanAngle );
const auto pos = path.currentPosition();
path.arcMoveTo( ellipseRect, m_startAngle ); // replaces the dummy arcMoveTo above QPainterPath innerPath;
path.arcTo( ellipseRect, m_startAngle, m_spanAngle ); innerPath.addEllipse( innerRect );
path -= innerPath;
}
else
{
/*
We need the end point of the inner arc to add the line that connects
the inner/outer arcs. As QPainterPath does not offer such a method
we insert a dummy arcMoveTo and grab the calculated position.
*/
path.arcMoveTo( innerRect, m_startAngle + m_spanAngle );
const auto pos = path.currentPosition();
path.lineTo( pos ); path.arcMoveTo( ellipseRect, m_startAngle ); // replaces the dummy arcMoveTo above
path.arcTo( innerRect, m_startAngle + m_spanAngle, -m_spanAngle ); path.arcTo( ellipseRect, m_startAngle, m_spanAngle );
path.lineTo( pos );
path.arcTo( innerRect, m_startAngle + m_spanAngle, -m_spanAngle );
path.closeSubpath();
}
} }
path.closeSubpath();
return path; return path;
} }