diff --git a/src/common/QskFunctions.cpp b/src/common/QskFunctions.cpp index a0c1f2ca..c084a433 100644 --- a/src/common/QskFunctions.cpp +++ b/src/common/QskFunctions.cpp @@ -122,6 +122,22 @@ QRectF qskValidOrEmptyInnerRect( const QRectF& rect, const QMarginsF& margins ) return QRectF( x, y, w, h ); } +QRectF qskInterpolatedRect( const QRectF &from, const QRectF &to, qreal progress ) +{ + if ( progress <= 0.0 ) + return from; + + if ( progress >= 1.0 ) + return to; + + const auto x = from.x() + progress * ( to.x() - from.x() ); + const auto y = from.y() + progress * ( to.y() - from.y() ); + const auto w = from.width() + progress * ( to.width() - from.width() ); + const auto h = from.height() + progress * ( to.height() - from.height() ); + + return QRectF( x, y, w, h ); +} + qreal qskHorizontalAdvance( const QFont& font, const QString& text ) { return qskHorizontalAdvance( QFontMetricsF( font ), text ); diff --git a/src/common/QskFunctions.h b/src/common/QskFunctions.h index 2855a2be..765960a5 100644 --- a/src/common/QskFunctions.h +++ b/src/common/QskFunctions.h @@ -30,6 +30,9 @@ QSK_EXPORT QRectF qskValidOrEmptyInnerRect( QSK_EXPORT qreal qskHorizontalAdvance( const QFont&, const QString& ); QSK_EXPORT qreal qskHorizontalAdvance( const QFontMetricsF&, const QString& ); +QSK_EXPORT QRectF qskInterpolatedRect( + const QRectF& from, const QRectF& to, qreal progress ); + inline QMarginsF qskMargins( const QRectF& rect, const QRectF& innerRect ) { return QMarginsF(