heightForWidth/widthForHeight generalized for autoLayoutChildren
This commit is contained in:
parent
cb6faf7a1f
commit
f8982e2177
|
@ -43,75 +43,4 @@ QSizeF QskBox::contentsSizeHint() const
|
||||||
return outerBoxSize( Panel, size ).expandedTo( minSize );
|
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"
|
#include "moc_QskBox.cpp"
|
||||||
|
|
|
@ -22,9 +22,6 @@ public:
|
||||||
|
|
||||||
virtual QRectF layoutRect() const override;
|
virtual QRectF layoutRect() const override;
|
||||||
virtual QSizeF contentsSizeHint() const override;
|
virtual QSizeF contentsSizeHint() const override;
|
||||||
|
|
||||||
virtual qreal heightForWidth( qreal width ) const override;
|
|
||||||
virtual qreal widthForHeight( qreal height ) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1237,14 +1237,58 @@ void QskControl::resetImplicitSize()
|
||||||
|
|
||||||
qreal QskControl::heightForWidth( qreal width ) const
|
qreal QskControl::heightForWidth( qreal width ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED( width )
|
qreal h = -1;
|
||||||
return -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
|
qreal QskControl::widthForHeight( qreal height ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED( height )
|
qreal w = -1;
|
||||||
return -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 )
|
bool QskControl::event( QEvent* event )
|
||||||
|
|
Loading…
Reference in New Issue