6#include "QskBoxShapeMetrics.h"
8#include <qhashfunctions.h>
13static void qskRegisterBoxShapeMetrics()
15 qRegisterMetaType< QskBoxShapeMetrics >();
17#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
18 QMetaType::registerEqualsComparator< QskBoxShapeMetrics >();
21 QMetaType::registerConverter< int, QskBoxShapeMetrics >(
24 QMetaType::registerConverter< qreal, QskBoxShapeMetrics >(
28Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxShapeMetrics )
30static inline QSizeF qskInterpolatedSize(
31 const QSizeF& from,
const QSizeF& to, qreal ratio )
33 return from + ( to - from ) * ratio;
36static inline qreal qskAbsoluted( qreal length, qreal percentage )
39 percentage = qBound( 0.0, percentage, 100.0 );
40 return percentage / 100.0 * 0.5 * length;
43static inline void qskSetRadius( qreal rx, qreal ry, QSizeF& radius )
45 radius.rwidth() = ( rx > 0.0 ) ? rx : 0.0;
46 radius.rheight() = ( ry > 0.0 ) ? ry : 0.0;
49void QskBoxShapeMetrics::setRadius(
50 qreal topLeftX, qreal topLeftY,
51 qreal topRightX, qreal topRightY,
52 qreal bottomLeftX, qreal bottomLeftY,
53 qreal bottomRightX, qreal bottomRightY )
noexcept
55 qskSetRadius( topLeftX, topLeftY, m_radii[ Qt::TopLeftCorner ] );
56 qskSetRadius( topRightX, topRightY, m_radii[ Qt::TopRightCorner ] );
57 qskSetRadius( bottomLeftX, bottomLeftY, m_radii[ Qt::BottomLeftCorner ] );
58 qskSetRadius( bottomRightX, bottomRightY, m_radii[ Qt::BottomRightCorner ] );
61void QskBoxShapeMetrics::setRadius( Qt::Corner corner, qreal radiusX, qreal radiusY )
noexcept
63 if ( ( corner >= Qt::TopLeftCorner ) && ( corner <= Qt::BottomRightCorner ) )
64 qskSetRadius( radiusX, radiusY, m_radii[ corner ] );
67void QskBoxShapeMetrics::setTopLeft(
const QSizeF& radius )
noexcept
69 setRadius( Qt::TopLeftCorner, radius );
72void QskBoxShapeMetrics::setTopRight(
const QSizeF& radius )
noexcept
74 setRadius( Qt::TopRightCorner, radius );
77void QskBoxShapeMetrics::setBottomLeft(
const QSizeF& radius )
noexcept
79 setRadius( Qt::BottomLeftCorner, radius );
82void QskBoxShapeMetrics::setBottomRight(
const QSizeF& radius )
noexcept
84 setRadius( Qt::BottomRightCorner, radius );
89 if ( m_sizeMode != Qt::RelativeSize )
96 shape.m_sizeMode = Qt::AbsoluteSize;
98 for (
int i = 0; i < 4; i++ )
100 auto& radius = shape.m_radii[ i ];
102 if ( radius.isEmpty() )
104 radius.rheight() = radius.rwidth() = 0.0;
108 const qreal rx = qskAbsoluted( size.width(), radius.width() );
109 const qreal ry = qskAbsoluted( size.height(), radius.height() );
111 switch ( m_scalingMode )
115 radius.rheight() = radius.rwidth() = std::min( rx, ry );
118 case SymmetricByMaximum:
120 radius.rheight() = radius.rwidth() = std::max( rx, ry );
125 const auto ratio = radius.height() / radius.width();
129 radius.rwidth() = ry / ratio;
130 radius.rheight() = ry;
134 radius.rwidth() = rx;
135 radius.rheight() = rx * ratio;
149 if ( ( *
this == to ) || ( m_sizeMode != to.m_sizeMode ) )
153 qskInterpolatedSize( m_radii[ 0 ], to.m_radii[ 0 ], ratio ),
154 qskInterpolatedSize( m_radii[ 1 ], to.m_radii[ 1 ], ratio ),
155 qskInterpolatedSize( m_radii[ 2 ], to.m_radii[ 2 ], ratio ),
156 qskInterpolatedSize( m_radii[ 3 ], to.m_radii[ 3 ], ratio ),
157 to.m_sizeMode, to.m_scalingMode );
160QVariant QskBoxShapeMetrics::interpolate(
163 return QVariant::fromValue( from.interpolated( to, progress ) );
166QskHashValue QskBoxShapeMetrics::hash( QskHashValue seed )
const noexcept
168 auto hash = qHash(
static_cast< int >( m_sizeMode ), seed );
169 return qHashBits( m_radii,
sizeof( m_radii ), hash );
172#ifndef QT_NO_DEBUG_STREAM
178 QDebugStateSaver saver( debug );
181 debug <<
"BoxShape" <<
'(';
182 debug << metrics.sizeMode();
184 for (
int i = Qt::TopLeftCorner; i <= Qt::BottomRightCorner; i++ )
186 const QSizeF r = metrics.radius(
static_cast< Qt::Corner
>( i ) );
187 debug <<
"(" << r.width() <<
',' << r.height() <<
")";
197#include "moc_QskBoxShapeMetrics.cpp"