From 3426e78ed4c5cafee34cd2a4e6ee7765ca663356 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 16 May 2019 08:23:10 +0200 Subject: [PATCH] more efficient implementation of qskAlignedRect --- src/common/QskFunctions.cpp | 41 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/common/QskFunctions.cpp b/src/common/QskFunctions.cpp index eec2c6f5..f10c7572 100644 --- a/src/common/QskFunctions.cpp +++ b/src/common/QskFunctions.cpp @@ -8,49 +8,38 @@ template< class Rect, class Value > static inline Rect qskAlignedRect( const Rect& outerRect, Value width, Value height, Qt::Alignment alignment ) { - // we might need this code at other place too ??? - - Rect r( 0, 0, width, height ); + Value x = outerRect.x(); + Value y = outerRect.y(); switch ( alignment & Qt::AlignHorizontal_Mask ) { - case Qt::AlignLeft: - { - r.moveLeft( outerRect.left() ); + case Qt::AlignHCenter: + x += ( outerRect.width() - width ) / 2; break; - } + case Qt::AlignRight: - { - r.moveRight( outerRect.right() ); + x += outerRect.width() - width; break; - } + default: - { - const auto dx = ( outerRect.width() - width ) / 2; - r.moveLeft( outerRect.left() + dx ); - } + break; } switch ( alignment & Qt::AlignVertical_Mask ) { - case Qt::AlignTop: - { - r.moveTop( outerRect.top() ); + case Qt::AlignVCenter: + y += ( outerRect.height() - height ) / 2; break; - } + case Qt::AlignBottom: - { - r.moveBottom( outerRect.bottom() ); + y += outerRect.height() - height; break; - } + default: - { - const auto dy = ( outerRect.height() - height ) / 2; - r.moveTop( outerRect.top() + dy ); - } + break; } - return r; + return Rect( x, y, width, height ); } QRect qskAlignedRect( const QRect& outerRect,