QskBoxShapeMetrics::ScalingMode: using better names, missing mode
reinserted
This commit is contained in:
parent
64fee0247e
commit
d71b972232
@ -72,7 +72,7 @@ static void addTestRectangle( QskLinearBox* parent )
|
||||
box->setBorderWidth( 10, 20, 40, 20 );
|
||||
|
||||
QskBoxShapeMetrics shape( 50, Qt::RelativeSize );
|
||||
shape.setScalingMode( QskBoxShapeMetrics::Elliptic );
|
||||
shape.setScalingMode( QskBoxShapeMetrics::Proportional );
|
||||
shape.setRadius( Qt::BottomRightCorner, 30 );
|
||||
shape.setRadius( Qt::TopRightCorner, 70 );
|
||||
|
||||
|
@ -19,7 +19,6 @@ Qsk.PushButton
|
||||
shape
|
||||
{
|
||||
sizeMode: Qt.RelativeSize
|
||||
scalingMode: Qsk.BoxShapeMetrics.Circular
|
||||
radius: 10
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ Qsk.Window
|
||||
shape
|
||||
{
|
||||
sizeMode: Qt.RelativeSize
|
||||
scalingMode: Qsk.BoxShapeMetrics.Elliptic
|
||||
scalingMode: Qsk.BoxShapeMetrics.SymmetricByMaximum
|
||||
radius: 100
|
||||
}
|
||||
}
|
||||
|
@ -108,23 +108,32 @@ QskBoxShapeMetrics QskBoxShapeMetrics::toAbsolute( const QSizeF& size ) const no
|
||||
const qreal rx = qskAbsoluted( size.width(), radius.width() );
|
||||
const qreal ry = qskAbsoluted( size.height(), radius.height() );
|
||||
|
||||
if ( m_scalingMode == Circular )
|
||||
switch ( m_scalingMode )
|
||||
{
|
||||
radius.rheight() = radius.rwidth() = std::min( rx, ry );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto ratio = radius.height() / radius.width();
|
||||
|
||||
if ( ratio >= 1.0 )
|
||||
case Symmetric:
|
||||
{
|
||||
radius.rwidth() = ry / ratio;
|
||||
radius.rheight() = ry;
|
||||
radius.rheight() = radius.rwidth() = std::min( rx, ry );
|
||||
break;
|
||||
}
|
||||
else
|
||||
case SymmetricByMaximum:
|
||||
{
|
||||
radius.rwidth() = rx;
|
||||
radius.rheight() = rx * ratio;
|
||||
radius.rheight() = radius.rwidth() = std::max( rx, ry );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
const auto ratio = radius.height() / radius.width();
|
||||
|
||||
if ( ratio >= 1.0 )
|
||||
{
|
||||
radius.rwidth() = ry / ratio;
|
||||
radius.rheight() = ry;
|
||||
}
|
||||
else
|
||||
{
|
||||
radius.rwidth() = rx;
|
||||
radius.rheight() = rx * ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,35 @@ class QSK_EXPORT QskBoxShapeMetrics
|
||||
Q_PROPERTY( ScalingMode scalingMode READ scalingMode WRITE setScalingMode )
|
||||
|
||||
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
|
||||
{
|
||||
// How to scale, when translating to Qt::AbsoluteSize
|
||||
Circular,
|
||||
Elliptic
|
||||
Symmetric,
|
||||
SymmetricByMaximum,
|
||||
|
||||
Proportional
|
||||
};
|
||||
Q_ENUM( ScalingMode );
|
||||
|
||||
@ -121,13 +145,13 @@ class QSK_EXPORT QskBoxShapeMetrics
|
||||
|
||||
QSizeF m_radii[ 4 ];
|
||||
Qt::SizeMode m_sizeMode : 2;
|
||||
ScalingMode m_scalingMode : 1;
|
||||
ScalingMode m_scalingMode : 2;
|
||||
};
|
||||
|
||||
inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics() noexcept
|
||||
: m_radii{ { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }
|
||||
, m_sizeMode( Qt::AbsoluteSize )
|
||||
, m_scalingMode( Circular )
|
||||
, m_scalingMode( Symmetric )
|
||||
{
|
||||
}
|
||||
|
||||
@ -142,7 +166,7 @@ inline constexpr QskBoxShapeMetrics::QskBoxShapeMetrics(
|
||||
: m_radii{ { radiusX, radiusY }, { radiusX, radiusY },
|
||||
{ radiusX, radiusY }, { radiusX, radiusY } }
|
||||
, 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 },
|
||||
{ bottomLeft, bottomLeft }, { bottomRight, bottomRight } }
|
||||
, m_sizeMode( sizeMode )
|
||||
, m_scalingMode( Circular )
|
||||
, m_scalingMode( Symmetric )
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user