QskArcMetrics adjustments

This commit is contained in:
Uwe Rathmann 2021-10-20 09:27:05 +02:00
parent b89621a3d4
commit 73dbfeb708
6 changed files with 47 additions and 40 deletions

View File

@ -15,13 +15,11 @@ static void qskRegisterArcMetrics()
Q_CONSTRUCTOR_FUNCTION( qskRegisterArcMetrics ) Q_CONSTRUCTOR_FUNCTION( qskRegisterArcMetrics )
// copied from QskMargins.cpp, we should unify this somehwere:
static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio ) static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio )
{ {
return from + ( to - from ) * ratio; return from + ( to - from ) * ratio;
} }
// copied from QskBoxBorderMetrics.cpp, we should unify this somewhere:
static inline qreal qskAbsoluted( qreal length, qreal percentage ) static inline qreal qskAbsoluted( qreal length, qreal percentage )
{ {
// 100% means -> 0.5 of length // 100% means -> 0.5 of length
@ -34,12 +32,12 @@ void QskArcMetrics::setWidth( qreal width ) noexcept
m_width = width; m_width = width;
} }
void QskArcMetrics::setStartAngle( int startAngle ) noexcept void QskArcMetrics::setStartAngle( qreal startAngle ) noexcept
{ {
m_startAngle = startAngle; m_startAngle = startAngle;
} }
void QskArcMetrics::setSpanAngle( int spanAngle ) noexcept void QskArcMetrics::setSpanAngle( qreal spanAngle ) noexcept
{ {
m_spanAngle = spanAngle; m_spanAngle = spanAngle;
} }
@ -56,7 +54,11 @@ QskArcMetrics QskArcMetrics::interpolated(
return to; return to;
const qreal width = qskInterpolated( m_width, to.m_width, ratio ); const qreal width = qskInterpolated( m_width, to.m_width, ratio );
return QskArcMetrics( width, m_startAngle, m_spanAngle, m_sizeMode );
const qreal s1 = qskInterpolated( m_startAngle, to.m_startAngle, ratio );
const qreal s2 = qskInterpolated( endAngle(), to.endAngle(), ratio );
return QskArcMetrics( width, s1, s2 - s1, m_sizeMode );
} }
QVariant QskArcMetrics::interpolate( QVariant QskArcMetrics::interpolate(
@ -71,18 +73,20 @@ QskArcMetrics QskArcMetrics::toAbsolute( const QSizeF& size ) const noexcept
if ( m_sizeMode != Qt::RelativeSize ) if ( m_sizeMode != Qt::RelativeSize )
return *this; return *this;
QskArcMetrics absoluted = *this; /*
Being relative to what - TODO ?
I can imagine arcs being relative to other arcs !!!
*/
auto& w = absoluted.m_width; QskArcMetrics absoluted = *this;
if ( size.isEmpty() ) if ( size.isEmpty() )
{ {
w = 0; absoluted.m_width = 0;
} }
else else
{ {
// for now we just use the width: absoluted.m_width = qskAbsoluted( size.width(), absoluted.m_width );
w = qskAbsoluted( size.width(), w );
} }
absoluted.m_sizeMode = Qt::AbsoluteSize; absoluted.m_sizeMode = Qt::AbsoluteSize;
@ -95,6 +99,7 @@ uint QskArcMetrics::hash( uint seed ) const noexcept
uint hash = qHash( m_width, seed ); uint hash = qHash( m_width, seed );
hash = qHash( m_startAngle, hash ); hash = qHash( m_startAngle, hash );
hash = qHash( m_spanAngle, hash ); hash = qHash( m_spanAngle, hash );
const int mode = m_sizeMode; const int mode = m_sizeMode;
return qHashBits( &mode, sizeof( mode ), hash ); return qHashBits( &mode, sizeof( mode ), hash );
} }

View File

