aspectRatioMode replaced by scalingMode
This commit is contained in:
parent
e7c2cd0eba
commit
1c4bcffc3f
@ -90,61 +90,58 @@ QskBoxShapeMetrics QskBoxShapeMetrics::toAbsolute( const QSizeF& size ) const no
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
QskBoxShapeMetrics absoluted = *this;
|
QskBoxShapeMetrics absoluted = *this;
|
||||||
|
absoluted.m_sizeMode = Qt::AbsoluteSize;
|
||||||
|
|
||||||
if ( size.isEmpty() )
|
if ( size.isEmpty() )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < 4; i++ )
|
for ( int i = 0; i < 4; i++ )
|
||||||
absoluted.m_radii[ i ] = QSizeF( 0.0, 0.0 );
|
absoluted.m_radii[ i ] = QSizeF( 0.0, 0.0 );
|
||||||
|
|
||||||
|
return absoluted;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if ( m_scalingMode == RoundedRectangle )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < 4; i++ )
|
for ( int i = 0; i < 4; i++ )
|
||||||
{
|
{
|
||||||
auto& radius = absoluted.m_radii[ i ];
|
auto& radius = absoluted.m_radii[ i ];
|
||||||
|
|
||||||
qreal rx = qskAbsoluted( size.width(), radius.width() );
|
const qreal rx = qskAbsoluted( size.width(), radius.width() );
|
||||||
qreal ry = qskAbsoluted( size.height(), radius.height() );
|
const qreal ry = qskAbsoluted( size.height(), radius.height() );
|
||||||
|
|
||||||
|
radius.rheight() = radius.rwidth() = std::min( rx, ry );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto ratio = size.height() / size.width();
|
||||||
|
|
||||||
|
for ( int i = 0; i < 4; i++ )
|
||||||
|
{
|
||||||
|
auto& radius = absoluted.m_radii[ i ];
|
||||||
|
|
||||||
|
const qreal rx = qskAbsoluted( size.width(), radius.width() );
|
||||||
|
const qreal ry = qskAbsoluted( size.height(), radius.height() );
|
||||||
|
|
||||||
if ( rx <= 0.0 || ry <= 0.0 )
|
if ( rx <= 0.0 || ry <= 0.0 )
|
||||||
{
|
{
|
||||||
radius.rwidth() = radius.rheight() = 0.0;
|
radius.rwidth() = radius.rheight() = 0.0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ratio >= 1.0 )
|
||||||
|
{
|
||||||
|
radius.rwidth() = ry / ratio;
|
||||||
|
radius.rheight() = ry;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_aspectRatioMode != Qt::IgnoreAspectRatio )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
if ( ( m_aspectRatioMode == Qt::KeepAspectRatioByExpanding ) &&
|
|
||||||
( radius.width() >= radius.height() ) )
|
|
||||||
{
|
|
||||||
rx = ry * radius.width() / radius.height();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ry = rx * radius.height() / radius.width();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
if ( m_aspectRatioMode == Qt::KeepAspectRatio )
|
|
||||||
{
|
|
||||||
rx = std::min( rx, ry );
|
|
||||||
ry = std::min( rx, ry );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rx = std::max( rx, ry );
|
|
||||||
ry = std::max( rx, ry );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
radius.rwidth() = rx;
|
radius.rwidth() = rx;
|
||||||
radius.rheight() = ry;
|
radius.rheight() = rx * ratio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
absoluted.m_sizeMode = Qt::AbsoluteSize;
|
|
||||||
|
|
||||||
return absoluted;
|
return absoluted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +158,7 @@ QskBoxShapeMetrics QskBoxShapeMetrics::interpolated(
|
|||||||
qskInterpolatedSize( m_radii[ 1 ], to.m_radii[ 1 ], ratio ),
|
qskInterpolatedSize( m_radii[ 1 ], to.m_radii[ 1 ], ratio ),
|
||||||
qskInterpolatedSize( m_radii[ 2 ], to.m_radii[ 2 ], ratio ),
|
qskInterpolatedSize( m_radii[ 2 ], to.m_radii[ 2 ], ratio ),
|
||||||
qskInterpolatedSize( m_radii[ 3 ], to.m_radii[ 3 ], ratio ),
|
qskInterpolatedSize( m_radii[ 3 ], to.m_radii[ 3 ], ratio ),
|
||||||
to.m_sizeMode, to.m_aspectRatioMode );
|
to.m_sizeMode, to.m_scalingMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QskBoxShapeMetrics::interpolate(
|
QVariant QskBoxShapeMetrics::interpolate(
|
||||||
|
@ -26,10 +26,17 @@ class QSK_EXPORT QskBoxShapeMetrics
|
|||||||
Q_PROPERTY( qreal radius READ radiusX WRITE setRadius )
|
Q_PROPERTY( qreal radius READ radiusX WRITE setRadius )
|
||||||
|
|
||||||
Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode )
|
Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode )
|
||||||
Q_PROPERTY( Qt::AspectRatioMode aspectRatioMode
|
Q_PROPERTY( ScalingMode scalingMode READ scalingMode WRITE setScalingMode )
|
||||||
READ aspectRatioMode WRITE setAspectRatioMode )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum ScalingMode
|
||||||
|
{
|
||||||
|
// How to scale, when translating to Qt::AbsoluteSize
|
||||||
|
RoundedRectangle,
|
||||||
|
Ellipsoid
|
||||||
|
};
|
||||||
|
Q_ENUM( ScalingMode );
|
||||||
|
|
||||||
constexpr QskBoxShapeMetrics() noexcept;
|
constexpr QskBoxShapeMetrics() noexcept;
|
||||||
|
|
||||||
constexpr QskBoxShapeMetrics( qreal topLeft, qreal topRight,
|
constexpr QskBoxShapeMetrics( qreal topLeft, qreal topRight,
|
||||||
@ -83,8 +90,8 @@ class QSK_EXPORT QskBoxShapeMetrics
|
|||||||
void setSizeMode( Qt::SizeMode ) noexcept;
|
void setSizeMode( Qt::SizeMode ) noexcept;
|
||||||
constexpr Qt::SizeMode sizeMode() const noexcept;
|
constexpr Qt::SizeMode sizeMode() const noexcept;
|
||||||
|
|
||||||
void setAspectRatioMode( Qt::AspectRatioMode ) noexcept;
|
void setScalingMode( ScalingMode ) noexcept;
|
||||||
constexpr Qt::AspectRatioMode aspectRatioMode() const noexcept;
|
constexpr ScalingMode scalingMode() const noexcept;
|
||||||
|
|
||||||
QskBoxShapeMetrics interpolated(
|
QskBoxShapeMetrics interpolated(
|
||||||
const QskBoxShapeMetrics&, qreal value ) const noexcept;
|
const QskBoxShapeMetrics&, qreal value ) const noexcept;
|
||||||
@ -105,22 +112,22 @@ class QSK_EXPORT QskBoxShapeMetrics
|
|||||||
inline constexpr QskBoxShapeMetrics(
|
inline constexpr QskBoxShapeMetrics(
|
||||||
const QSizeF& topLeft, const QSizeF& topRight,
|
const QSizeF& topLeft, const QSizeF& topRight,
|
||||||
const QSizeF& bottomLeft, const QSizeF& bottomRight,
|
const QSizeF& bottomLeft, const QSizeF& bottomRight,
|
||||||
Qt::SizeMode sizeMode, Qt::AspectRatioMode aspectRatioMode ) noexcept
|
Qt::SizeMode sizeMode, ScalingMode scalingMode ) noexcept
|
||||||
: m_radii{ topLeft, topRight, bottomLeft, bottomRight }
|
: m_radii{ topLeft, topRight, bottomLeft, bottomRight }
|
||||||
, m_sizeMode( sizeMode )
|
, m_sizeMode( sizeMode )
|
||||||
, m_aspectRatioMode( aspectRatioMode )
|
, m_scalingMode( scalingMode )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF m_radii[ 4 ];
|
QSizeF m_radii[ 4 ];
|
||||||
Qt::SizeMode m_sizeMode : 2;
|
Qt::SizeMode m_sizeMode : 2;
|
||||||
Qt::AspectRatioMode m_aspectRatioMode : 2;
|
ScalingMode m_scalingMode : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics() noexcept
|
inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics() noexcept
|
||||||
: m_radii{ { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }
|
: m_radii{ { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }
|
||||||
, m_sizeMode( Qt::AbsoluteSize )
|
, m_sizeMode( Qt::AbsoluteSize )
|
||||||
, m_aspectRatioMode( Qt::KeepAspectRatio )
|
, m_scalingMode( RoundedRectangle )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +142,7 @@ inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics(
|
|||||||
: m_radii{ { radiusX, radiusY }, { radiusX, radiusY },
|
: m_radii{ { radiusX, radiusY }, { radiusX, radiusY },
|
||||||
{ radiusX, radiusY }, { radiusX, radiusY } }
|
{ radiusX, radiusY }, { radiusX, radiusY } }
|
||||||
, m_sizeMode( sizeMode )
|
, m_sizeMode( sizeMode )
|
||||||
, m_aspectRatioMode( Qt::KeepAspectRatio )
|
, m_scalingMode( RoundedRectangle )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +151,7 @@ inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics( qreal topLeft, qreal to
|
|||||||
: m_radii{ { topLeft, topLeft }, { topRight, topRight },
|
: m_radii{ { topLeft, topLeft }, { topRight, topRight },
|
||||||
{ bottomLeft, bottomLeft }, { bottomRight, bottomRight } }
|
{ bottomLeft, bottomLeft }, { bottomRight, bottomRight } }
|
||||||
, m_sizeMode( sizeMode )
|
, m_sizeMode( sizeMode )
|
||||||
, m_aspectRatioMode( Qt::KeepAspectRatio )
|
, m_scalingMode( RoundedRectangle )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +159,7 @@ inline constexpr bool QskBoxShapeMetrics::operator==(
|
|||||||
const QskBoxShapeMetrics& other ) const noexcept
|
const QskBoxShapeMetrics& other ) const noexcept
|
||||||
{
|
{
|
||||||
return ( m_sizeMode == other.m_sizeMode )
|
return ( m_sizeMode == other.m_sizeMode )
|
||||||
&& ( m_aspectRatioMode == other.m_aspectRatioMode )
|
&& ( m_scalingMode == other.m_scalingMode )
|
||||||
&& ( m_radii[ 0 ] == other.m_radii[ 0 ] )
|
&& ( m_radii[ 0 ] == other.m_radii[ 0 ] )
|
||||||
&& ( m_radii[ 1 ] == other.m_radii[ 1 ] )
|
&& ( m_radii[ 1 ] == other.m_radii[ 1 ] )
|
||||||
&& ( m_radii[ 2 ] == other.m_radii[ 2 ] )
|
&& ( m_radii[ 2 ] == other.m_radii[ 2 ] )
|
||||||
@ -250,15 +257,15 @@ inline constexpr Qt::SizeMode QskBoxShapeMetrics::sizeMode() const noexcept
|
|||||||
return m_sizeMode;
|
return m_sizeMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QskBoxShapeMetrics::setAspectRatioMode(
|
inline void QskBoxShapeMetrics::setScalingMode( ScalingMode scalingMode ) noexcept
|
||||||
Qt::AspectRatioMode aspectRatioMode ) noexcept
|
|
||||||
{
|
{
|
||||||
m_aspectRatioMode = aspectRatioMode;
|
m_scalingMode = scalingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr Qt::AspectRatioMode QskBoxShapeMetrics::aspectRatioMode() const noexcept
|
inline constexpr QskBoxShapeMetrics::ScalingMode
|
||||||
|
QskBoxShapeMetrics::scalingMode() const noexcept
|
||||||
{
|
{
|
||||||
return m_aspectRatioMode;
|
return m_scalingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr bool QskBoxShapeMetrics::isRectellipse() const noexcept
|
inline constexpr bool QskBoxShapeMetrics::isRectellipse() const noexcept
|
||||||
@ -281,7 +288,7 @@ inline constexpr QskBoxShapeMetrics QskBoxShapeMetrics::transposed() const noexc
|
|||||||
return QskBoxShapeMetrics(
|
return QskBoxShapeMetrics(
|
||||||
m_radii[ 0 ].transposed(), m_radii[ 1 ].transposed(),
|
m_radii[ 0 ].transposed(), m_radii[ 1 ].transposed(),
|
||||||
m_radii[ 2 ].transposed(), m_radii[ 3 ].transposed(),
|
m_radii[ 2 ].transposed(), m_radii[ 3 ].transposed(),
|
||||||
m_sizeMode, m_aspectRatioMode );
|
m_sizeMode, m_scalingMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user