QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskFunctions.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_FUNCTIONS_H
7#define QSK_FUNCTIONS_H
8
9#include "QskGlobal.h"
10
11#include <qmargins.h>
12#include <qrect.h>
13
14class QFont;
15class QFontMetricsF;
16class QString;
17
18QSK_EXPORT QRect qskAlignedRect( const QRect& outerRect,
19 int width, int height, Qt::Alignment alignment );
20
21QSK_EXPORT QRectF qskAlignedRectF( const QRectF& outerRect,
22 qreal width, qreal height, Qt::Alignment alignment );
23
24QSK_EXPORT QRect qskInnerRect( const QRectF& rect );
25QSK_EXPORT QRectF qskInnerRectF( const QRectF& rect );
26
27QSK_EXPORT QRectF qskValidOrEmptyInnerRect(
28 const QRectF& rect, const QMarginsF& margins );
29
30QSK_EXPORT qreal qskHorizontalAdvance( const QFont&, const QString& );
31QSK_EXPORT qreal qskHorizontalAdvance( const QFontMetricsF&, const QString& );
32QSK_EXPORT QSizeF qskTextRenderSize( const QFontMetricsF&, const QString& );
33
34QSK_EXPORT QRectF qskInterpolatedRect(
35 const QRectF& from, const QRectF& to, qreal progress );
36
37QSK_EXPORT QSizeF qskInterpolatedSize(
38 const QSizeF& from, const QSizeF& to, qreal progress );
39
40inline QRect qskAlignedRect( const QRect& outerRect,
41 const QSize& size, Qt::Alignment alignment )
42{
43 return qskAlignedRect( outerRect, size.width(), size.height(), alignment );
44}
45
46inline QRectF qskAlignedRectF( const QRectF& outerRect,
47 const QSizeF& size, Qt::Alignment alignment )
48{
49 return qskAlignedRectF( outerRect, size.width(), size.height(), alignment );
50}
51
52inline constexpr QMarginsF qskMargins( const QRectF& rect, const QRectF& innerRect )
53{
54 return QMarginsF(
55 innerRect.left() - rect.left(),
56 innerRect.top() - rect.top(),
57 rect.right() - innerRect.right(),
58 rect.bottom() - innerRect.bottom() );
59}
60
61inline constexpr bool qskFuzzyCompare( qreal value1, qreal value2 )
62{
63 if ( qFuzzyIsNull( value1 ) )
64 return qFuzzyIsNull( value2 );
65
66 if ( qFuzzyIsNull( value2 ) )
67 return false;
68
69 return qFuzzyCompare( value1, value2 );
70}
71
72QSK_EXPORT qreal qskFuzzyFloor( qreal value, qreal stepSize );
73QSK_EXPORT qreal qskFuzzyCeil( qreal value, qreal stepSize );
74
75QSK_EXPORT double qskConstrainedDegrees( double );
76QSK_EXPORT float qskConstrainedDegrees( float );
77
78QSK_EXPORT double qskConstrainedRadians( double );
79QSK_EXPORT float qskConstrainedRadians( float );
80
81#endif