6#include "QskComboBoxSkinlet.h"
7#include "QskComboBox.h"
10#include "QskLabelData.h"
13#include "QskSubcontrolLayoutEngine.h"
23 setSpacing( box->
spacingHint( QskComboBox::Panel ) );
28 if ( box->currentIndex() >= 0 )
30 const auto option = box->optionAt( box->currentIndex() );
32 graphicSize = option.icon().graphic().defaultSize();
37 text = box->placeholderText();
40 setGraphicTextElements( box,
41 QskComboBox::Text, text, QskComboBox::Icon, graphicSize );
44 QskComboBox::Panel, Qt::AlignLeft );
46 setFixedContent( QskComboBox::Text, Qt::Horizontal, alignment );
51QskComboBoxSkinlet::QskComboBoxSkinlet(
QskSkin* skin )
54 setNodeRoles( { PanelRole, IconRole, TextRole, StatusIndicatorRole } );
57QskComboBoxSkinlet::~QskComboBoxSkinlet() =
default;
59QRectF QskComboBoxSkinlet::subControlRect(
const QskSkinnable* skinnable,
64 const auto* box =
static_cast< const QskComboBox*
>( skinnable );
66 if ( subControl == Q::Panel )
69 if ( subControl == Q::Text || subControl == Q::Icon )
73 LayoutEngine layoutEngine( box );
74 layoutEngine.setGeometries( r );
76 return layoutEngine.subControlRect( subControl );
79 if( subControl == Q::StatusIndicator )
81 auto rect = box->
innerBox( Q::Panel, contentsRect );
83 rect.setLeft( rect.right() - size.width() );
87 return Inherited::subControlRect( skinnable, contentsRect, subControl );
90QSGNode* QskComboBoxSkinlet::updateSubNode(
91 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
95 const auto box =
static_cast< const QskComboBox*
>( skinnable );
100 return updateBoxNode( box, node, Q::Panel );
104 const auto option = box->optionAt( box->currentIndex() );
105 return updateGraphicNode( box, node,
106 option.icon().graphic(), Q::Icon );
110 return updateTextNode( box, node );
112 case StatusIndicatorRole:
113 return updateSymbolNode( box, node, Q::StatusIndicator );
116 return Inherited::updateSubNode( skinnable, nodeRole, node );
119QSGNode* QskComboBoxSkinlet::updateTextNode(
126 const auto textHeight = box->effectiveFontHeight( Q::Text );
127 if ( !box->clip() && ( rect.height() < textHeight ) )
130 const auto alignment = box->
alignmentHint( Q::Text, Qt::AlignLeft | Qt::AlignVCenter );
132 return QskSkinlet::updateTextNode( box, node, rect,
133 alignment, box->currentText(), Q::Text );
136QSizeF QskComboBoxSkinlet::sizeHint(
const QskSkinnable* skinnable,
137 Qt::SizeHint which,
const QSizeF& )
const
141 if ( which != Qt::PreferredSize )
144 const auto box =
static_cast< const QskComboBox*
>( skinnable );
146 LayoutEngine layoutEngine( box );
147 auto size = layoutEngine.sizeHint( which, QSizeF() );
149 const auto spacingHint = box->
spacingHint( Q::Panel );
150 const auto menuGraphicHint = box->
strutSizeHint( Q::StatusIndicator );
152 size.rwidth() += spacingHint + menuGraphicHint.width();
156 size = size.grownBy( skinnable->
marginHint( Q::Panel ) );
161#include "moc_QskComboBoxSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
QRectF subControlContentsRect(QskAspect::Subcontrol) const
qreal spacingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a spacing hint.
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
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.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.