working more with RGBA values instead of QColor

This commit is contained in:
Uwe Rathmann 2022-11-16 13:46:37 +01:00
parent 31577cab9b
commit 615e0016c2
7 changed files with 34 additions and 22 deletions

View File

@ -233,7 +233,7 @@ QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors )
if ( colors.isMonochrome() ) if ( colors.isMonochrome() )
{ {
const auto& gradient = colors.gradientAt( Qt::LeftEdge ); const auto& gradient = colors.gradientAt( Qt::LeftEdge );
QskRgb::debugColor( debug, gradient.startColor() ); QskRgb::debugColor( debug, gradient.rgbStart() );
} }
else else
{ {
@ -252,7 +252,7 @@ QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors )
debug << prompts[ i ] << ": "; debug << prompts[ i ] << ": ";
if ( gradient.isValid() && gradient.isMonochrome() ) if ( gradient.isValid() && gradient.isMonochrome() )
QskRgb::debugColor( debug, gradient.startColor() ); QskRgb::debugColor( debug, gradient.rgbStart() );
else else
debug << gradient; debug << gradient;
} }

View File

@ -609,8 +609,7 @@ QDebug operator<<( QDebug debug, const QskGradient& gradient )
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
debug << ' '; debug << ' ';
const auto color = gradient.stops().first().color(); QskRgb::debugColor( debug, gradient.rgbStart() );
QskRgb::debugColor( debug, color );
} }
else else
{ {

View File

@ -103,6 +103,9 @@ class QSK_EXPORT QskGradient
Q_INVOKABLE QColor startColor() const noexcept; Q_INVOKABLE QColor startColor() const noexcept;
Q_INVOKABLE QColor endColor() const noexcept; Q_INVOKABLE QColor endColor() const noexcept;
QRgb rgbStart() const;
QRgb rgbEnd() const;
void setAlpha( int alpha ); void setAlpha( int alpha );
void setSpread( QGradient::Spread ); void setSpread( QGradient::Spread );
@ -218,6 +221,16 @@ inline QColor QskGradient::endColor() const noexcept
return m_stops.isEmpty() ? QColor() : m_stops.last().color(); return m_stops.isEmpty() ? QColor() : m_stops.last().color();
} }
inline QRgb QskGradient::rgbStart() const
{
return m_stops.isEmpty() ? qRgba( 0, 0, 0, 255 ) : m_stops.first().rgb();
}
inline QRgb QskGradient::rgbEnd() const
{
return m_stops.isEmpty() ? qRgba( 0, 0, 0, 255 ) : m_stops.last().rgb();
}
inline QGradient::Spread QskGradient::spread() const noexcept inline QGradient::Spread QskGradient::spread() const noexcept
{ {
return m_spread; return m_spread;

View File

@ -50,7 +50,7 @@ static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
g.setLinearDirection( Qt::Vertical ); g.setLinearDirection( Qt::Vertical );
g.setStops( gradient.startColor() ); g.setStops( gradient.rgbStart() );
} }
else else
{ {
@ -197,7 +197,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
{ {
if ( isFillMonochrome && isBorderMonochrome ) if ( isFillMonochrome && isBorderMonochrome )
{ {
if ( borderColors.left().startColor() == fillGradient.startColor() ) if ( borderColors.left().rgbStart() == fillGradient.rgbStart() )
{ {
// we can draw border and background in one // we can draw border and background in one
hasBorder = false; hasBorder = false;
@ -246,12 +246,12 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( hasFill ) if ( hasFill )
{ {
flatMaterial->setColor( fillGradient.startColor() ); flatMaterial->setColor( fillGradient.rgbStart() );
renderer.renderFill( d->rect, shape, QskBoxBorderMetrics(), *geometry() ); renderer.renderFill( d->rect, shape, QskBoxBorderMetrics(), *geometry() );
} }
else else
{ {
flatMaterial->setColor( borderColors.left().startColor().rgba() ); flatMaterial->setColor( borderColors.left().rgbStart() );
renderer.renderBorder( d->rect, shape, borderMetrics, *geometry() ); renderer.renderBorder( d->rect, shape, borderMetrics, *geometry() );
} }
} }

View File

@ -261,13 +261,13 @@ namespace QskVertex
{ {
if ( value2 == 1.0 && value1 == 0.0 ) if ( value2 == 1.0 && value1 == 0.0 )
{ {
TwoColorIterator01 colorIt( gradient.startColor(), gradient.endColor() ); TwoColorIterator01 colorIt( gradient.rgbStart(), gradient.rgbEnd() );
line = fillOrdered( contourIt, colorIt, line ); line = fillOrdered( contourIt, colorIt, line );
} }
else else
{ {
TwoColorIterator colorIt( value1, value2, TwoColorIterator colorIt( value1, value2,
gradient.startColor(), gradient.endColor() ); gradient.rgbStart(), gradient.rgbEnd() );
line = fillOrdered( contourIt, colorIt, line ); line = fillOrdered( contourIt, colorIt, line );
} }

View File

@ -500,7 +500,7 @@ namespace
{ {
public: public:
inline BorderMapSolid( const QskBoxBorderColors& colors ) inline BorderMapSolid( const QskBoxBorderColors& colors )
: m_color( colors.left().startColor() ) : m_color( colors.left().rgbStart() )
{ {
} }
@ -515,8 +515,8 @@ namespace
public: public:
inline BorderMapGradient( int stepCount, const QskGradient& gradient1, const QskGradient& gradient2 ) inline BorderMapGradient( int stepCount, const QskGradient& gradient1, const QskGradient& gradient2 )
: m_stepCount( stepCount ) : m_stepCount( stepCount )
, m_color1( gradient1.startColor() ) , m_color1( gradient1.rgbStart() )
, m_color2( gradient2.endColor() ) , m_color2( gradient2.rgbEnd() )
, m_gradient( gradient2 ) , m_gradient( gradient2 )
{ {
} }
@ -1037,12 +1037,12 @@ static inline void qskRenderFillRandom(
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
const ColorMapSolid map( gradient.startColor() ); const ColorMapSolid map( gradient.rgbStart() );
qskRenderFillLines( metrics, orientation, line, map ); qskRenderFillLines( metrics, orientation, line, map );
} }
else else
{ {
const ColorMapGradient map( gradient.startColor(), gradient.endColor() ); const ColorMapGradient map( gradient.rgbStart(), gradient.rgbEnd() );
qskRenderFillLines( metrics, orientation, line, map ); qskRenderFillLines( metrics, orientation, line, map );
} }
} }
@ -1059,14 +1059,14 @@ static inline void qskRenderBoxRandom(
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
const ColorMapSolid fillMap( gradient.startColor() ); const ColorMapSolid fillMap( gradient.rgbStart() );
qskRenderLines( metrics, Qt::Vertical, borderLine, borderMap, fillLine, fillMap ); qskRenderLines( metrics, Qt::Vertical, borderLine, borderMap, fillLine, fillMap );
} }
else else
{ {
const auto orientation = qskQtOrientation( gradient ); const auto orientation = qskQtOrientation( gradient );
const ColorMapGradient fillMap( gradient.startColor(), gradient.endColor() ); const ColorMapGradient fillMap( gradient.rgbStart(), gradient.rgbEnd() );
qskRenderLines( metrics, orientation, borderLine, borderMap, fillLine, fillMap ); qskRenderLines( metrics, orientation, borderLine, borderMap, fillLine, fillMap );
} }
} }
@ -1086,14 +1086,14 @@ static inline void qskRenderBoxRandom(
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
const ColorMapSolid fillMap( gradient.startColor() ); const ColorMapSolid fillMap( gradient.rgbStart() );
qskRenderLines( metrics, Qt::Vertical, borderLine, tl, tr, bl, br, fillLine, fillMap ); qskRenderLines( metrics, Qt::Vertical, borderLine, tl, tr, bl, br, fillLine, fillMap );
} }
else else
{ {
const auto orientation = qskQtOrientation( gradient ); const auto orientation = qskQtOrientation( gradient );
const ColorMapGradient fillMap( gradient.startColor(), gradient.endColor() ); const ColorMapGradient fillMap( gradient.rgbStart(), gradient.rgbEnd() );
qskRenderLines( metrics, orientation, borderLine, tl, tr, bl, br, fillLine, fillMap ); qskRenderLines( metrics, orientation, borderLine, tl, tr, bl, br, fillLine, fillMap );
} }
} }

View File

@ -622,7 +622,7 @@ void QskBoxRenderer::renderRect(
if ( gd.isMonochrome() ) if ( gd.isMonochrome() )
{ {
const ColorMapSolid colorMap( gd.startColor() ); const ColorMapSolid colorMap( gd.rgbStart() );
qskCreateFillRandom( Qt::Vertical, in, colorMap, line ); qskCreateFillRandom( Qt::Vertical, in, colorMap, line );
} }
else else
@ -643,7 +643,7 @@ void QskBoxRenderer::renderRect(
const auto orientation = gd.linearDirection().isVertical() const auto orientation = gd.linearDirection().isVertical()
? Qt::Vertical : Qt::Horizontal; ? Qt::Vertical : Qt::Horizontal;
const ColorMapGradient colorMap( gd.startColor(), gd.endColor() ); const ColorMapGradient colorMap( gd.rgbStart(), gd.rgbEnd() );
qskCreateFillRandom( orientation, in, colorMap, line ); qskCreateFillRandom( orientation, in, colorMap, line );
} }
else else
@ -660,7 +660,7 @@ void QskBoxRenderer::renderRect(
if ( bc.isMonochrome() ) if ( bc.isMonochrome() )
{ {
const auto rgb = bc.left().startColor().rgba(); const auto rgb = bc.left().rgbStart();
qskCreateBorderMonochrome( rect, in, rgb, fillLines ); qskCreateBorderMonochrome( rect, in, rgb, fillLines );
} }
else else