From 83432af799e706ed67c6acc2000538d344b9d084 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 22 Jan 2024 14:10:46 +0100 Subject: [PATCH] =?UTF-8?q?better=20painter=20paths=20for=20>=3D=20360?= =?UTF-8?q?=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/QskArcMetrics.cpp | 58 ++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/common/QskArcMetrics.cpp b/src/common/QskArcMetrics.cpp index 956508ce..a7981827 100644 --- a/src/common/QskArcMetrics.cpp +++ b/src/common/QskArcMetrics.cpp @@ -119,10 +119,6 @@ QskArcMetrics QskArcMetrics::toAbsolute( qreal radius ) const noexcept 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() ); qreal t = m_thickness; @@ -141,31 +137,49 @@ QPainterPath QskArcMetrics::painterPath( const QRectF& ellipseRect ) const if ( innerRect.isEmpty() ) { - // a pie - - path.arcMoveTo( ellipseRect, m_startAngle ); - path.arcTo( ellipseRect, m_startAngle, m_spanAngle ); - path.lineTo( ellipseRect.center() ); + if ( qAbs( m_spanAngle ) >= 360.0 ) + { + path.addEllipse( ellipseRect ); + } + else + { + // pie + path.arcMoveTo( ellipseRect, m_startAngle ); + path.arcTo( ellipseRect, m_startAngle, m_spanAngle ); + path.lineTo( ellipseRect.center() ); + path.closeSubpath(); + } } 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(); + if ( qAbs( m_spanAngle ) >= 360.0 ) + { + path.addEllipse( ellipseRect ); - path.arcMoveTo( ellipseRect, m_startAngle ); // replaces the dummy arcMoveTo above - path.arcTo( ellipseRect, m_startAngle, m_spanAngle ); + QPainterPath innerPath; + 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.arcTo( innerRect, m_startAngle + m_spanAngle, -m_spanAngle ); + path.arcMoveTo( ellipseRect, m_startAngle ); // replaces the dummy arcMoveTo above + 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; }