6#include "QskShadowMetrics.h"
8#include <qhashfunctions.h>
12static void qskRegisterShadowMetrics()
14 qRegisterMetaType< QskShadowMetrics >();
16#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
17 QMetaType::registerEqualsComparator< QskShadowMetrics >();
21Q_CONSTRUCTOR_FUNCTION( qskRegisterShadowMetrics )
23static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio )
25 return from + ( to - from ) * ratio;
28static inline qreal qskToAbsolute( qreal length, qreal percentage )
30 percentage = qBound( 0.0, percentage, 100.0 );
31 return percentage / 100.0 * length;
34QskShadowMetrics QskShadowMetrics::toAbsolute(
const QSizeF& size )
const noexcept
36 if ( m_sizeMode != Qt::RelativeSize )
42 const qreal length = std::max( size.width(), size.height() );
44 const qreal spreadRadius = qskToAbsolute( length, m_spreadRadius );
45 const qreal blurRadius = qskToAbsolute( length, m_spreadRadius );
46 const qreal dx = qskToAbsolute( size.width(), m_offset.x() );
47 const qreal dy = qskToAbsolute( size.height(), m_offset.x() );
55 if ( ( *
this == to ) || ( m_sizeMode != to.m_sizeMode ) )
59 qskInterpolated( m_offset.x(), to.m_offset.x(), ratio ),
60 qskInterpolated( m_offset.y(), to.m_offset.y(), ratio ) );
63 qskInterpolated( m_spreadRadius, to.m_spreadRadius, ratio ),
64 qskInterpolated( m_blurRadius, to.m_blurRadius, ratio ),
66 metrics.m_sizeMode = m_sizeMode;
71QVariant QskShadowMetrics::interpolate(
75 return QVariant::fromValue( from.interpolated( to, progress ) );
78QRectF QskShadowMetrics::shadowRect(
const QRectF& sourceRect )
const
80 const auto metrics = toAbsolute( sourceRect.size() );
81 const auto extent = metrics.m_spreadRadius + metrics.m_blurRadius;
84 sourceRect.x() + metrics.m_offset.x() - extent,
85 sourceRect.y() + metrics.m_offset.y() - extent,
86 sourceRect.width() + 2 * extent,
87 sourceRect.height() + 2 * extent );
90QskHashValue QskShadowMetrics::hash( QskHashValue seed )
const noexcept
94 hash = qHash( m_offset.x(), seed );
95 hash = qHash( m_offset.y(), seed );
96 hash = qHash( m_spreadRadius, hash );
97 hash = qHash( m_blurRadius, hash );
98 hash = qHash( m_sizeMode, hash );
99 hash = qHash( m_shapeMode, hash );
104#ifndef QT_NO_DEBUG_STREAM
110 QDebugStateSaver saver( debug );
113 debug <<
"Shadow" <<
'(';
114 debug <<
" spread:" << metrics.spreadRadius();
115 debug <<
" blur:" << metrics.blurRadius();
116 debug <<
" dx:" << metrics.offset().x();
117 debug <<
" dy:" << metrics.offset().y();
125#include "moc_QskShadowMetrics.cpp"