From 1ccd19392be6f7bcbadee4bb3a8bbb850d951ce4 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 13 Oct 2021 12:22:20 +0200 Subject: [PATCH] support linear gradients in the arc renderer --- src/nodes/QskArcRenderer.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/nodes/QskArcRenderer.h b/src/nodes/QskArcRenderer.h index e928c939..3a2d7f7d 100644 --- a/src/nodes/QskArcRenderer.h +++ b/src/nodes/QskArcRenderer.h @@ -10,6 +10,7 @@ #include "QskGlobal.h" #include "QskGradient.h" +#include #include #include @@ -34,7 +35,22 @@ void QskArcRenderer::renderArc(const QRectF& rect, stops.append( s ); } - if( gradient.orientation() == QskGradient::Radial ) + if( gradient.orientation() == QskGradient::Horizontal + || gradient.orientation() == QskGradient::Vertical ) + { + QPointF finalStop = ( gradient.orientation() == QskGradient::Horizontal ) + ? QPointF( rect.width(), 0 ) : QPointF( 0, rect.height() ); + + QLinearGradient linearGradient( { 0, 0 }, finalStop ); + linearGradient.setStops( stops ); + painter->setPen( QPen( linearGradient, metrics.width(), Qt::SolidLine, + Qt::FlatCap ) ); + } + else if( gradient.orientation() == QskGradient::Diagonal ) + { + qWarning() << "cannot paint a diagonal gradient with QPainter"; + } + else if( gradient.orientation() == QskGradient::Radial ) { QRadialGradient radialGradient( rect.center(), qMin( rect.width(), rect.height() ) ); @@ -50,7 +66,6 @@ void QskArcRenderer::renderArc(const QRectF& rect, painter->setPen( QPen( conicalGradient, metrics.width(), Qt::SolidLine, Qt::FlatCap ) ); } - // ### add other types painter->drawArc( rect, metrics.startAngle(), metrics.spanAngle() ); }