QskSkinlet cleanup by using QskBoxHints

This commit is contained in:
Uwe Rathmann 2025-03-11 11:21:02 +01:00
parent da1691eaa0
commit fbcce286d4
6 changed files with 66 additions and 112 deletions

View File

@ -9,6 +9,7 @@
#include <QskSGNode.h>
#include <QskTextOptions.h>
#include <QskTextColors.h>
#include <QskBoxHints.h>
#include <QskPlotCurve.h>
#include <QskPlotCorridor.h>
@ -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 )

View File

@ -6,7 +6,7 @@
#include "QskProgressBarSkinlet.h"
#include "QskProgressBar.h"
#include "QskIntervalF.h"
#include "QskBoxBorderMetrics.h"
#include "QskBoxHints.h"
#include <qeasingcurve.h>
#include <cmath>
@ -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(

View File

@ -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(

View File

@ -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& );

View File

@ -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 );

View File

@ -9,14 +9,8 @@
#include "QskGlobal.h"
#include <qsgnode.h>
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