diff --git a/examples/boxes/main.cpp b/examples/boxes/main.cpp index 6adbb7c1..ae68f825 100644 --- a/examples/boxes/main.cpp +++ b/examples/boxes/main.cpp @@ -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 ); diff --git a/examples/buttons/TestButton.qml b/examples/buttons/TestButton.qml index 8ad14523..fcdc26ef 100644 --- a/examples/buttons/TestButton.qml +++ b/examples/buttons/TestButton.qml @@ -19,7 +19,6 @@ Qsk.PushButton shape { sizeMode: Qt.RelativeSize - scalingMode: Qsk.BoxShapeMetrics.Circular radius: 10 } diff --git a/examples/buttons/buttons.qml b/examples/buttons/buttons.qml index ce93f330..dee2e448 100644 --- a/examples/buttons/buttons.qml +++ b/examples/buttons/buttons.qml @@ -129,7 +129,7 @@ Qsk.Window shape { sizeMode: Qt.RelativeSize - scalingMode: Qsk.BoxShapeMetrics.Elliptic + scalingMode: Qsk.BoxShapeMetrics.SymmetricByMaximum radius: 100 } } diff --git a/src/common/QskBoxShapeMetrics.cpp b/src/common/QskBoxShapeMetrics.cpp index f0726f0e..02dbb31d 100644 --- a/src/common/QskBoxShapeMetrics.cpp +++ b/src/common/QskBoxShapeMetrics.cpp @@ -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; + } } } } diff --git a/src/common/QskBoxShapeMetrics.h b/src/common/QskBoxShapeMetrics.h index c9b04c53..727900a4 100644 --- a/src/common/QskBoxShapeMetrics.h +++ b/src/common/QskBoxShapeMetrics.h @@ -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 ) { }