6#include "QskBoxBorderMetrics.h"
8#include <qhashfunctions.h>
12static void qskRegisterBoxBorderMetrics()
14 qRegisterMetaType< QskBoxBorderMetrics >();
16#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
17 QMetaType::registerEqualsComparator< QskBoxBorderMetrics >();
20 QMetaType::registerConverter< QskMargins, QskBoxBorderMetrics >(
23 QMetaType::registerConverter< int, QskBoxBorderMetrics >(
26 QMetaType::registerConverter< qreal, QskBoxBorderMetrics >(
30Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxBorderMetrics )
32static inline qreal qskToAbsolute( qreal length, qreal percentage )
35 percentage = qBound( 0.0, percentage, 100.0 );
36 return percentage / 100.0 * 0.5 * length;
39void QskBoxBorderMetrics::setSizeMode( Qt::SizeMode sizeMode )
noexcept
41 m_sizeMode = sizeMode;
44void QskBoxBorderMetrics::setWidths(
const QskMargins& widths )
noexcept
46 m_widths.setLeft( qMax( widths.left(), 0.0 ) );
47 m_widths.setTop( qMax( widths.top(), 0.0 ) );
48 m_widths.setRight( qMax( widths.right(), 0.0 ) );
49 m_widths.setBottom( qMax( widths.bottom(), 0.0 ) );
52void QskBoxBorderMetrics::setWidthAt( Qt::Edges edges, qreal width )
noexcept
54 m_widths.setMarginsAt( edges, qMax( width, 0.0 ) );
59 if ( m_sizeMode != Qt::RelativeSize )
64 auto& w = absoluted.m_widths;
72 w.setLeft( qskToAbsolute( size.width(), w.left() ) );
73 w.setTop( qskToAbsolute( size.height(), w.top() ) );
74 w.setRight( qskToAbsolute( size.width(), w.right() ) );
75 w.setBottom( qskToAbsolute( size.height(), w.bottom() ) );
78 absoluted.m_sizeMode = Qt::AbsoluteSize;
83QRectF QskBoxBorderMetrics::adjustedRect(
const QRectF& rect )
const
85 if ( m_sizeMode == Qt::AbsoluteSize )
86 return rect.marginsRemoved( m_widths );
88 const auto m = toAbsolute( rect.size() );
89 return rect.marginsRemoved( m.m_widths );
95 if ( ( *
this == to ) || ( m_sizeMode != to.m_sizeMode ) )
98 const auto widths = m_widths.interpolated( to.m_widths, ratio );
102QVariant QskBoxBorderMetrics::interpolate(
106 return QVariant::fromValue( from.interpolated( to, progress ) );
109QskHashValue QskBoxBorderMetrics::hash( QskHashValue seed )
const noexcept
111 auto hash = qHashBits( &m_widths,
sizeof( m_widths ), seed );
113 const int mode = m_sizeMode;
114 return qHashBits( &mode,
sizeof( mode ), hash );
117#ifndef QT_NO_DEBUG_STREAM
123 QDebugStateSaver saver( debug );
126 debug <<
"BoxBorder" <<
"( ";
128 if ( metrics.sizeMode() != Qt::AbsoluteSize )
129 debug << metrics.sizeMode() <<
", ";
131 const auto& w = metrics.widths();
133 if ( metrics.isEquidistant() )
139 const char s[] =
", ";
140 debug << w.left() << s << w.top() << s << w.right() << s << w.bottom();
150#include "moc_QskBoxBorderMetrics.cpp"