gradient rendering fixed

This commit is contained in:
Uwe Rathmann 2024-06-05 10:34:19 +02:00
parent 1a08de914a
commit 929b7a43fd
4 changed files with 55 additions and 33 deletions

View File

@ -48,24 +48,50 @@ namespace
} }
} }
}; };
class Arc : public ShadowedArc
{
public:
Arc()
{
setStartAngle( 45.0 );
setSpanAngle( 270.0 );
setThickness( 10.0 );
setBorderWidth( 2.0 );
setBorderColor( Qt::black );
#if 0
const QskGradientStops stops =
{
{ 0.1, Qt::darkRed },
{ 0.1, Qt::darkYellow },
{ 0.5, Qt::darkYellow },
{ 0.5, Qt::darkBlue },
{ 0.75, Qt::darkBlue },
{ 0.75, Qt::darkRed }
};
#else
const QskGradientStops stops =
{
{ 0.1, Qt::darkRed },
{ 0.5, Qt::darkYellow },
{ 0.75, Qt::darkBlue },
{ 1.0, Qt::darkRed }
};
#endif
setFillGradient( stops );
}
};
} }
ArcPage::ArcPage( QQuickItem* parent ) ArcPage::ArcPage( QQuickItem* parent )
: QskLinearBox( Qt::Vertical, parent ) : QskLinearBox( Qt::Vertical, parent )
{ {
auto arc = new ShadowedArc(); auto arc = new Arc();
arc->setMargins( 40 ); // some extra space for testing the offsets arc->setMargins( 40 ); // some extra space for testing the offsets
{
// initial settings
arc->setStartAngle( 45.0 );
arc->setSpanAngle( 270.0 );
arc->setThickness( 10.0 );
arc->setBorderWidth( 2.0 );
arc->setBorderColor( Qt::darkBlue );
}
auto panel = new ControlPanel( arc ); auto panel = new ControlPanel( arc );
panel->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed ); panel->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );

View File

@ -101,17 +101,7 @@ ShadowedArc::ShadowedArc( QQuickItem* parent )
setArcMetrics( { 0.0, 360.0, 1.0, Qt::RelativeSize } ); setArcMetrics( { 0.0, 360.0, 1.0, Qt::RelativeSize } );
//setFillColor( Qt::darkRed ); setFillGradient( Qt::white );
const QskGradientStops stops =
{
{ 0.1, Qt::darkRed },
{ 0.5, Qt::darkYellow },
{ 0.75, Qt::darkBlue },
{ 1.0, Qt::darkRed }
};
setGradientHint( Arc, stops );
setBorderWidth( 0 ); setBorderWidth( 0 );
setBorderColor( Qt::gray ); setBorderColor( Qt::gray );
@ -226,14 +216,14 @@ qreal ShadowedArc::blurRadius() const
return shadowMetrics().blurRadius(); return shadowMetrics().blurRadius();
} }
void ShadowedArc::setFillColor( const QColor& color ) void ShadowedArc::setFillGradient( const QskGradient& gradient )
{ {
setColor( Arc, color ); setGradientHint( Arc, gradient );
} }
QColor ShadowedArc::fillColor() const QskGradient ShadowedArc::fillGradient() const
{ {
return color( Arc ); return gradientHint( Arc );
} }
void ShadowedArc::setShadowColor( const QColor& color ) void ShadowedArc::setShadowColor( const QColor& color )

View File

@ -9,6 +9,7 @@
class QskShadowMetrics; class QskShadowMetrics;
class QskArcMetrics; class QskArcMetrics;
class QskGradient;
class ShadowedArc : public QskControl class ShadowedArc : public QskControl
{ {
@ -35,7 +36,7 @@ class ShadowedArc : public QskControl
qreal blurRadius() const; qreal blurRadius() const;
QColor borderColor() const; QColor borderColor() const;
QColor fillColor() const; QskGradient fillGradient() const;
QColor shadowColor() const; QColor shadowColor() const;
public Q_SLOTS: public Q_SLOTS:
@ -52,7 +53,7 @@ class ShadowedArc : public QskControl
void setBlurRadius( qreal ); void setBlurRadius( qreal );
void setBorderColor( const QColor& ); void setBorderColor( const QColor& );
void setFillColor( const QColor& ); void setFillGradient( const QskGradient& );
void setShadowColor( const QColor& ); void setShadowColor( const QColor& );
private: private:

View File

@ -166,15 +166,20 @@ namespace
it.advance(); // the first stop is always covered by the contour it.advance(); // the first stop is always covered by the contour
} }
const auto stepCount = arcLineCount(); const auto count = arcLineCount();
const auto stepSize = ( m_radians2 - m_radians1 ) / ( stepCount - 1 );
for ( int i = 0; i < stepCount; i++ ) const qreal stepMax = count - 1;
const auto stepSize = ( m_radians2 - m_radians1 ) / stepMax;
for ( int i = 0; i < count; i++ )
{ {
const auto progress = qreal( i ) / stepCount; const auto progress = i / stepMax;
for ( ; it.position() < progress; it.advance() ) while( !it.isDone() && ( it.position() < progress ) )
{
setFillLine( radiansAt( it.position() ), it.color(), *l++ ); setFillLine( radiansAt( it.position() ), it.color(), *l++ );
it.advance();
}
const auto color = it.colorAt( progress ); const auto color = it.colorAt( progress );
setFillLine( m_radians1 + i * stepSize, color, *l++ ); setFillLine( m_radians1 + i * stepSize, color, *l++ );