QskGradient::qtStops added

This commit is contained in:
Uwe Rathmann 2022-10-20 09:22:11 +02:00
parent 4ca794f7db
commit d5ba7d9504
3 changed files with 19 additions and 12 deletions

View File

@ -693,6 +693,17 @@ QskGradientStops QskGradient::colorStops(
return qskColorStops( rgb.constData(), count, discrete );
}
QGradientStops QskGradient::qtStops() const
{
QGradientStops qstops;
qstops.reserve( m_stops.count() );
for ( const auto& stop : m_stops )
qstops += { stop.position(), stop.color() };
return qstops;
}
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>

View File

@ -101,6 +101,8 @@ class QSK_EXPORT QskGradient
Q_INVOKABLE QColor colorAt( int index ) const;
Q_INVOKABLE int stopCount() const;
QGradientStops qtStops() const;
static QskGradientStops colorStops(
const QVector< QRgb >&, bool discrete = false );

View File

@ -16,12 +16,6 @@ void QskArcRenderer::renderArc(const QRectF& rect,
{
painter->setRenderHint( QPainter::Antialiasing, true );
QGradientStops stops;
stops.reserve( gradient.stops().count() );
for( const auto& stop : qAsConst( gradient.stops() ) )
stops += QGradientStop( stop.position(), stop.color() );
/*
horizontal is interpreted as in direction of the arc,
while vertical means from the inner to the outer border
@ -31,17 +25,17 @@ void QskArcRenderer::renderArc(const QRectF& rect,
if( gradient.orientation() == QskGradient::Vertical )
{
QRadialGradient gradient( rect.center(), qMin( rect.width(), rect.height() ) );
gradient.setStops( stops );
QRadialGradient radial( rect.center(), qMin( rect.width(), rect.height() ) );
radial.setStops( gradient.qtStops() );
brush = gradient;
brush = radial;
}
else
{
QConicalGradient gradient( rect.center(), metrics.startAngle() );
gradient.setStops( stops );
QConicalGradient conical( rect.center(), metrics.startAngle() );
conical.setStops( gradient.qtStops() );
brush = gradient;
brush = conical;
}
painter->setPen( QPen( brush, metrics.width(), Qt::SolidLine, Qt::FlatCap ) );