qskValidOrInnerRect improved

This commit is contained in:
Uwe Rathmann 2019-04-24 08:39:13 +02:00
parent b2d9663a20
commit ba365909d8
2 changed files with 31 additions and 34 deletions

View File

@ -89,29 +89,45 @@ QRectF qskValidOrEmptyInnerRect( const QRectF& rect, const QMarginsF& margins )
{ {
qreal x, y, h, w; qreal x, y, h, w;
const qreal marginsWidth = margins.left() + margins.right(); if ( rect.width() > 0.0 )
const qreal marginsHeight = margins.top() + margins.bottom();
if ( marginsWidth > rect.width() )
{ {
x = rect.x() + rect.width() * ( margins.left() / marginsWidth ); const qreal marginsWidth = margins.left() + margins.right();
w = 0;
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 else
{ {
x = rect.x() + margins.left(); x = rect.x();
w = rect.width() - marginsWidth; w = 0.0;
} }
if ( marginsHeight > rect.height() ) if ( rect.height() > 0.0 )
{ {
y = rect.y() + rect.height() * ( margins.top() / marginsHeight ); const qreal marginsHeight = margins.top() + margins.bottom();
h = 0; 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 else
{ {
y = rect.y() + margins.top(); y = rect.y();
h = rect.height() - marginsHeight; h = 0.0;
} }
return QRectF( x, y, w, h ); return QRectF( x, y, w, h );

View File

@ -5,6 +5,7 @@
#include "QskControl.h" #include "QskControl.h"
#include "QskAspect.h" #include "QskAspect.h"
#include "QskFunctions.h"
#include "QskDirtyItemFilter.h" #include "QskDirtyItemFilter.h"
#include "QskEvent.h" #include "QskEvent.h"
#include "QskQuick.h" #include "QskQuick.h"
@ -1003,27 +1004,7 @@ QMarginsF QskControl::margins() const
QRectF QskControl::contentsRect() const QRectF QskControl::contentsRect() const
{ {
const QRectF r = rect(); return qskValidOrEmptyInnerRect( rect(), margins() );
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 ) );
} }
bool QskControl::layoutMirroring() const bool QskControl::layoutMirroring() const