6#include "QskCheckBoxSkinlet.h"
7#include "QskCheckBox.h"
8#include "QskTextOptions.h"
9#include "QskFunctions.h"
11QskCheckBoxSkinlet::QskCheckBoxSkinlet(
QskSkin* skin )
14 setNodeRoles( { BoxRole, IndicatorRole, TextRole } );
17QskCheckBoxSkinlet::~QskCheckBoxSkinlet()
21QRectF QskCheckBoxSkinlet::subControlRect(
const QskSkinnable* skinnable,
26 const auto checkBox =
static_cast< const QskCheckBox*
>( skinnable );
28 if ( subControl == Q::Panel )
31 if ( subControl == Q::Box )
32 return boxRect( checkBox, contentsRect );
34 if ( subControl == Q::Indicator )
36 const auto boxRect = subControlRect( skinnable, contentsRect, Q::Box );
37 return skinnable->
innerBox( Q::Box, boxRect );
40 if ( subControl == Q::Text )
41 return textRect( checkBox, contentsRect );
46QRectF QskCheckBoxSkinlet::textRect(
47 const QskCheckBox* checkBox,
const QRectF& contentsRect )
const
51 const auto boxRect = subControlRect( checkBox, contentsRect, Q::Box );
52 const qreal spacing = checkBox->
spacingHint( Q::Panel );
54 auto r = subControlRect( checkBox, contentsRect, Q::Panel );
55 r = checkBox->
innerBox( Q::Panel, r );
58 r.setRight( boxRect.left() - spacing );
60 r.setLeft( boxRect.right() + spacing );
65QRectF QskCheckBoxSkinlet::boxRect(
66 const QskCheckBox* checkBox,
const QRectF& contentsRect )
const
68 const auto size = checkBox->
strutSizeHint( QskCheckBox::Box );
70 auto r = checkBox->
innerBox( QskCheckBox::Panel, contentsRect );
73 r.setLeft( r.right() - size.width() );
75 r.setWidth( size.width() );
77 r.setTop( r.top() + 0.5 * ( r.height() - size.height() ) );
78 r.setHeight( size.height() );
83QSGNode* QskCheckBoxSkinlet::updateSubNode(
84 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
88 auto checkBox =
static_cast< const QskCheckBox*
>( skinnable );
93 return updateBoxNode( skinnable, node, Q::Panel );
96 return updateBoxNode( skinnable, node, Q::Box );
99 return updateSymbolNode( checkBox, node, Q::Indicator );
102 return updateTextNode( checkBox, node );
105 return Inherited::updateSubNode( skinnable, nodeRole, node );
108QSGNode* QskCheckBoxSkinlet::updateTextNode(
115 ? Qt::AlignRight : Qt::AlignLeft;
117 return QskSkinlet::updateTextNode( checkBox, node,
118 rect, alignH | Qt::AlignVCenter, checkBox->text(), Q::Text );
121QSizeF QskCheckBoxSkinlet::sizeHint(
const QskSkinnable* skinnable,
122 Qt::SizeHint which,
const QSizeF& )
const
126 if ( which != Qt::PreferredSize )
129 auto checkBox =
static_cast< const QskCheckBox*
>( skinnable );
134 auto text = checkBox->text();
135 if ( !text.isEmpty() )
139 if ( which == Qt::MinimumSize )
143 extra += qskHorizontalAdvance( font, text );
145 size.setWidth( size.width() + extra );
148 return size.expandedTo( skinnable->
strutSizeHint( Q::Panel ) );
151#include "moc_QskCheckBoxSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
bool layoutMirroring() const
Describes the rendering interface of a QskControl. Change the skinlet to change the appearance of the...
qreal spacingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a spacing hint.
QFont effectiveFont(QskAspect) 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.
QRectF innerBox(QskAspect, const QRectF &outerBox) const
Calculate the rectangle, whith paddings, indentations being subtracted.