move some functionality to the arc renderer

This commit is contained in:
Peter Hartmann 2021-10-11 15:48:17 +02:00
parent d1f79e2f72
commit b90af00685
2 changed files with 35 additions and 29 deletions

View File

@ -4,6 +4,7 @@
*****************************************************************************/ *****************************************************************************/
#include "QskArcNode.h" #include "QskArcNode.h"
#include "QskArcRenderer.h"
#include <QPainter> #include <QPainter>
@ -47,35 +48,12 @@ void QskArcNode::paint( QPainter *painter, const QSizeF &size )
spanAngle = -1 * ( m_value / m_maximum ) * 360; spanAngle = -1 * ( m_value / m_maximum ) * 360;
} }
painter->setRenderHint( QPainter::Antialiasing, true );
const QRectF r( 0.5 * m_width, 0.5 * m_width, const QRectF r( 0.5 * m_width, 0.5 * m_width,
size.width() - m_width, size.height() - m_width ); size.width() - m_width, size.height() - m_width );
QGradientStops stops; QskArcRenderer renderer;
renderer.renderArc( r, m_gradient, m_gradientType, m_width, startAngle, spanAngle,
for( const QskGradientStop& stop : m_gradient.stops() ) painter );
{
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 );
}
} }
uint QskArcNode::hash() const uint QskArcNode::hash() const

View File

@ -16,13 +16,41 @@ class QSK_EXPORT QskArcRenderer
{ {
public: public:
void renderArc( const QRectF& rect, const QskGradient& gradient, 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, inline void QskArcRenderer::renderArc( const QRectF& rect,
const QskGradient& gradient, QGradient::Type gradientType, const QskGradient& gradient, QGradient::Type gradientType, double width,
int startAngle, int endAngle, QPainter* painter ) 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 #endif