From fbcce286d438ceb8796b6da3a657f8ba5edc06e8 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 11 Mar 2025 11:21:02 +0100 Subject: [PATCH] QskSkinlet cleanup by using QskBoxHints --- playground/plots/PlotCursorSkinlet.cpp | 7 ++- src/controls/QskProgressBarSkinlet.cpp | 74 ++++++++++++-------------- src/controls/QskSkinlet.cpp | 58 +++++--------------- src/controls/QskSkinlet.h | 7 --- src/nodes/QskBoxNode.cpp | 19 +++---- src/nodes/QskBoxNode.h | 13 +---- 6 files changed, 66 insertions(+), 112 deletions(-) diff --git a/playground/plots/PlotCursorSkinlet.cpp b/playground/plots/PlotCursorSkinlet.cpp index 48095c24..1bd3857c 100644 --- a/playground/plots/PlotCursorSkinlet.cpp +++ b/playground/plots/PlotCursorSkinlet.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -143,8 +144,10 @@ QSGNode* PlotCursorSkinlet::updateSampleNode( const QskSkinnable* skinnable, if ( subControl == Q::LabelPanel ) { - const auto gradient = skinnable->gradientHint( aspect ); - return updateBoxNode( skinnable, node, rect, gradient, subControl ); + auto hints = skinnable->boxHints( subControl ); + hints.gradient = skinnable->gradientHint( aspect ); + + return updateBoxNode( skinnable, node, rect, hints ); } if ( subControl == Q::LabelText ) diff --git a/src/controls/QskProgressBarSkinlet.cpp b/src/controls/QskProgressBarSkinlet.cpp index f3b99a37..a2095b0b 100644 --- a/src/controls/QskProgressBarSkinlet.cpp +++ b/src/controls/QskProgressBarSkinlet.cpp @@ -6,7 +6,7 @@ #include "QskProgressBarSkinlet.h" #include "QskProgressBar.h" #include "QskIntervalF.h" -#include "QskBoxBorderMetrics.h" +#include "QskBoxHints.h" #include #include @@ -50,41 +50,6 @@ static QskIntervalF qskFillInterval( const QskProgressIndicator* indicator ) return QskIntervalF( pos1, pos2 ); } -static QskGradient qskFillGradient( const QskProgressBar* progressBar ) -{ - auto gradient = progressBar->gradientHint( Q::Fill ); - - if ( gradient.isVisible() && !gradient.isMonochrome() - && ( gradient.type() == QskGradient::Stops ) ) - { - /* - When having stops only we use a linear gradient, - where the colors are increasing in direction of the - progress value. We interprete the gradient as a - definition for the 100% situation and have to adjust - the stops for smaller bars. - - For this situation it would be more convenient to - adjust the start/stop positions, but the box renderer is - not supporting this yet. TODO ... - */ - - const auto intv = qskFillInterval( progressBar ); - - const auto stops = qskExtractedGradientStops( - gradient.stops(), intv.lowerBound(), intv.upperBound() ); - - gradient.setStops( stops ); - - gradient.setLinearDirection( progressBar->orientation() ); - - if ( progressBar->orientation() == Qt::Vertical || progressBar->layoutMirroring() ) - gradient.reverse(); - } - - return gradient; -} - QskProgressBarSkinlet::QskProgressBarSkinlet( QskSkin* skin ) : Inherited( skin ) { @@ -122,9 +87,40 @@ QSGNode* QskProgressBarSkinlet::updateFillNode( if ( rect.isEmpty() ) return nullptr; - const auto progressBar = static_cast< const Q* >( indicator ); - return updateBoxNode( indicator, node, rect, - qskFillGradient( progressBar ), Q::Fill ); + auto hints = indicator->boxHints( Q::Fill ); + + auto& gradient = hints.gradient; + + if ( gradient.isVisible() && !gradient.isMonochrome() + && ( gradient.type() == QskGradient::Stops ) ) + { + /* + When having stops only we use a linear gradient, + where the colors are increasing in direction of the + progress value. We interprete the gradient as a + definition for the 100% situation and have to adjust + the stops for smaller bars. + + For this situation it would be more convenient to + adjust the start/stop positions, but the box renderer is + not supporting this yet. TODO ... + */ + + const auto intv = qskFillInterval( indicator ); + + const auto stops = qskExtractedGradientStops( + gradient.stops(), intv.lowerBound(), intv.upperBound() ); + + gradient.setStops( stops ); + + const auto orientation = static_cast< const Q* >( indicator )->orientation(); + gradient.setLinearDirection( orientation ); + + if ( orientation == Qt::Vertical || indicator->layoutMirroring() ) + gradient.reverse(); + } + + return updateBoxNode( indicator, node, rect, hints ); } QRectF QskProgressBarSkinlet::grooveRect( diff --git a/src/controls/QskSkinlet.cpp b/src/controls/QskSkinlet.cpp index de23fe99..8a6caf7c 100644 --- a/src/controls/QskSkinlet.cpp +++ b/src/controls/QskSkinlet.cpp @@ -202,22 +202,18 @@ static inline QQuickWindow* qskWindowOfSkinnable( const QskSkinnable* skinnable return nullptr; } -static inline QSGNode* qskUpdateBoxNode( - const QskSkinnable* skinnable, QSGNode* node, const QRectF& rect, - const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics, - const QskBoxBorderColors& borderColors, const QskGradient& gradient, - const QskShadowMetrics& shadowMetrics, const QColor& shadowColor ) +static inline QSGNode* qskUpdateBoxNode( const QskSkinnable* skinnable, + QSGNode* node, const QRectF& rect, const QskBoxHints& hints ) { if ( !rect.isEmpty() ) { - if ( qskIsBoxVisible( borderMetrics, borderColors, gradient ) - || qskIsShadowVisible( shadowMetrics, shadowColor ) ) + if ( qskIsBoxVisible( hints.borderMetrics, hints.borderColors, hints.gradient ) + || qskIsShadowVisible( hints.shadowMetrics, hints.shadowColor ) ) { if ( auto window = qskWindowOfSkinnable( skinnable ) ) { auto boxNode = QskSGNode::ensureNode< QskBoxNode >( node ); - boxNode->updateNode( window, rect, shape, borderMetrics, - borderColors, gradient, shadowMetrics, shadowColor ); + boxNode->updateNode( window, rect, hints ); return boxNode; } @@ -435,53 +431,27 @@ QSGNode* QskSkinlet::updateBoxNode( const QskSkinnable* skinnable, QSGNode* node, QskAspect::Subcontrol subControl ) const { const auto rect = qskSubControlRect( this, skinnable, subControl ); - return updateBoxNode( skinnable, node, rect, subControl ); + if ( rect.isEmpty() ) + return nullptr; + + return qskUpdateBoxNode( skinnable, node, + rect, skinnable->boxHints( subControl ) ); } QSGNode* QskSkinlet::updateBoxNode( const QskSkinnable* skinnable, QSGNode* node, const QRectF& rect, QskAspect::Subcontrol subControl ) { - const auto fillGradient = skinnable->gradientHint( subControl ); - return updateBoxNode( skinnable, node, rect, fillGradient, subControl ); -} - -QSGNode* QskSkinlet::updateBoxNode( const QskSkinnable* skinnable, - QSGNode* node, const QRectF& rect, const QskGradient& fillGradient, - QskAspect::Subcontrol subControl ) -{ - const auto margins = skinnable->marginHint( subControl ); - - const auto boxRect = rect.marginsRemoved( margins ); - if ( boxRect.isEmpty() ) + if ( rect.isEmpty() ) return nullptr; - const auto borderMetrics = skinnable->boxBorderMetricsHint( subControl ); - const auto borderColors = skinnable->boxBorderColorsHint( subControl ); - const auto shape = skinnable->boxShapeHint( subControl ); - const auto shadowMetrics = skinnable->shadowMetricsHint( subControl ); - const auto shadowColor = skinnable->shadowColorHint( subControl ); - - return qskUpdateBoxNode( skinnable, node, - boxRect, shape, borderMetrics, borderColors, fillGradient, - shadowMetrics, shadowColor ); -} - -QSGNode* QskSkinlet::updateBoxNode( - const QskSkinnable* skinnable, QSGNode* node, const QRectF& rect, - const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics, - const QskBoxBorderColors& borderColors, const QskGradient& fillGradient ) -{ - return qskUpdateBoxNode( skinnable, node, - rect, shape, borderMetrics, borderColors, fillGradient, - QskShadowMetrics(), QColor() ); + const auto hints = skinnable->boxHints( subControl ); + return qskUpdateBoxNode( skinnable, node, rect, hints ); } QSGNode* QskSkinlet::updateBoxNode( const QskSkinnable* skinnable, QSGNode* node, const QRectF& rect, const QskBoxHints& hints ) { - return qskUpdateBoxNode( skinnable, node, rect, - hints.shape, hints.borderMetrics, hints.borderColors, hints.gradient, - hints.shadowMetrics, hints.shadowColor ); + return qskUpdateBoxNode( skinnable, node, rect, hints ); } QSGNode* QskSkinlet::updateInterpolatedBoxNode( diff --git a/src/controls/QskSkinlet.h b/src/controls/QskSkinlet.h index c13142bd..cd4ffa0a 100644 --- a/src/controls/QskSkinlet.h +++ b/src/controls/QskSkinlet.h @@ -76,13 +76,6 @@ class QSK_EXPORT QskSkinlet static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*, const QRectF&, QskAspect::Subcontrol ); - static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*, - const QRectF&, const QskGradient&, QskAspect::Subcontrol ); - - static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*, - const QRectF&, const QskBoxShapeMetrics&, const QskBoxBorderMetrics&, - const QskBoxBorderColors&, const QskGradient& ); - static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*, const QRectF&, const QskBoxHints& ); diff --git a/src/nodes/QskBoxNode.cpp b/src/nodes/QskBoxNode.cpp index a787c8e9..64ff3485 100644 --- a/src/nodes/QskBoxNode.cpp +++ b/src/nodes/QskBoxNode.cpp @@ -8,12 +8,8 @@ #include "QskBoxRectangleNode.h" #include "QskSGNode.h" -#include "QskGradient.h" +#include "QskBoxHints.h" #include "QskGradientDirection.h" -#include "QskShadowMetrics.h" -#include "QskBoxBorderMetrics.h" -#include "QskBoxBorderColors.h" -#include "QskBoxShapeMetrics.h" #include "QskRgbValue.h" namespace @@ -60,10 +56,8 @@ QskBoxNode::~QskBoxNode() { } -void QskBoxNode::updateNode( const QQuickWindow* window, const QRectF& rect, - const QskBoxShapeMetrics& shapeMetrics, const QskBoxBorderMetrics& borderMetrics, - const QskBoxBorderColors& borderColors, const QskGradient& gradient, - const QskShadowMetrics& shadowMetrics, const QColor& shadowColor ) +void QskBoxNode::updateNode( const QQuickWindow* window, + const QRectF& rect, const QskBoxHints& hints ) { using namespace QskSGNode; @@ -74,6 +68,13 @@ void QskBoxNode::updateNode( const QQuickWindow* window, const QRectF& rect, if ( !rect.isEmpty() ) { + const auto& shapeMetrics = hints.shape; + const auto& borderMetrics = hints.borderMetrics; + const auto& borderColors = hints.borderColors; + const auto& gradient = hints.gradient; + const auto& shadowMetrics = hints.shadowMetrics; + const auto& shadowColor = hints.shadowColor; + const auto hasFilling = gradient.isVisible(); const auto hasBorder = !borderMetrics.isNull() && borderColors.isVisible(); const auto hasShadow = !shadowMetrics.isNull() && QskRgb::isVisible( shadowColor ); diff --git a/src/nodes/QskBoxNode.h b/src/nodes/QskBoxNode.h index 8e14d668..7e2ffd3f 100644 --- a/src/nodes/QskBoxNode.h +++ b/src/nodes/QskBoxNode.h @@ -9,14 +9,8 @@ #include "QskGlobal.h" #include -class QskShadowMetrics; -class QskBoxShapeMetrics; -class QskBoxBorderMetrics; -class QskBoxBorderColors; -class QskGradient; -class QskShadowMetrics; +class QskBoxHints; class QQuickWindow; -class QColor; class QSK_EXPORT QskBoxNode : public QSGNode { @@ -24,10 +18,7 @@ class QSK_EXPORT QskBoxNode : public QSGNode QskBoxNode(); ~QskBoxNode() override; - void updateNode( const QQuickWindow*, const QRectF&, - const QskBoxShapeMetrics&, const QskBoxBorderMetrics&, - const QskBoxBorderColors&, const QskGradient&, - const QskShadowMetrics&, const QColor& shadowColor ); + void updateNode( const QQuickWindow*, const QRectF&, const QskBoxHints& ); }; #endif