/****************************************************************************** * 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 #include static void qskRegisterArcMetrics() { qRegisterMetaType< QskArcMetrics >(); #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) QMetaType::registerEqualsComparator< QskArcMetrics >(); #endif } 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; } void QskArcMetrics::setStartAngle( qreal startAngle ) noexcept { m_startAngle = startAngle; } void QskArcMetrics::setSpanAngle( qreal spanAngle ) noexcept { 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 ); 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( 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; QskArcMetrics absoluted = *this; const auto l = qMin( size.width(), size.height() ); if ( l <= 0.0 ) absoluted.m_width = 0.0; else absoluted.m_width = qskAbsoluted( l, absoluted.m_width ); absoluted.m_sizeMode = Qt::AbsoluteSize; return absoluted; } QskHashValue QskArcMetrics::hash( QskHashValue seed ) const noexcept { auto 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 ); } #ifndef QT_NO_DEBUG_STREAM #include QDebug operator<<( QDebug debug, const QskArcMetrics& metrics ) { QDebugStateSaver saver( debug ); debug.nospace(); debug << "QskArcMetrics" << '('; debug << metrics.width() << ',' << metrics.sizeMode(); debug << ",[" << metrics.startAngle() << ',' << metrics.spanAngle() << ']'; debug << ')'; return debug; } #endif #include "moc_QskArcMetrics.cpp"