From 958e087943cd0a8441fb031f45d8af8ee5ba21d3 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 8 Nov 2018 09:02:03 +0100 Subject: [PATCH] distributing extra space at the borders fixed --- src/layouts/QskGridBox.cpp | 6 ++---- src/layouts/QskLayoutEngine.cpp | 12 ++++++++++++ src/layouts/QskLayoutEngine.h | 3 +++ src/layouts/QskLinearBox.cpp | 10 ++++------ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/layouts/QskGridBox.cpp b/src/layouts/QskGridBox.cpp index 82e44821..ebc872ad 100644 --- a/src/layouts/QskGridBox.cpp +++ b/src/layouts/QskGridBox.cpp @@ -441,8 +441,7 @@ qreal QskGridBox::heightForWidth( qreal width ) const const auto m = margins(); width -= m.left() + m.right(); - const QSizeF constraint( width, -1 ); - qreal height = engine().sizeHint( Qt::PreferredSize, constraint ).height(); + qreal height = engine().heightForWidth( width ); height += m.top() + m.bottom(); return height; @@ -453,8 +452,7 @@ qreal QskGridBox::widthForHeight( qreal height ) const const auto m = margins(); height -= m.top() + m.bottom(); - const QSizeF constraint( -1, height ); - qreal width = engine().sizeHint( Qt::PreferredSize, constraint ).width(); + qreal width = engine().widthForHeight( height ); width += m.left() + m.right(); return width; diff --git a/src/layouts/QskLayoutEngine.cpp b/src/layouts/QskLayoutEngine.cpp index 605690c8..a563a919 100644 --- a/src/layouts/QskLayoutEngine.cpp +++ b/src/layouts/QskLayoutEngine.cpp @@ -165,6 +165,18 @@ QSizeF QskLayoutEngine::sizeHint( Qt::SizeHint which, const QSizeF& constraint ) return QGridLayoutEngine::sizeHint( which, constraint, &styleInfo ); } +qreal QskLayoutEngine::widthForHeight( qreal height ) const +{ + const QSizeF constraint( -1, height ); + return sizeHint( Qt::PreferredSize, constraint ).width(); +} + +qreal QskLayoutEngine::heightForWidth( qreal width ) const +{ + const QSizeF constraint( width, -1 ); + return sizeHint( Qt::PreferredSize, constraint ).height(); +} + qreal QskLayoutEngine::spacing( Qt::Orientation orientation ) const { const LayoutStyleInfo styleInfo; diff --git a/src/layouts/QskLayoutEngine.h b/src/layouts/QskLayoutEngine.h index 0c3083e1..257d44e6 100644 --- a/src/layouts/QskLayoutEngine.h +++ b/src/layouts/QskLayoutEngine.h @@ -41,6 +41,9 @@ class QskLayoutEngine : public QGridLayoutEngine QSizeF sizeHint( Qt::SizeHint, const QSizeF& constraint = QSizeF() ) const; + qreal widthForHeight( qreal height ) const; + qreal heightForWidth( qreal width ) const; + qreal spacing( Qt::Orientation ) const; static qreal defaultSpacing( Qt::Orientation ); diff --git a/src/layouts/QskLinearBox.cpp b/src/layouts/QskLinearBox.cpp index 203fa2d2..9ac757cf 100644 --- a/src/layouts/QskLinearBox.cpp +++ b/src/layouts/QskLinearBox.cpp @@ -336,8 +336,7 @@ qreal QskLinearBox::heightForWidth( qreal width ) const const auto m = margins(); width -= m.left() + m.right(); - const QSizeF constraint( width, -1 ); - qreal height = engine().sizeHint( Qt::PreferredSize, constraint ).height(); + qreal height = engine().heightForWidth( width ); height += m.top() + m.bottom(); return height; @@ -348,8 +347,7 @@ qreal QskLinearBox::widthForHeight( qreal height ) const const auto m = margins(); height -= m.top() + m.bottom(); - const QSizeF constraint( -1, height ); - qreal width = engine().sizeHint( Qt::PreferredSize, constraint ).width(); + qreal width = engine().widthForHeight( height ); width += m.left() + m.right(); return width; @@ -444,7 +442,7 @@ QRectF QskLinearBox::alignedLayoutRect( const QRectF& rect ) const if ( !isExpandable ) { - const qreal w = widthForHeight( r.height() ); + const qreal w = engine.widthForHeight( r.height() ); if ( m_data->extraSpacingAt & Qt::LeftEdge ) { @@ -484,7 +482,7 @@ QRectF QskLinearBox::alignedLayoutRect( const QRectF& rect ) const if ( !isExpandable ) { - const qreal h = heightForWidth( r.width() ); + const qreal h = engine.heightForWidth( r.width() ); if ( m_data->extraSpacingAt & Qt::TopEdge ) {