diff --git a/src/layouts/QskLayoutChain.cpp b/src/layouts/QskLayoutChain.cpp index 7f7cbb53..28d92abb 100644 --- a/src/layouts/QskLayoutChain.cpp +++ b/src/layouts/QskLayoutChain.cpp @@ -85,7 +85,6 @@ void QskLayoutChain::expandCell( int index, const CellData& newCell ) if ( !cell.isValid ) { cell = newCell; - cell.stretch = qMax( cell.stretch, 0 ); m_validCells++; } else @@ -105,58 +104,63 @@ void QskLayoutChain::expandCells( int index, int count, const CellData& multiCell ) { QskLayoutChain chain; + chain.setSpacing( m_spacing ); chain.reset( count, -1 ); for ( int i = 0; i < count; i++ ) { - chain.expandCell( i, m_cells[ index + i ] ); - auto& cell = chain.m_cells[ i ]; -#if 1 - // what to do now ?? + cell = m_cells[ index + i ]; + if ( !cell.isValid ) { cell.isValid = true; cell.canGrow = multiCell.canGrow; - cell.stretch = qMax( cell.stretch, 0 ); + cell.stretch = multiCell.stretch; } -#endif } - chain.m_validCells = count; + chain.finish(); - QVarLengthArray< QskLayoutHint > hints( count ); + QskLayoutChain::Segments minimum; + QskLayoutChain::Segments preferred; + QskLayoutChain::Segments maximum; - const auto& hint = multiCell.hint; const auto chainHint = chain.boundingHint(); - if ( hint.minimum() > chainHint.minimum() ) - { - const auto segments = chain.segments( hint.minimum() ); - for ( int i = 0; i < count; i++ ) - hints[i].setMinimum( segments[i].length ); - } + if ( multiCell.hint.minimum() > chainHint.minimum() ) + minimum = chain.segments( multiCell.hint.minimum() ); - if ( hint.preferred() > chainHint.preferred() ) - { - const auto segments = chain.segments( hint.preferred() ); - for ( int i = 0; i < count; i++ ) - hints[i].setPreferred( segments[i].length ); - } + if ( multiCell.hint.preferred() > chainHint.preferred() ) + preferred = chain.segments( multiCell.hint.preferred() ); - if ( hint.maximum() < chainHint.maximum() ) + if ( chainHint.maximum() == QskLayoutConstraint::unlimited ) { - const auto segments = chain.segments( hint.maximum() ); - for ( int i = 0; i < count; i++ ) - hints[i].setMaximum( segments[i].length ); + if ( multiCell.hint.maximum() < QskLayoutConstraint::unlimited ) + maximum = chain.segments( multiCell.hint.maximum() ); } for ( int i = 0; i < count; i++ ) { - auto cell = multiCell; - cell.hint = hints[i]; + auto& cell = m_cells[ index + i ]; - expandCell( index + i, cell ); - } + cell.canGrow |= multiCell.canGrow; + cell.stretch = qMax( cell.stretch, multiCell.stretch ); + + if ( !minimum.isEmpty() ) + cell.hint.expandMinimum( minimum[i].length ); + + if ( !preferred.isEmpty() ) + cell.hint.expandPreferred( preferred[i].length ); + + if ( !maximum.isEmpty() && !cell.isValid ) + cell.hint.setMaximum( maximum[i].length ); + + if ( !cell.isValid ) + { + cell.isValid = true; + m_validCells++; + } + } } void QskLayoutChain::finish() diff --git a/src/layouts/QskLayoutHint.cpp b/src/layouts/QskLayoutHint.cpp index ee386e54..98fffff7 100644 --- a/src/layouts/QskLayoutHint.cpp +++ b/src/layouts/QskLayoutHint.cpp @@ -58,6 +58,13 @@ void QskLayoutHint::setSize( int which, qreal size ) } } +void QskLayoutHint::expandTo( const QskLayoutHint& other ) +{ + m_minimum = qMax( m_minimum, other.m_minimum ); + m_preferred = qMax( m_preferred, other.m_preferred ); + m_maximum = qMax( m_maximum, other.m_maximum ); +} + void QskLayoutHint::normalize() { m_minimum = qMax( m_minimum, qreal( 0.0 ) ); diff --git a/src/layouts/QskLayoutHint.h b/src/layouts/QskLayoutHint.h index 3551a66d..4a04550f 100644 --- a/src/layouts/QskLayoutHint.h +++ b/src/layouts/QskLayoutHint.h @@ -38,6 +38,11 @@ class QSK_EXPORT QskLayoutHint qreal maximum() const; void setSizes( qreal minimum, qreal preferred, qreal maximum ); + void expandTo( const QskLayoutHint& ); + + void expandMinimum( qreal value ); + void expandPreferred( qreal value ); + void expandMaximum( qreal value ); private: qreal m_minimum; @@ -75,6 +80,24 @@ inline void QskLayoutHint::setMaximum( qreal value ) m_maximum = value; } +inline void QskLayoutHint::expandMinimum( qreal value ) +{ + if ( value > m_minimum ) + m_minimum = value; +} + +inline void QskLayoutHint::expandPreferred( qreal value ) +{ + if ( value > m_preferred ) + m_preferred = value; +} + +inline void QskLayoutHint::expandMaximum( qreal value ) +{ + if ( value > m_maximum ) + m_maximum = value; +} + inline void QskLayoutHint::setSizes( qreal minimum, qreal preferred, qreal maximum ) {