2021-10-20 07:50:25 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2021 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskArcMetrics.h"
|
|
|
|
|
|
|
|
#include <qhashfunctions.h>
|
|
|
|
#include <qvariant.h>
|
|
|
|
|
|
|
|
static void qskRegisterArcMetrics()
|
|
|
|
{
|
|
|
|
qRegisterMetaType< QskArcMetrics >();
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_CONSTRUCTOR_FUNCTION( qskRegisterArcMetrics )
|
|
|
|
|
|
|
|
static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio )
|
|
|
|
{
|
|
|
|
return from + ( to - from ) * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline qreal qskAbsoluted( qreal length, qreal percentage )
|
|
|
|
{
|
|
|
|
// 100% means -> 0.5 of length
|
|
|
|
percentage = qBound( 0.0, percentage, 100.0 );
|
|
|
|
return percentage / 100.0 * 0.5 * length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskArcMetrics::setWidth( qreal width ) noexcept
|
|
|
|
{
|
|
|
|
m_width = width;
|
|
|
|
}
|
|
|
|
|
2021-10-20 09:27:05 +02:00
|
|
|
void QskArcMetrics::setStartAngle( qreal startAngle ) noexcept
|
2021-10-20 07:50:25 +02:00
|
|
|
{
|
|
|
|
m_startAngle = startAngle;
|
|
|
|
}
|
|
|
|
|
2021-10-20 09:27:05 +02:00
|
|
|
void QskArcMetrics::setSpanAngle( qreal spanAngle ) noexcept
|
2021-10-20 07:50:25 +02:00
|
|
|
{
|
|
|
|
m_spanAngle = spanAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskArcMetrics::setSizeMode( Qt::SizeMode sizeMode ) noexcept
|
|
|
|
{
|
|
|
|
m_sizeMode = sizeMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
QskArcMetrics QskArcMetrics::interpolated(
|
|
|
|
const QskArcMetrics& to, qreal ratio ) const noexcept
|
|
|
|
{
|
|
|
|
if ( ( *this == to ) || ( m_sizeMode != to.m_sizeMode ) )
|
|
|
|
return to;
|
|
|
|
|
|
|
|
const qreal width = qskInterpolated( m_width, to.m_width, ratio );
|
2021-10-20 09:27:05 +02:00
|
|
|
|
|
|
|
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 );
|
2021-10-20 07:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant QskArcMetrics::interpolate(
|
|
|
|
const QskArcMetrics& from, const QskArcMetrics& to,
|
|
|
|
qreal progress )
|
|
|
|
{
|
|
|
|
return QVariant::fromValue( from.interpolated( to, progress ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskArcMetrics QskArcMetrics::toAbsolute( const QSizeF& size ) const noexcept
|
|
|
|
{
|
|
|
|
if ( m_sizeMode != Qt::RelativeSize )
|
|
|
|
return *this;
|
|
|
|
|
2021-10-20 09:27:05 +02:00
|
|
|
QskArcMetrics absoluted = *this;
|
2021-10-20 07:50:25 +02:00
|
|
|
|
2021-10-20 12:42:48 +02:00
|
|
|
const auto l = qMin( size.width(), size.height() );
|
|
|
|
if ( l <= 0.0 )
|
|
|
|
absoluted.m_width = 0.0;
|
2021-10-20 07:50:25 +02:00
|
|
|
else
|
2021-10-20 12:42:48 +02:00
|
|
|
absoluted.m_width = qskAbsoluted( l, absoluted.m_width );
|
2021-10-20 07:50:25 +02:00
|
|
|
|
|
|
|
absoluted.m_sizeMode = Qt::AbsoluteSize;
|
|
|
|
|
|
|
|
return absoluted;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint QskArcMetrics::hash( uint seed ) const noexcept
|
|
|
|
{
|
|
|
|
uint hash = qHash( m_width, seed );
|
|
|
|
hash = qHash( m_startAngle, hash );
|
|
|
|
hash = qHash( m_spanAngle, hash );
|
2021-10-20 09:27:05 +02:00
|
|
|
|
2021-10-20 07:50:25 +02:00
|
|
|
const int mode = m_sizeMode;
|
|
|
|
return qHashBits( &mode, sizeof( mode ), hash );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
|
|
|
|
#include <qdebug.h>
|
|
|
|
|
|
|
|
QDebug operator<<( QDebug debug, const QskArcMetrics& metrics )
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver( debug );
|
|
|
|
debug.nospace();
|
|
|
|
|
2021-10-20 12:42:48 +02:00
|
|
|
debug << "QskArcMetrics" << '(';
|
|
|
|
debug << metrics.width() << ',' << metrics.sizeMode();
|
|
|
|
debug << ",[" << metrics.startAngle() << ',' << metrics.spanAngle() << ']';
|
2021-10-20 07:50:25 +02:00
|
|
|
debug << ')';
|
|
|
|
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "moc_QskArcMetrics.cpp"
|