6#include "QskTextLabelSkinlet.h"
7#include "QskTextLabel.h"
9#include "QskTextOptions.h"
10#include "QskTextRenderer.h"
12#include <qfontmetrics.h>
15QskTextLabelSkinlet::QskTextLabelSkinlet(
QskSkin* skin )
18 setNodeRoles( { PanelRole, TextRole } );
21QskTextLabelSkinlet::~QskTextLabelSkinlet() =
default;
23QRectF QskTextLabelSkinlet::subControlRect(
const QskSkinnable* skinnable,
26 if ( subControl == QskTextLabel::Panel )
30 else if ( subControl == QskTextLabel::Text )
32 const auto label =
static_cast< const QskTextLabel*
>( skinnable );
34 if ( label->hasPanel() )
37 contentsRect, QskTextLabel::Panel );
43 return Inherited::subControlRect( skinnable, contentsRect, subControl );
46QSGNode* QskTextLabelSkinlet::updateSubNode(
47 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
49 const auto label =
static_cast< const QskTextLabel*
>( skinnable );
55 if ( !label->hasPanel() )
58 return updateBoxNode( label, node, QskTextLabel::Panel );
62 return updateTextNode( label, node,
63 label->text(), QskTextLabel::Text );
67 return Inherited::updateSubNode( skinnable, nodeRole, node );
70QSizeF QskTextLabelSkinlet::sizeHint(
const QskSkinnable* skinnable,
71 Qt::SizeHint which,
const QSizeF& constraint )
const
73 if ( which != Qt::PreferredSize )
76 const auto label =
static_cast< const QskTextLabel*
>( skinnable );
80 auto textOptions = label->textOptions();
81 textOptions.setFormat( label->effectiveTextFormat() );
83 const auto text = label->text();
87 const qreal lineHeight = QFontMetricsF( font ).height();
91 if ( constraint.height() < 0.0 )
92 hint.setHeight( qCeil( lineHeight ) );
94 else if ( constraint.width() >= 0.0 )
96 if ( textOptions.effectiveElideMode() != Qt::ElideNone )
98 hint.setHeight( qCeil( lineHeight ) );
107 qreal maxHeight = std::numeric_limits< qreal >::max();
108 if ( maxHeight / lineHeight > textOptions.maximumLineCount() )
111 maxHeight = textOptions.maximumLineCount() * lineHeight;
114 QSizeF size( constraint.width(), maxHeight );
116 size = QskTextRenderer::textSize( text, font, textOptions, size );
118 if ( label->hasPanel() )
119 size = label->outerBoxSize( QskTextLabel::Panel, size );
121 hint.setHeight( qCeil( size.height() ) );
124 else if ( constraint.height() >= 0.0 )
126 const qreal maxWidth = std::numeric_limits< qreal >::max();
128 QSizeF size( maxWidth, constraint.height() );
130 size = QskTextRenderer::textSize( text, font, textOptions, size );
132 if ( label->hasPanel() )
133 size = label->outerBoxSize( QskTextLabel::Panel, size );
135 hint.setWidth( qCeil( size.width() ) );
139 hint = QskTextRenderer::textSize( text, font, textOptions );
141 if ( label->hasPanel() )
142 hint = label->outerBoxSize( QskTextLabel::Panel, hint );
148#include "moc_QskTextLabelSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlContentsRect(QskAspect::Subcontrol) const
QFont effectiveFont(QskAspect) const