6#include "QskComboBoxSkinlet.h"
7#include "QskComboBox.h"
10#include "QskLabelData.h"
11#include "QskTextOptions.h"
14#include "QskSubcontrolLayoutEngine.h"
15#include "QskTextRenderer.h"
17#include <qfontmetrics.h>
26 for (
int i = 0; i < box->count(); i++ )
28 const auto option = box->optionAt( i );
30 const auto size = QskTextRenderer::textSize(
33 if ( size.width() > w )
48 LayoutEngine(
const QskComboBox* box,
int index = -1 )
51 setSpacing( box->
spacingHint( QskComboBox::Panel ) );
58 if ( box->currentIndex() >= 0 )
60 const auto option = box->optionAt( box->currentIndex() );
62 graphicSize = option.icon().graphic().defaultSize();
67 text = box->placeholderText();
72 const auto option = box->optionAt( index );
74 graphicSize = option.icon().graphic().defaultSize();
78 setGraphicTextElements( box,
79 QskComboBox::Text, text, QskComboBox::Icon, graphicSize );
82 QskComboBox::Panel, Qt::AlignLeft );
84 setFixedContent( QskComboBox::Text, Qt::Horizontal, alignment );
89QskComboBoxSkinlet::QskComboBoxSkinlet(
QskSkin* skin )
92 setNodeRoles( { PanelRole, IconRole, TextRole, StatusIndicatorRole } );
95QskComboBoxSkinlet::~QskComboBoxSkinlet() =
default;
97QRectF QskComboBoxSkinlet::subControlRect(
const QskSkinnable* skinnable,
102 const auto* box =
static_cast< const QskComboBox*
>( skinnable );
104 if ( subControl == Q::Panel )
107 if ( subControl == Q::Text || subControl == Q::Icon )
111 LayoutEngine layoutEngine( box );
112 layoutEngine.setGeometries( r );
114 return layoutEngine.subControlRect( subControl );
117 if( subControl == Q::StatusIndicator )
119 auto rect = box->
innerBox( Q::Panel, contentsRect );
121 rect.setLeft( rect.right() - size.width() );
125 return Inherited::subControlRect( skinnable, contentsRect, subControl );
128QSGNode* QskComboBoxSkinlet::updateSubNode(
129 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
133 const auto box =
static_cast< const QskComboBox*
>( skinnable );
138 return updateBoxNode( box, node, Q::Panel );
142 const auto option = box->optionAt( box->currentIndex() );
143 return updateGraphicNode( box, node,
144 option.icon().graphic(), Q::Icon );
148 return updateTextNode( box, node );
150 case StatusIndicatorRole:
151 return updateSymbolNode( box, node, Q::StatusIndicator );
154 return Inherited::updateSubNode( skinnable, nodeRole, node );
157QSGNode* QskComboBoxSkinlet::updateTextNode(
164 const auto textHeight = box->effectiveFontHeight( Q::Text );
165 if ( !box->clip() && ( rect.height() < textHeight ) )
168 const auto alignment = box->
alignmentHint( Q::Text, Qt::AlignLeft | Qt::AlignVCenter );
170 return QskSkinlet::updateTextNode( box, node, rect,
171 alignment, box->currentText(), Q::Text );
174QSizeF QskComboBoxSkinlet::sizeHint(
const QskSkinnable* skinnable,
175 Qt::SizeHint which,
const QSizeF& )
const
179 if ( which != Qt::PreferredSize )
182 const auto box =
static_cast< const QskComboBox*
>( skinnable );
184 LayoutEngine layoutEngine( box, qskWidestIndex( box ) );
185 auto size = layoutEngine.sizeHint( which, QSizeF() );
187 const auto spacingHint = box->
spacingHint( Q::Panel );
188 const auto menuGraphicHint = box->
strutSizeHint( Q::StatusIndicator );
190 size.rwidth() += spacingHint + menuGraphicHint.width();
194 size = size.grownBy( skinnable->
marginHint( Q::Panel ) );
199#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.
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.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.