@ -17,14 +17,13 @@ class QSK_EXPORT QskArcMetrics
Q_GADGET Q_GADGET
Q_PROPERTY( qreal width READ width WRITE setWidth ) Q_PROPERTY( qreal width READ width WRITE setWidth )
Q_PROPERTY( int startAngle READ startAngle WRITE setStartAngle ) Q_PROPERTY( qreal startAngle READ startAngle WRITE setStartAngle )
Q_PROPERTY( int spanAngle READ spanAngle WRITE setSpanAngle ) Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle )
Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode ) Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode )
public: public:
constexpr QskArcMetrics() noexcept; constexpr QskArcMetrics() noexcept;
constexpr QskArcMetrics( qreal width, qreal startAngle, qreal spanAngle,
constexpr QskArcMetrics( qreal width, int startAngle, int spanAngle,
Qt::SizeMode = Qt::AbsoluteSize ) noexcept; Qt::SizeMode = Qt::AbsoluteSize ) noexcept;
bool operator==( const QskArcMetrics& ) const noexcept; bool operator==( const QskArcMetrics& ) const noexcept;
@ -35,11 +34,13 @@ class QSK_EXPORT QskArcMetrics
void setWidth( qreal width ) noexcept; void setWidth( qreal width ) noexcept;
constexpr qreal width() const noexcept; constexpr qreal width() const noexcept;
void setStartAngle( int startAngle ) noexcept; void setStartAngle( qreal startAngle ) noexcept;
constexpr int startAngle() const noexcept; constexpr qreal startAngle() const noexcept;
void setSpanAngle( int spanAngle ) noexcept; void setSpanAngle( qreal spanAngle ) noexcept;
constexpr int spanAngle() const noexcept; constexpr qreal spanAngle() const noexcept;
constexpr qreal endAngle() const noexcept;
void setSizeMode( Qt::SizeMode ) noexcept; void setSizeMode( Qt::SizeMode ) noexcept;
constexpr Qt::SizeMode sizeMode() const noexcept; constexpr Qt::SizeMode sizeMode() const noexcept;
@ -56,8 +57,8 @@ class QSK_EXPORT QskArcMetrics
private: private:
qreal m_width; qreal m_width;
int m_startAngle; qreal m_startAngle;
int m_spanAngle; qreal m_spanAngle;
Qt::SizeMode m_sizeMode; Qt::SizeMode m_sizeMode;
}; };
@ -69,8 +70,8 @@ inline constexpr QskArcMetrics::QskArcMetrics() noexcept
{ {
} }
inline constexpr QskArcMetrics::QskArcMetrics( qreal width, inline constexpr QskArcMetrics::QskArcMetrics(
int startAngle, int spanAngle, qreal width, qreal startAngle, qreal spanAngle,
Qt::SizeMode sizeMode ) noexcept Qt::SizeMode sizeMode ) noexcept
: m_width( width ) : m_width( width )
, m_startAngle( startAngle ) , m_startAngle( startAngle )
@ -83,8 +84,8 @@ inline bool QskArcMetrics::operator==(
const QskArcMetrics& other ) const noexcept const QskArcMetrics& other ) const noexcept
{ {
return ( qskFuzzyCompare( m_width, other.m_width ) return ( qskFuzzyCompare( m_width, other.m_width )
&& m_startAngle == other.m_startAngle && qskFuzzyCompare( m_startAngle, other.m_startAngle )
&& m_spanAngle == other.m_spanAngle && qskFuzzyCompare( m_spanAngle, other.m_spanAngle )
&& m_sizeMode == other.m_sizeMode ); && m_sizeMode == other.m_sizeMode );
} }
@ -96,10 +97,7 @@ inline bool QskArcMetrics::operator!=(
inline constexpr bool QskArcMetrics::isNull() const noexcept inline constexpr bool QskArcMetrics::isNull() const noexcept
{ {
return ( qFuzzyIsNull( m_width ) return qFuzzyIsNull( m_width ) || qFuzzyIsNull( m_spanAngle );
&& m_startAngle == 0
&& m_spanAngle == 0
&& m_sizeMode == Qt::AbsoluteSize );
} }
inline constexpr qreal QskArcMetrics::width() const noexcept inline constexpr qreal QskArcMetrics::width() const noexcept
@ -107,16 +105,21 @@ inline constexpr qreal QskArcMetrics::width() const noexcept
return m_width; return m_width;
} }
inline constexpr int QskArcMetrics::startAngle() const noexcept inline constexpr qreal QskArcMetrics::startAngle() const noexcept
{ {
return m_startAngle; return m_startAngle;
} }
inline constexpr int QskArcMetrics::spanAngle() const noexcept inline constexpr qreal QskArcMetrics::spanAngle() const noexcept
{ {
return m_spanAngle; return m_spanAngle;
} }
inline constexpr qreal QskArcMetrics::endAngle() const noexcept
{
return m_startAngle + m_spanAngle;
}
inline constexpr Qt::SizeMode QskArcMetrics::sizeMode() const noexcept inline constexpr Qt::SizeMode QskArcMetrics::sizeMode() const noexcept
{ {
return m_sizeMode; return m_sizeMode;

View File

@ -470,7 +470,7 @@ QskBoxBorderColors QskSkinHintTableEditor::boxBorderColors( QskAspect aspect ) c
} }
void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect, qreal width, void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect, qreal width,
int startAngle, int spanAngle, Qt::SizeMode sizeMode ) qreal startAngle, qreal spanAngle, Qt::SizeMode sizeMode )
{ {
setMetricHint( aspectShape( aspect ), setMetricHint( aspectShape( aspect ),
QskArcMetrics( width, startAngle, spanAngle, sizeMode ) ); QskArcMetrics( width, startAngle, spanAngle, sizeMode ) );

View File

@ -223,8 +223,7 @@ class QSK_EXPORT QskSkinHintTableEditor
// arcMetrics // arcMetrics
void setArcMetrics( QskAspect, qreal, int, int, void setArcMetrics( QskAspect, qreal, qreal, qreal, Qt::SizeMode = Qt::AbsoluteSize );
Qt::SizeMode = Qt::AbsoluteSize );
void setArcMetrics( QskAspect, void setArcMetrics( QskAspect,
const QskArcMetrics&, QskStateCombination = QskStateCombination() ); const QskArcMetrics&, QskStateCombination = QskStateCombination() );

View File

@ -375,7 +375,7 @@ QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
} }
QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable, QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
QSGNode* node, int startAngle, int spanAngle, QSGNode* node, qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol subControl ) const QskAspect::Subcontrol subControl ) const
{ {
const auto rect = qskSubControlRect( this, skinnable, subControl ); const auto rect = qskSubControlRect( this, skinnable, subControl );
@ -384,7 +384,7 @@ QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
} }
QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable, QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
QSGNode* node, const QRectF& rect, int startAngle, int spanAngle, QSGNode* node, const QRectF& rect, qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol subControl ) QskAspect::Subcontrol subControl )
{ {
const auto fillGradient = skinnable->gradientHint( subControl ); const auto fillGradient = skinnable->gradientHint( subControl );
@ -394,7 +394,7 @@ QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable, QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
QSGNode* node, const QRectF& rect, const QskGradient& fillGradient, QSGNode* node, const QRectF& rect, const QskGradient& fillGradient,
int startAngle, int spanAngle, QskAspect::Subcontrol subControl ) qreal startAngle, qreal spanAngle, QskAspect::Subcontrol subControl )
{ {
auto arcMetrics = skinnable->arcMetricsHint( subControl ); auto arcMetrics = skinnable->arcMetricsHint( subControl );
arcMetrics.setStartAngle( startAngle ); arcMetrics.setStartAngle( startAngle );

View File

@ -64,10 +64,10 @@ class QSK_EXPORT QskSkinlet
QskAspect::Subcontrol ); QskAspect::Subcontrol );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*, static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
const QRectF&, int startAngle, int spanAngle, QskAspect::Subcontrol ); const QRectF&, qreal startAngle, qreal spanAngle, QskAspect::Subcontrol );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*, static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
const QRectF&, const QskGradient&, int startAngle, int spanAngle, const QRectF&, const QskGradient&, qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol ); QskAspect::Subcontrol );
static QSGNode* updateTextNode( const QskSkinnable*, QSGNode*, static QSGNode* updateTextNode( const QskSkinnable*, QSGNode*,
@ -107,7 +107,7 @@ class QSK_EXPORT QskSkinlet
QskAspect::Subcontrol ) const; QskAspect::Subcontrol ) const;
QSGNode* updateArcNode( const QskSkinnable*, QSGNode*, QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
int startAngle, int spanAngle, qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol ) const; QskAspect::Subcontrol ) const;
QSGNode* updateBoxClipNode( const QskSkinnable*, QSGNode*, QSGNode* updateBoxClipNode( const QskSkinnable*, QSGNode*,