6#include "QskSwitchButtonSkinlet.h"
7#include "QskSwitchButton.h"
11static inline qreal qskEffectivePosition(
const QskSwitchButton* switchButton )
13 auto pos = switchButton->positionHint( QskSwitchButton::Handle );
14 pos = qBound( 0.0, pos, 1.0 );
16 if( switchButton->isInverted() )
19 if ( switchButton->orientation() == Qt::Horizontal )
30 if( button->iconMode() == Q::NoIcon
31 || ( button->iconMode() == Q::ShowIconWhenSelected && !button->isChecked() ) )
41QskSwitchButtonSkinlet::QskSwitchButtonSkinlet(
QskSkin* skin )
44 setNodeRoles( { GrooveRole, HandleRole, IconRole } );
47QskSwitchButtonSkinlet::~QskSwitchButtonSkinlet()
51QRectF QskSwitchButtonSkinlet::subControlRect(
const QskSkinnable* skinnable,
54 const auto button =
static_cast< const Q*
>( skinnable );
56 if ( subControl == Q::Groove )
58 return grooveRect( button, contentsRect );
61 if ( subControl == Q::Handle )
63 return handleRect( button, contentsRect );
66 if ( subControl == Q::Icon )
68 return iconRect( button, contentsRect );
71 return Inherited::subControlRect( skinnable, contentsRect, subControl );
74QSizeF QskSwitchButtonSkinlet::sizeHint(
const QskSkinnable* skinnable,
75 Qt::SizeHint which,
const QSizeF& )
const
77 if ( which != Qt::PreferredSize )
80 const auto grooveHint = skinnable->
strutSizeHint( QskSwitchButton::Groove );
81 const auto handleHint = skinnable->
strutSizeHint( QskSwitchButton::Handle );
83 auto hint = grooveHint;
84 hint = hint.expandedTo( handleHint );
89QSGNode* QskSwitchButtonSkinlet::updateSubNode(
const QskSkinnable* skinnable,
90 quint8 nodeRole, QSGNode* node )
const
95 return updateBoxNode( skinnable, node, Q::Handle );
98 return updateSymbolNode( skinnable, node, Q::Icon );
101 return updateBoxNode( skinnable, node, Q::Groove );
104 return Inherited::updateSubNode( skinnable, nodeRole, node );
107QRectF QskSwitchButtonSkinlet::grooveRect(
112 if ( button->orientation() == Qt::Vertical )
114 if ( size.height() < 0.0 )
117 size.setHeight( 2 * handleSize.height() );
122 if ( size.width() < 0.0 )
125 size.setWidth( 2 * handleSize.width() );
129 size = size.expandedTo( QSize( 0.0, 0.0 ) );
133 r.moveCenter( contentsRect.center() );
138QRectF QskSwitchButtonSkinlet::handleRect(
141 const auto grooveRect = subControlRect( button, contentsRect, Q::Groove );
142 const auto pos = qskEffectivePosition( button );
148 if( button->orientation() == Qt::Vertical )
150 const qreal y0 = grooveRect.y() + 0.5 * size.height();
151 const qreal h = grooveRect.height() - size.height();
153 cx = grooveRect.x() + 0.5 * grooveRect.width();
158 const qreal x0 = grooveRect.x() + 0.5 * size.width();
159 const qreal w = grooveRect.width() - size.width();
162 cy = grooveRect.y() + 0.5 * grooveRect.height();
165 auto iconSize = qskIconSize( button );
167 if( !iconSize.isNull() )
173 auto margins = button->
marginHint( Q::Handle );
175 iconSize = iconSize.grownBy( padding ).grownBy( margins );
176 size = size.expandedTo( iconSize );
181 r.moveCenter( QPointF( cx, cy ) );
186QRectF QskSwitchButtonSkinlet::iconRect(
const QskSwitchButton* button,
const QRectF& contentsRect )
const
189 rect.setSize( qskIconSize( button ) );
190 const auto hr = handleRect( button, contentsRect );
191 rect.moveCenter( hr.center() );
196#include "moc_QskSwitchButtonSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
bool layoutMirroring() const
QMarginsF paddingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a padding hint.
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.