From 0e67ed8aecbe0653928a44031c5aea8317782443 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 6 Jun 2023 15:24:10 +0200 Subject: [PATCH] subcontrol layout engine: Allow for laying out more than 2 elements --- src/layouts/QskSubcontrolLayoutEngine.cpp | 67 ++++++++++++++--------- src/layouts/QskSubcontrolLayoutEngine.h | 3 + 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/layouts/QskSubcontrolLayoutEngine.cpp b/src/layouts/QskSubcontrolLayoutEngine.cpp index 6b74fc84..e00b4835 100644 --- a/src/layouts/QskSubcontrolLayoutEngine.cpp +++ b/src/layouts/QskSubcontrolLayoutEngine.cpp @@ -345,31 +345,8 @@ void QskSubcontrolLayoutEngine::setGraphicTextElements( const QskSkinnable* skin having to deal with the details of the layout classes. */ - 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 ); - } - - 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 ); - } + auto graphicElement = appendGraphicElement( skinnable, graphicSubControl, graphicSize ); + auto textElement = appendTextElement( skinnable, textSubcontrol, text ); /* 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( QskAspect::Subcontrol subcontrol, Qt::Orientation orientation, Qt::Alignment alignment ) { diff --git a/src/layouts/QskSubcontrolLayoutEngine.h b/src/layouts/QskSubcontrolLayoutEngine.h index 6f929066..c1afc485 100644 --- a/src/layouts/QskSubcontrolLayoutEngine.h +++ b/src/layouts/QskSubcontrolLayoutEngine.h @@ -127,6 +127,9 @@ class QskSubcontrolLayoutEngine : public QskLayoutEngine2D QskAspect::Subcontrol, const QString& text, 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 ); QRectF subControlRect( QskAspect::Subcontrol ) const;