6#include "QskTextFieldSkinlet.h"
7#include "QskTextField.h"
11QskTextFieldSkinlet::QskTextFieldSkinlet(
QskSkin* skin )
14 setNodeRoles( { PanelRole, TextPanelRole, PlaceholderRole } );
17QskTextFieldSkinlet::~QskTextFieldSkinlet()
21QRectF QskTextFieldSkinlet::subControlRect(
const QskSkinnable* skinnable,
24 if ( subControl == Q::Panel )
27 if ( subControl == Q::TextPanel )
30 if ( subControl == Q::Text )
33 if ( subControl == Q::Placeholder )
35 const auto textField =
static_cast< const QskTextField*
>( skinnable );
36 if( textField->text().isEmpty() )
37 return subControlRect( skinnable, contentsRect, Q::Text );
42 return Inherited::subControlRect( skinnable, contentsRect, subControl );
45QSGNode* QskTextFieldSkinlet::updateSubNode(
46 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
48 const auto textField =
static_cast< const QskTextField*
>( skinnable );
54 return updateBoxNode( skinnable, node, Q::Panel );
58 return updateBoxNode( skinnable, node, Q::TextPanel );
62 const auto text = effectivePlaceholderText( textField );
66 const auto subControl = Q::Placeholder;
70 auto options = skinnable->textOptionsHint( subControl, &status );
72 options.setElideMode( Qt::ElideRight );
74 return updateTextNode( skinnable, node,
75 textField->subControlRect( subControl ),
76 textField->alignmentHint( subControl, Qt::AlignLeft ),
77 options, text, subControl );
81 return Inherited::updateSubNode( skinnable, nodeRole, node );
84QSizeF QskTextFieldSkinlet::sizeHint(
const QskSkinnable* skinnable,
85 Qt::SizeHint which,
const QSizeF& constraint )
const
87 Q_UNUSED( constraint );
89 if ( which != Qt::PreferredSize )
94 auto hint = input->unwrappedTextSize();
95 hint = hint.grownBy( skinnable->
marginHint( Q::Text ) );
97 hint = input->outerBoxSize( Q::TextPanel, hint );
98 hint = hint.expandedTo( input->strutSizeHint( Q::TextPanel ) );
101 hint = hint.expandedTo( skinnable->
strutSizeHint( Q::Panel ) );
106QString QskTextFieldSkinlet::effectivePlaceholderText(
109 if ( textField->text().isEmpty() &&
110 !( textField->isReadOnly() || textField->isEditing() ) )
112 return textField->placeholderText();
118#include "moc_QskTextFieldSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
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 subControlContentsRect(const QRectF &, QskAspect::Subcontrol) const
Calculate the inner rectangle for subControl.