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 )
// copied from QskMargins.cpp, we should unify this somehwere:
static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio )
{
return from + ( to - from ) * ratio;
}
// copied from QskBoxBorderMetrics.cpp, we should unify this somewhere:
static inline qreal qskAbsoluted( qreal length, qreal percentage )
{
// 100% means -> 0.5 of length
@ -34,12 +32,12 @@ void QskArcMetrics::setWidth( qreal width ) noexcept
m_width = width;
}
void QskArcMetrics::setStartAngle( int startAngle ) noexcept
void QskArcMetrics::setStartAngle( qreal startAngle ) noexcept
{
m_startAngle = startAngle;
}
void QskArcMetrics::setSpanAngle( int spanAngle ) noexcept
void QskArcMetrics::setSpanAngle( qreal spanAngle ) noexcept
{
m_spanAngle = spanAngle;
}
@ -56,7 +54,11 @@ QskArcMetrics QskArcMetrics::interpolated(
return to;
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(
@ -71,18 +73,20 @@ QskArcMetrics QskArcMetrics::toAbsolute( const QSizeF& size ) const noexcept
if ( m_sizeMode != Qt::RelativeSize )
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() )
{
w = 0;
absoluted.m_width = 0;
}
else
{
// for now we just use the width:
w = qskAbsoluted( size.width(), w );
absoluted.m_width = qskAbsoluted( size.width(), absoluted.m_width );
}
absoluted.m_sizeMode = Qt::AbsoluteSize;
@ -95,6 +99,7 @@ uint QskArcMetrics::hash( uint seed ) const noexcept
uint hash = qHash( m_width, seed );
hash = qHash( m_startAngle, hash );
hash = qHash( m_spanAngle, hash );
const int mode = m_sizeMode;
return qHashBits( &mode, sizeof( mode ), hash );
}

View File

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

View File

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

View File

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

View File

@ -375,7 +375,7 @@ 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
{
const auto rect = qskSubControlRect( this, skinnable, subControl );
@ -384,7 +384,7 @@ 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 )
{
const auto fillGradient = skinnable->gradientHint( subControl );
@ -394,7 +394,7 @@ QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
QSGNode* QskSkinlet::updateArcNode( const QskSkinnable* skinnable,
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 );
arcMetrics.setStartAngle( startAngle );

View File

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