diff --git a/src/common/QskFunctions.cpp b/src/common/QskFunctions.cpp index f5ea912f..eec2c6f5 100644 --- a/src/common/QskFunctions.cpp +++ b/src/common/QskFunctions.cpp @@ -89,29 +89,45 @@ QRectF qskValidOrEmptyInnerRect( const QRectF& rect, const QMarginsF& margins ) { qreal x, y, h, w; - const qreal marginsWidth = margins.left() + margins.right(); - const qreal marginsHeight = margins.top() + margins.bottom(); - - if ( marginsWidth > rect.width() ) + if ( rect.width() > 0.0 ) { - x = rect.x() + rect.width() * ( margins.left() / marginsWidth ); - w = 0; + const qreal marginsWidth = margins.left() + margins.right(); + + if ( marginsWidth > rect.width() ) + { + x = rect.x() + rect.width() * ( margins.left() / marginsWidth ); + w = 0.0; + } + else + { + x = rect.x() + margins.left(); + w = rect.width() - marginsWidth; + } } else { - x = rect.x() + margins.left(); - w = rect.width() - marginsWidth; + x = rect.x(); + w = 0.0; } - if ( marginsHeight > rect.height() ) + if ( rect.height() > 0.0 ) { - y = rect.y() + rect.height() * ( margins.top() / marginsHeight ); - h = 0; + const qreal marginsHeight = margins.top() + margins.bottom(); + if ( marginsHeight > rect.height() ) + { + y = rect.y() + rect.height() * ( margins.top() / marginsHeight ); + h = 0.0; + } + else + { + y = rect.y() + margins.top(); + h = rect.height() - marginsHeight; + } } else { - y = rect.y() + margins.top(); - h = rect.height() - marginsHeight; + y = rect.y(); + h = 0.0; } return QRectF( x, y, w, h ); diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 4608749b..0db72187 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -5,6 +5,7 @@ #include "QskControl.h" #include "QskAspect.h" +#include "QskFunctions.h" #include "QskDirtyItemFilter.h" #include "QskEvent.h" #include "QskQuick.h" @@ -1003,27 +1004,7 @@ QMarginsF QskControl::margins() const QRectF QskControl::contentsRect() const { - const QRectF r = rect(); - - const auto m = margins(); - qreal left = r.left() + m.left(); - qreal top = r.top() + m.top(); - qreal right = r.right() - m.right(); - qreal bottom = r.bottom() - m.bottom(); - - if ( left > r.right() ) - left = r.right(); - - if ( top > r.bottom() ) - top = r.bottom(); - - if ( right < left ) - right = left; - - if ( bottom < top ) - bottom = top; - - return QRectF( QPointF( left, top ), QPointF( right, bottom ) ); + return qskValidOrEmptyInnerRect( rect(), margins() ); } bool QskControl::layoutMirroring() const