subcontrol layout engine: Allow for laying out more than 2 elements

This commit is contained in:
Peter Hartmann 2023-06-06 15:24:10 +02:00 committed by uwerat
parent 34776ee664
commit 0e67ed8aec
2 changed files with 45 additions and 25 deletions

View File

@ -345,31 +345,8 @@ void QskSubcontrolLayoutEngine::setGraphicTextElements( const QskSkinnable* skin
having to deal with the details of the layout classes. having to deal with the details of the layout classes.
*/ */
GraphicElement* graphicElement = nullptr; auto graphicElement = appendGraphicElement( skinnable, graphicSubControl, graphicSize );
if ( !graphicSize.isEmpty() && ( graphicSubControl != QskAspect::NoSubcontrol ) ) auto textElement = appendTextElement( skinnable, textSubcontrol, text );
{
graphicElement = dynamic_cast< GraphicElement* >( element( graphicSubControl ) );
if ( graphicElement == nullptr )
{
graphicElement = new GraphicElement( skinnable, graphicSubControl );
m_data->elements.prepend( graphicElement );
}
graphicElement->setSourceSize( graphicSize );
}
TextElement* textElement = nullptr;
if ( !text.isEmpty() && ( textSubcontrol != QskAspect::NoSubcontrol ) )
{
textElement = dynamic_cast< TextElement* >( element( textSubcontrol ) );
if ( textElement == nullptr )
{
textElement = new TextElement( skinnable, textSubcontrol );
m_data->elements.append( textElement );
}
textElement->setText( text );
}
/* /*
Now the difficult part: setting up size policies and the preferred size. Now the difficult part: setting up size policies and the preferred size.
@ -419,6 +396,46 @@ void QskSubcontrolLayoutEngine::setGraphicTextElements( const QskSkinnable* skin
} }
} }
QskSubcontrolLayoutEngine::GraphicElement* QskSubcontrolLayoutEngine::appendGraphicElement( const QskSkinnable* skinnable,
QskAspect::Subcontrol graphicSubcontrol, const QSizeF& graphicSize )
{
GraphicElement* graphicElement = nullptr;
if ( !graphicSize.isEmpty() && ( graphicSubcontrol != QskAspect::NoSubcontrol ) )
{
graphicElement = dynamic_cast< GraphicElement* >( element( graphicSubcontrol ) );
if ( graphicElement == nullptr )
{
graphicElement = new GraphicElement( skinnable, graphicSubcontrol );
m_data->elements.prepend( graphicElement );
}
graphicElement->setSourceSize( graphicSize );
}
return graphicElement;
}
QskSubcontrolLayoutEngine::TextElement* QskSubcontrolLayoutEngine::appendTextElement( const QskSkinnable* skinnable,
QskAspect::Subcontrol textSubcontrol, const QString& text )
{
TextElement* textElement = nullptr;
if ( !text.isEmpty() && ( textSubcontrol != QskAspect::NoSubcontrol ) )
{
textElement = dynamic_cast< TextElement* >( element( textSubcontrol ) );
if ( textElement == nullptr )
{
textElement = new TextElement( skinnable, textSubcontrol );
m_data->elements.append( textElement );
}
textElement->setText( text );
}
return textElement;
}
void QskSubcontrolLayoutEngine::setFixedContent( void QskSubcontrolLayoutEngine::setFixedContent(
QskAspect::Subcontrol subcontrol, Qt::Orientation orientation, Qt::Alignment alignment ) QskAspect::Subcontrol subcontrol, Qt::Orientation orientation, Qt::Alignment alignment )
{ {

View File

@ -127,6 +127,9 @@ class QskSubcontrolLayoutEngine : public QskLayoutEngine2D
QskAspect::Subcontrol, const QString& text, QskAspect::Subcontrol, const QString& text,
QskAspect::Subcontrol, const QSizeF& graphicSize ); QskAspect::Subcontrol, const QSizeF& graphicSize );
GraphicElement* appendGraphicElement( const QskSkinnable*, QskAspect::Subcontrol, const QSizeF& );
TextElement* appendTextElement( const QskSkinnable*, QskAspect::Subcontrol, const QString& );
void setFixedContent( QskAspect::Subcontrol, Qt::Orientation, Qt::Alignment ); void setFixedContent( QskAspect::Subcontrol, Qt::Orientation, Qt::Alignment );
QRectF subControlRect( QskAspect::Subcontrol ) const; QRectF subControlRect( QskAspect::Subcontrol ) const;