6#include "QskRadioBoxSkinlet.h"
8#include "QskRadioBox.h"
9#include "QskFunctions.h"
11#include <qfontmetrics.h>
17 const QFontMetricsF& fm,
const QString& text )
21 auto hint = skinnable->
strutSizeHint( Q::CheckIndicatorPanel );
23 hint.rwidth() += skinnable->
spacingHint( Q::Button )
24 + qskHorizontalAdvance( fm, text );
25 hint.rheight() = qMax( hint.height(), fm.height() );
27 hint = hint.grownBy( skinnable->
paddingHint( Q::Button ) );
28 hint = hint.expandedTo( skinnable->
strutSizeHint( Q::Button ) );
33 QSizeF buttonSizeHint(
const QskRadioBox* radioBox,
int index )
35 const QFontMetrics fm( radioBox->
effectiveFont( QskRadioBox::Text ) );
36 return buttonSizeHint( radioBox, fm, radioBox->optionAt( index ) );
40QskRadioBoxSkinlet::QskRadioBoxSkinlet(
QskSkin* )
42 setNodeRoles( { PanelRole, ButtonRole, CheckPanelRole,
43 CheckIndicatorRole, TextRole } );
46QskRadioBoxSkinlet::~QskRadioBoxSkinlet()
50QRectF QskRadioBoxSkinlet::subControlRect(
const QskSkinnable* skinnable,
53 Q_UNUSED( skinnable );
54 Q_UNUSED( subcontrol );
59QSGNode* QskRadioBoxSkinlet::updateSubNode(
const QskSkinnable* skinnable,
60 quint8 nodeRole, QSGNode* node )
const
67 return updateBoxNode( skinnable, node, Q::Panel );
70 return updateSeriesNode( skinnable, Q::Button, node );
73 return updateSeriesNode( skinnable, Q::CheckIndicatorPanel, node );
75 case CheckIndicatorRole:
76 return updateSeriesNode( skinnable, Q::CheckIndicator, node );
79 return updateSeriesNode( skinnable, Q::Text, node );
82 return Inherited::updateSubNode( skinnable, nodeRole, node );
85int QskRadioBoxSkinlet::sampleCount(
88 const auto radioBox =
static_cast< const QskRadioBox*
>( skinnable );
89 return radioBox->options().count();
92QRectF QskRadioBoxSkinlet::buttonRect(
93 const QskRadioBox* radioBox,
const QRectF& rect,
int index )
const
102 const auto h = buttonSizeHint( radioBox, index ).height();
103 const auto y = index * ( h + radioBox->
spacingHint( Q::Panel ) );
106 return QRectF( r.left(), r.top() + y, r.width(), h );
109QRectF QskRadioBoxSkinlet::checkPanelRect(
const QskRadioBox* radioBox,
110 const QRectF& rect,
int index )
const
114 auto r = sampleRect( radioBox, rect, Q::Button, index );
115 r = radioBox->
innerBox( Q::Button, r );
117 auto alignment = radioBox->
alignmentHint( Q::CheckIndicatorPanel, Qt::AlignCenter );
119 alignment &= Qt::AlignVertical_Mask;
120 alignment |= radioBox->
layoutMirroring() ? Qt::AlignRight : Qt::AlignLeft;
122 auto size = radioBox->
strutSizeHint( Q::CheckIndicatorPanel );
123 size = size.grownBy( radioBox->
marginHint( Q::CheckIndicatorPanel ) );
125 return qskAlignedRectF( r, size.width(), size.height(), alignment );
128QRectF QskRadioBoxSkinlet::textRect(
const QskRadioBox* radioBox,
129 const QRectF& rect,
int index )
const
133 auto r = sampleRect( radioBox, rect, Q::Button, index );
134 r = radioBox->
innerBox( Q::Button, r );
136 const auto checkPanelRect = sampleRect(
137 radioBox, rect, Q::CheckIndicatorPanel, index );
139 const auto spacing = radioBox->
spacingHint( Q::Button );
142 r.setLeft( checkPanelRect.right() + spacing );
144 r.setRight( checkPanelRect.left() - spacing );
149QRectF QskRadioBoxSkinlet::sampleRect(
const QskSkinnable* skinnable,
154 auto radioBox =
static_cast< const QskRadioBox*
>( skinnable );
156 if( subControl == Q::Text )
157 return textRect( radioBox, rect, index );
159 if( subControl == Q::Button )
160 return buttonRect( radioBox, rect, index );
162 if( subControl == Q::CheckIndicatorPanel )
163 return checkPanelRect( radioBox, rect, index );
165 if( subControl == Q::CheckIndicator )
167 auto r = sampleRect( radioBox, rect, Q::CheckIndicatorPanel, index );
168 r = r.marginsRemoved( radioBox->
paddingHint( Q::CheckIndicatorPanel ) );
176QskAspect::States QskRadioBoxSkinlet::sampleStates(
181 auto radioBox =
static_cast< const QskRadioBox*
>( skinnable );
183 auto states = radioBox->skinStates();
185 if( radioBox->selectedIndex() == index )
186 states |= Q::Selected;
188 if( radioBox->pressedIndex() == index )
189 states |= Q::Pressed;
192 if( radioBox->positionHint( Q::CheckIndicator |
Q::Hovered ) == index )
195 states &=
~Q::Hovered;
197 if( radioBox->positionHint( Q::CheckIndicator ) == index )
200 states &=
~Q::Focused;
206QSGNode* QskRadioBoxSkinlet::updateSampleNode(
const QskSkinnable* skinnable,
211 auto radioBox =
static_cast< const QskRadioBox*
>( skinnable );
213 auto rect = sampleRect( skinnable, radioBox->
contentsRect(), subcontrol, index );
215 if( subcontrol == Q::Text )
217 Qt::Alignment alignment = Qt::AlignVCenter;
218 alignment |= ( radioBox->
layoutMirroring() ? Qt::AlignRight : Qt::AlignLeft );
220 alignment = radioBox->
alignmentHint( Q::Text, Qt::AlignCenter );
221 alignment &= Qt::AlignVertical_Mask;
222 alignment |= radioBox->
layoutMirroring() ? Qt::AlignRight : Qt::AlignLeft;
224 return updateTextNode( radioBox, node, rect,
225 alignment, radioBox->optionAt( index ), subcontrol );
228 if ( subcontrol == Q::CheckIndicatorPanel || subcontrol == Q::CheckIndicator )
229 return updateBoxNode( radioBox, node, rect, subcontrol );
234QSizeF QskRadioBoxSkinlet::sizeHint(
const QskSkinnable* skinnable,
235 Qt::SizeHint which,
const QSizeF& constraint )
const
239 if ( which != Qt::PreferredSize )
242 if ( constraint.width() >= 0.0 )
247 const auto radioBox =
static_cast< const QskRadioBox*
>( skinnable );
249 const QFontMetrics fm( radioBox->
effectiveFont( QskRadioBox::Text ) );
254 const auto options = radioBox->options();
255 for(
const auto& option : options )
257 const auto buttonSize = buttonSizeHint( radioBox, fm, option );
259 w = qMax( w, buttonSize.width() );
260 h += buttonSize.height();
263 if (
auto count = radioBox->options().count() )
264 h += ( count - 1 ) * skinnable->
spacingHint( Q::Panel );
267 hint = hint.grownBy( skinnable->
paddingHint( Q::Panel ) );
268 hint = hint.expandedTo( skinnable->
strutSizeHint( Q::Panel ) );
273#include "moc_QskRadioBoxSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
static const QskAspect::State Hovered
QRectF subControlContentsRect(QskAspect::Subcontrol) const
QRectF contentsRect() const
static const QskAspect::State Focused
bool layoutMirroring() const
qreal spacingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a spacing hint.
QMarginsF paddingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a padding hint.
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
QFont effectiveFont(QskAspect) const
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QRectF innerBox(QskAspect, const QRectF &outerBox) const
Calculate the rectangle, whith paddings, indentations being subtracted.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.