From b90af006850099fa9e632f3a912056a5d11f6124 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Mon, 11 Oct 2021 15:48:17 +0200 Subject: [PATCH] move some functionality to the arc renderer --- src/nodes/QskArcNode.cpp | 30 ++++-------------------------- src/nodes/QskArcRenderer.h | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/nodes/QskArcNode.cpp b/src/nodes/QskArcNode.cpp index dff8f5da..511bd020 100644 --- a/src/nodes/QskArcNode.cpp +++ b/src/nodes/QskArcNode.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "QskArcNode.h" +#include "QskArcRenderer.h" #include @@ -47,35 +48,12 @@ void QskArcNode::paint( QPainter *painter, const QSizeF &size ) spanAngle = -1 * ( m_value / m_maximum ) * 360; } - painter->setRenderHint( QPainter::Antialiasing, true ); - const QRectF r( 0.5 * m_width, 0.5 * m_width, size.width() - m_width, size.height() - m_width ); - QGradientStops stops; - - for( const QskGradientStop& stop : m_gradient.stops() ) - { - QGradientStop s( stop.position(), stop.color() ); - stops.append( s ); - } - - if( m_gradientType == QGradient::RadialGradient ) - { - QRadialGradient radialGradient( r.center(), qMin( r.width(), r.height() ) ); - radialGradient.setStops( stops ); - - painter->setPen( QPen( radialGradient, m_width, Qt::SolidLine, Qt::FlatCap ) ); - painter->drawArc( r, startAngle * 16, spanAngle * 16 ); - } - else - { - QConicalGradient conicalGradient( r.center(), startAngle ); - conicalGradient.setStops( stops ); - - painter->setPen( QPen( conicalGradient, m_width, Qt::SolidLine, Qt::FlatCap ) ); - painter->drawArc( r, startAngle * 16, spanAngle * 16 ); - } + QskArcRenderer renderer; + renderer.renderArc( r, m_gradient, m_gradientType, m_width, startAngle, spanAngle, + painter ); } uint QskArcNode::hash() const diff --git a/src/nodes/QskArcRenderer.h b/src/nodes/QskArcRenderer.h index b32e4cd2..b5733433 100644 --- a/src/nodes/QskArcRenderer.h +++ b/src/nodes/QskArcRenderer.h @@ -16,13 +16,41 @@ class QSK_EXPORT QskArcRenderer { public: void renderArc( const QRectF& rect, const QskGradient& gradient, - QGradient::Type gradientType, int startAngle, int endAngle, QPainter* ); + QGradient::Type gradientType, double width, int startAngle, + int endAngle, QPainter* ); }; inline void QskArcRenderer::renderArc( const QRectF& rect, - const QskGradient& gradient, QGradient::Type gradientType, - int startAngle, int endAngle, QPainter* painter ) + const QskGradient& gradient, QGradient::Type gradientType, double width, + int startAngle, int spanAngle, QPainter* painter ) { + painter->setRenderHint( QPainter::Antialiasing, true ); + + QGradientStops stops; + + for( const QskGradientStop& stop : gradient.stops() ) + { + QGradientStop s( stop.position(), stop.color() ); + stops.append( s ); + } + + if( gradientType == QGradient::RadialGradient ) + { + QRadialGradient radialGradient( rect.center(), qMin( rect.width(), rect.height() ) ); + radialGradient.setStops( stops ); + + painter->setPen( QPen( radialGradient, width, Qt::SolidLine, Qt::FlatCap ) ); + painter->drawArc( rect, startAngle * 16, spanAngle * 16 ); + } + else + { + QConicalGradient conicalGradient( rect.center(), startAngle ); + conicalGradient.setStops( stops ); + + painter->setPen( QPen( conicalGradient, width, Qt::SolidLine, Qt::FlatCap ) ); + painter->drawArc( rect, startAngle * 16, spanAngle * 16 ); + } + } #endif