From e9947c17a0cbee840f8226b1e4891001c58fbca8 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 24 Sep 2024 12:23:51 +0200 Subject: [PATCH] QskGradient::effectiveGradient moved to QskBoxRenderer::effectiveFradient as its implementation is not correct for arcs --- playground/gradients/GradientQuickShape.cpp | 3 ++- src/common/QskGradient.cpp | 15 --------------- src/common/QskGradient.h | 2 -- src/nodes/QskBoxRectangleNode.cpp | 6 +++--- src/nodes/QskBoxRenderer.cpp | 15 +++++++++++++++ src/nodes/QskBoxRenderer.h | 2 ++ 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/playground/gradients/GradientQuickShape.cpp b/playground/gradients/GradientQuickShape.cpp index cfe00b13..d71fd03c 100644 --- a/playground/gradients/GradientQuickShape.cpp +++ b/playground/gradients/GradientQuickShape.cpp @@ -7,6 +7,7 @@ #include #include +#include QSK_QT_PRIVATE_BEGIN @@ -54,7 +55,7 @@ namespace { QQuickShapeGradient* shapeGradient = nullptr; - auto effectiveGradient = gradient.effectiveGradient(); + auto effectiveGradient = QskBoxRenderer::effectiveGradient( gradient ); effectiveGradient.stretchTo( rect ); switch( static_cast< int >( effectiveGradient.type() ) ) diff --git a/src/common/QskGradient.cpp b/src/common/QskGradient.cpp index 3a66b5e8..7d552076 100644 --- a/src/common/QskGradient.cpp +++ b/src/common/QskGradient.cpp @@ -722,21 +722,6 @@ void QskGradient::resetDirection() m_values[0] = m_values[1] = m_values[2] = m_values[3] = m_values[4] = 0.0; } -QskGradient QskGradient::effectiveGradient() const -{ - if ( ( m_type == QskGradient::Stops ) || isMonochrome() ) - { - // the shader for linear gradients is the fastest - - QskGradient g = *this; - g.setDirection( QskGradient::Linear ); - - return g; - } - - return *this; -} - QGradient QskGradient::toQGradient() const { QGradient g; diff --git a/src/common/QskGradient.h b/src/common/QskGradient.h index 7e5fd665..f6757902 100644 --- a/src/common/QskGradient.h +++ b/src/common/QskGradient.h @@ -152,8 +152,6 @@ class QSK_EXPORT QskGradient QskGradient stretchedTo( const QSizeF& ) const; QskGradient stretchedTo( const QRectF& ) const; - QskGradient effectiveGradient() const; - static QVariant interpolate( const QskGradient&, const QskGradient&, qreal progress ); diff --git a/src/nodes/QskBoxRectangleNode.cpp b/src/nodes/QskBoxRectangleNode.cpp index 36f31d83..461e558b 100644 --- a/src/nodes/QskBoxRectangleNode.cpp +++ b/src/nodes/QskBoxRectangleNode.cpp @@ -103,7 +103,7 @@ void QskBoxRectangleNode::updateFilling( const QRectF& rect, return; } - const auto fillGradient = gradient.effectiveGradient(); + const auto fillGradient = QskBoxRenderer::effectiveGradient( gradient ); const auto shape = shapeMetrics.toAbsolute( rect.size() ); const bool coloredGeometry = hasHint( PreferColoredGeometry ) @@ -211,13 +211,13 @@ void QskBoxRectangleNode::updateBox( const QRectF& rect, if ( isDirty ) { /* - For monochrome border/fiiling with the same color we might be + For monochrome border/filling with the same color we might be able to do QskFillNode::Monochrome. However this is not implemeted in QskBoxRenderer yet. TODO ... */ setColoring( QskFillNode::Polychrome ); - auto fillGradient = gradient.effectiveGradient(); + auto fillGradient = QskBoxRenderer::effectiveGradient( gradient ); if ( !QskBoxRenderer::isGradientSupported( fillGradient ) ) { qWarning() << "QskBoxRenderer does not support radial/conic gradients"; diff --git a/src/nodes/QskBoxRenderer.cpp b/src/nodes/QskBoxRenderer.cpp index cb432d3c..eadd6693 100644 --- a/src/nodes/QskBoxRenderer.cpp +++ b/src/nodes/QskBoxRenderer.cpp @@ -231,3 +231,18 @@ void QskBoxRenderer::setColoredBorderAndFillLines( const QRectF& rect, } } } + +QskGradient QskBoxRenderer::effectiveGradient( const QskGradient& gradient ) +{ + if ( ( gradient.type() == QskGradient::Stops ) || gradient.isMonochrome() ) + { + // the shader for linear gradients is the fastest + + auto g = gradient; + g.setDirection( QskGradient::Linear ); + + return g; + } + + return gradient; +} diff --git a/src/nodes/QskBoxRenderer.h b/src/nodes/QskBoxRenderer.h index 2f8c89fc..9b30eb88 100644 --- a/src/nodes/QskBoxRenderer.h +++ b/src/nodes/QskBoxRenderer.h @@ -54,6 +54,8 @@ namespace QskBoxRenderer QSK_EXPORT void setColoredBorderAndFillLines( const QRectF&, const QskBoxShapeMetrics&, const QskBoxBorderMetrics&, const QskBoxBorderColors&, const QskGradient&, QSGGeometry& ); + + QSK_EXPORT QskGradient effectiveGradient( const QskGradient& ); } #endif