more efficient implementation of qskAlignedRect
This commit is contained in:
parent
0b8d857714
commit
3426e78ed4
@ -8,49 +8,38 @@ template< class Rect, class Value >
|
|||||||
static inline Rect qskAlignedRect( const Rect& outerRect,
|
static inline Rect qskAlignedRect( const Rect& outerRect,
|
||||||
Value width, Value height, Qt::Alignment alignment )
|
Value width, Value height, Qt::Alignment alignment )
|
||||||
{
|
{
|
||||||
// we might need this code at other place too ???
|
Value x = outerRect.x();
|
||||||
|
Value y = outerRect.y();
|
||||||
Rect r( 0, 0, width, height );
|
|
||||||
|
|
||||||
switch ( alignment & Qt::AlignHorizontal_Mask )
|
switch ( alignment & Qt::AlignHorizontal_Mask )
|
||||||
{
|
{
|
||||||
case Qt::AlignLeft:
|
case Qt::AlignHCenter:
|
||||||
{
|
x += ( outerRect.width() - width ) / 2;
|
||||||
r.moveLeft( outerRect.left() );
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case Qt::AlignRight:
|
case Qt::AlignRight:
|
||||||
{
|
x += outerRect.width() - width;
|
||||||
r.moveRight( outerRect.right() );
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
break;
|
||||||
const auto dx = ( outerRect.width() - width ) / 2;
|
|
||||||
r.moveLeft( outerRect.left() + dx );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( alignment & Qt::AlignVertical_Mask )
|
switch ( alignment & Qt::AlignVertical_Mask )
|
||||||
{
|
{
|
||||||
case Qt::AlignTop:
|
case Qt::AlignVCenter:
|
||||||
{
|
y += ( outerRect.height() - height ) / 2;
|
||||||
r.moveTop( outerRect.top() );
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case Qt::AlignBottom:
|
case Qt::AlignBottom:
|
||||||
{
|
y += outerRect.height() - height;
|
||||||
r.moveBottom( outerRect.bottom() );
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
break;
|
||||||
const auto dy = ( outerRect.height() - height ) / 2;
|
|
||||||
r.moveTop( outerRect.top() + dy );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return Rect( x, y, width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect qskAlignedRect( const QRect& outerRect,
|
QRect qskAlignedRect( const QRect& outerRect,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user