6#include "QskGraphicLabelSkinlet.h"
7#include "QskGraphicLabel.h"
10#include "QskColorFilter.h"
11#include "QskFunctions.h"
12#include "QskGraphic.h"
16QskGraphicLabelSkinlet::QskGraphicLabelSkinlet(
QskSkin* skin )
19 setNodeRoles( { PanelRole, GraphicRole } );
22QskGraphicLabelSkinlet::~QskGraphicLabelSkinlet() =
default;
24QRectF QskGraphicLabelSkinlet::subControlRect(
const QskSkinnable* skinnable,
27 if ( subControl == QskGraphicLabel::Panel )
31 else if ( subControl == QskGraphicLabel::Graphic )
33 auto innerRect = contentsRect;
37 if ( label->hasPanel() )
40 innerRect, QskGraphicLabel::Panel );
43 return graphicRect( label, innerRect );
46 return Inherited::subControlRect( skinnable, contentsRect, subControl );
49QSGNode* QskGraphicLabelSkinlet::updateSubNode(
50 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
58 if ( !label->hasPanel() )
61 return updateBoxNode( label, node, QskGraphicLabel::Panel );
65 return updateGraphicNode( label, node );
69 return Inherited::updateSubNode( skinnable, nodeRole, node );
72QRect QskGraphicLabelSkinlet::graphicRect(
80 const auto fillMode = label->fillMode();
82 const QRect graphicRect = contentsRect.toAlignedRect();
84 if ( fillMode == Q::Stretch )
89 QSizeF sz = label->effectiveSourceSize();
91 if ( fillMode == Q::PreserveAspectFit )
93 sz.scale( graphicRect.size(), Qt::KeepAspectRatio );
95 else if ( fillMode == Q::PreserveAspectCrop )
97 sz.scale( graphicRect.size(), Qt::KeepAspectRatioByExpanding );
100 return qskAlignedRect( graphicRect,
101 qCeil( sz.width() ), qCeil( sz.height() ), label->alignment() );
104QSGNode* QskGraphicLabelSkinlet::updateGraphicNode(
109 const auto colorFilter = label->graphicFilter();
112 Qt::Orientations mirrored;
113 if ( label->mirror() )
114 mirrored = Qt::Horizontal;
116 if ( label->fillMode() == Q::Stretch )
118 node = QskSkinlet::updateGraphicNode( label, node,
119 label->graphic(), colorFilter, rect, mirrored );
123 node = QskSkinlet::updateGraphicNode( label, node,
124 label->graphic(), colorFilter, rect, Qt::AlignCenter, mirrored );
130QSizeF QskGraphicLabelSkinlet::sizeHint(
const QskSkinnable* skinnable,
131 Qt::SizeHint which,
const QSizeF& constraint )
const
135 if ( which != Qt::PreferredSize )
138 const bool hasConstraint =
139 ( constraint.width() >= 0.0 ) || ( constraint.height() >= 0.0 );
142 const auto sourceSize = label->effectiveSourceSize();
144 auto hint = sourceSize;
146 if ( hasConstraint && !sourceSize.isEmpty() )
148 auto innerConstraint = constraint;
150 if ( label->hasPanel() )
152 constexpr qreal max = std::numeric_limits< int >::max();
154 QRectF r( 0.0, 0.0, max, max );
156 if ( constraint.width() >= 0.0 )
157 r.setWidth( constraint.width() );
159 r.setHeight( constraint.height() );
164 const qreal aspectRatio = sourceSize.width() / sourceSize.height();
166 if ( constraint.width() >= 0.0 )
167 hint.setHeight( innerConstraint.width() / aspectRatio );
169 hint.setWidth( innerConstraint.height() * aspectRatio );
172 hint = hint.expandedTo( label->
strutSizeHint( Q::Graphic ) );
174 if ( label->hasPanel() )
181 hint = hintWithoutConstraint( hint, constraint );
186#include "moc_QskGraphicLabelSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
QRectF subControlContentsRect(QskAspect::Subcontrol) const
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QSizeF outerBoxSize(QskAspect, const QSizeF &innerBoxSize) const
Calculate the size, when being expanded by paddings, indentations.