From f8982e2177e98c32cccd4840781dc5e727e24517 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 12 Jun 2018 08:19:28 +0200 Subject: [PATCH] heightForWidth/widthForHeight generalized for autoLayoutChildren --- src/controls/QskBox.cpp | 71 ------------------------------------- src/controls/QskBox.h | 3 -- src/controls/QskControl.cpp | 52 ++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 78 deletions(-) diff --git a/src/controls/QskBox.cpp b/src/controls/QskBox.cpp index 5f0015b7..0af35c43 100644 --- a/src/controls/QskBox.cpp +++ b/src/controls/QskBox.cpp @@ -43,75 +43,4 @@ QSizeF QskBox::contentsSizeHint() const return outerBoxSize( Panel, size ).expandedTo( minSize ); } -qreal QskBox::heightForWidth( qreal width ) const -{ - qreal height = -1; - - if ( autoLayoutChildren() ) - { - const auto children = childItems(); - if ( !children.isEmpty() ) - { - const auto margins = this->margins(); - width -= margins.left() + margins.right(); - - const auto padding = innerPadding( Panel, QSizeF( width, width ) ); - width -= padding.left() + padding.right(); - - for ( auto child : children ) - { - if ( auto control = qobject_cast< const QskControl* >( child ) ) - { - if ( !control->isTransparentForPositioner() ) - height = qMax( height, control->heightForWidth( width ) ); - } - } - - if ( height >= 0 ) - { - height += padding.top() + padding.bottom(); - height += margins.top() + margins.bottom(); - } - } - } - - return height; -} - -qreal QskBox::widthForHeight( qreal height ) const -{ - qreal width = -1; - - if ( autoLayoutChildren() ) - { - const auto children = childItems(); - if ( !children.isEmpty() ) - { - const auto margins = this->margins(); - height -= margins.top() + margins.bottom(); - - const auto padding = innerPadding( Panel, QSizeF( height, height ) ); - height -= padding.top() + padding.bottom(); - - for ( auto child : children ) - { - if ( auto control = qobject_cast< const QskControl* >( child ) ) - { - if ( !control->isTransparentForPositioner() ) - width = qMax( width, control->widthForHeight( height ) ); - } - } - - if ( width >= 0 ) - { - width += padding.left() + padding.right(); - width += margins.left() + margins.right(); - } - } - } - - return width; -} - - #include "moc_QskBox.cpp" diff --git a/src/controls/QskBox.h b/src/controls/QskBox.h index 7fae8f62..4ac31754 100644 --- a/src/controls/QskBox.h +++ b/src/controls/QskBox.h @@ -22,9 +22,6 @@ public: virtual QRectF layoutRect() const override; virtual QSizeF contentsSizeHint() const override; - - virtual qreal heightForWidth( qreal width ) const override; - virtual qreal widthForHeight( qreal height ) const override; }; #endif diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 04e423ab..4efb9a0f 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -1237,14 +1237,58 @@ void QskControl::resetImplicitSize() qreal QskControl::heightForWidth( qreal width ) const { - Q_UNUSED( width ) - return -1; + qreal h = -1; + + if ( d_func()->autoLayoutChildren ) + { + const auto innerSize = layoutRect().size(); + const auto outerSize = size(); + + width -= outerSize.width() - innerSize.width(); + + const auto children = childItems(); + for ( auto child : children ) + { + if ( auto control = qobject_cast< const QskControl* >( child ) ) + { + if ( !control->isTransparentForPositioner() ) + h = qMax( h, control->heightForWidth( width ) ); + } + } + + if ( h >= 0 ) + h += outerSize.height() - innerSize.height(); + } + + return h; } qreal QskControl::widthForHeight( qreal height ) const { - Q_UNUSED( height ) - return -1; + qreal w = -1; + + if ( d_func()->autoLayoutChildren ) + { + const auto innerSize = layoutRect().size(); + const auto outerSize = size(); + + height -= outerSize.height() - innerSize.height(); + + const auto children = childItems(); + for ( auto child : children ) + { + if ( auto control = qobject_cast< const QskControl* >( child ) ) + { + if ( !control->isTransparentForPositioner() ) + w = qMax( w, control->widthForHeight( height ) ); + } + } + + if ( w >= 0 ) + w += outerSize.width() - innerSize.width(); + } + + return w; } bool QskControl::event( QEvent* event )