QskBoxShapeMetrics::ScalingMode: using better names, missing mode

reinserted
This commit is contained in:
Uwe Rathmann 2023-02-16 11:30:31 +01:00
parent 64fee0247e
commit d71b972232
5 changed files with 55 additions and 23 deletions

View File

@ -72,7 +72,7 @@ static void addTestRectangle( QskLinearBox* parent )
box->setBorderWidth( 10, 20, 40, 20 ); box->setBorderWidth( 10, 20, 40, 20 );
QskBoxShapeMetrics shape( 50, Qt::RelativeSize ); QskBoxShapeMetrics shape( 50, Qt::RelativeSize );
shape.setScalingMode( QskBoxShapeMetrics::Elliptic ); shape.setScalingMode( QskBoxShapeMetrics::Proportional );
shape.setRadius( Qt::BottomRightCorner, 30 ); shape.setRadius( Qt::BottomRightCorner, 30 );
shape.setRadius( Qt::TopRightCorner, 70 ); shape.setRadius( Qt::TopRightCorner, 70 );

View File

@ -19,7 +19,6 @@ Qsk.PushButton
shape shape
{ {
sizeMode: Qt.RelativeSize sizeMode: Qt.RelativeSize
scalingMode: Qsk.BoxShapeMetrics.Circular
radius: 10 radius: 10
} }

View File

@ -129,7 +129,7 @@ Qsk.Window
shape shape
{ {
sizeMode: Qt.RelativeSize sizeMode: Qt.RelativeSize
scalingMode: Qsk.BoxShapeMetrics.Elliptic scalingMode: Qsk.BoxShapeMetrics.SymmetricByMaximum
radius: 100 radius: 100
} }
} }

View File

@ -108,11 +108,19 @@ QskBoxShapeMetrics QskBoxShapeMetrics::toAbsolute( const QSizeF& size ) const no
const qreal rx = qskAbsoluted( size.width(), radius.width() ); const qreal rx = qskAbsoluted( size.width(), radius.width() );
const qreal ry = qskAbsoluted( size.height(), radius.height() ); const qreal ry = qskAbsoluted( size.height(), radius.height() );
if ( m_scalingMode == Circular ) switch ( m_scalingMode )
{
case Symmetric:
{ {
radius.rheight() = radius.rwidth() = std::min( rx, ry ); radius.rheight() = radius.rwidth() = std::min( rx, ry );
break;
} }
else case SymmetricByMaximum:
{
radius.rheight() = radius.rwidth() = std::max( rx, ry );
break;
}
default:
{ {
const auto ratio = radius.height() / radius.width(); const auto ratio = radius.height() / radius.width();
@ -128,6 +136,7 @@ QskBoxShapeMetrics QskBoxShapeMetrics::toAbsolute( const QSizeF& size ) const no
} }
} }
} }
}
return shape; return shape;
} }

View File

@ -29,11 +29,35 @@ class QSK_EXPORT QskBoxShapeMetrics
Q_PROPERTY( ScalingMode scalingMode READ scalingMode WRITE setScalingMode ) Q_PROPERTY( ScalingMode scalingMode READ scalingMode WRITE setScalingMode )
public: public:
/*
How to scale, when translating to Qt::AbsoluteSize
Symmetric/SymmetricByMaximum sets the aspect ratio between x/y radii
to 1:1, while Proportional preserves the aspect ratio of the relative radii.
Symmetric or Proportional shrink the larger radius, while SymmetricByMaximum
expands the smaller radius to achieve the desired aspect ratio.
The effect of the scaling on the implemented box rendering is:
- SymmetricByMaximum in combination with a relative radius of 100
results in an ellipse.
- Rectangles with rounded corners can be achieved by Symmetric in combination
with a relative radius < 100.
Note, that the scaling is affected by the aspect ratio of the relative radii and
the one of the absolute size.
The default setting is Symmetric.
*/
enum ScalingMode enum ScalingMode
{ {
// How to scale, when translating to Qt::AbsoluteSize Symmetric,
Circular, SymmetricByMaximum,
Elliptic
Proportional
}; };
Q_ENUM( ScalingMode ); Q_ENUM( ScalingMode );
@ -121,13 +145,13 @@ class QSK_EXPORT QskBoxShapeMetrics
QSizeF m_radii[ 4 ]; QSizeF m_radii[ 4 ];
Qt::SizeMode m_sizeMode : 2; Qt::SizeMode m_sizeMode : 2;
ScalingMode m_scalingMode : 1; ScalingMode m_scalingMode : 2;
}; };
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_scalingMode( Circular ) , m_scalingMode( Symmetric )
{ {
} }
@ -142,7 +166,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_scalingMode( Circular ) , m_scalingMode( Symmetric )
{ {
} }
@ -151,7 +175,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_scalingMode( Circular ) , m_scalingMode( Symmetric )
{ {
} }