QskInterval::center(), QskInterval::stretch removed as they the

implementation is only handling normalized intervals
This commit is contained in:
Uwe Rathmann 2024-11-25 09:02:04 +01:00
parent 494c370e61
commit ea3d7a5e69
2 changed files with 22 additions and 33 deletions

View File

@ -36,8 +36,6 @@ class QSK_EXPORT QskIntervalF
constexpr qreal upperBound() const noexcept;
void setUpperBound( qreal ) noexcept;
constexpr qreal center() const noexcept;
void spanFromLowerBound( qreal ) noexcept;
void spanFromUpperBound( qreal ) noexcept;
@ -68,9 +66,6 @@ class QSK_EXPORT QskIntervalF
void extend( qreal value ) noexcept;
QskIntervalF extended( qreal value ) const noexcept;
void stretch( qreal length ) noexcept;
constexpr QskIntervalF stretched( qreal length ) const noexcept;
QskIntervalF operator|( const QskIntervalF& ) const noexcept;
QskIntervalF operator&( const QskIntervalF& ) const noexcept;
@ -140,11 +135,6 @@ inline constexpr qreal QskIntervalF::upperBound() const noexcept
return m_upperBound;
}
inline constexpr qreal QskIntervalF::center() const noexcept
{
return m_lowerBound + 0.5 * ( m_upperBound - m_lowerBound );
}
inline constexpr qreal QskIntervalF::length() const noexcept
{
return ( m_upperBound > m_lowerBound ) ? ( m_upperBound - m_lowerBound ) : 0.0;
@ -208,18 +198,6 @@ inline constexpr QskIntervalF QskIntervalF::normalized( qreal value1, qreal valu
return ( value1 < value2 ) ? QskIntervalF( value1, value2 ) : QskIntervalF( value2, value1 );
}
inline void QskIntervalF::stretch( qreal length ) noexcept
{
m_lowerBound = center() - 0.5 * length;
m_upperBound = m_lowerBound + length;
}
inline constexpr QskIntervalF QskIntervalF::stretched( qreal length ) const noexcept
{
const auto lowerBound = center() - 0.5 * length;
return QskIntervalF( lowerBound, lowerBound + length );
}
inline QskIntervalF QskIntervalF::operator&( const QskIntervalF& other ) const noexcept
{
return intersected( other );

View File

@ -6,9 +6,9 @@
#include "QskSliderSkinlet.h"
#include "QskSlider.h"
#include "QskFunctions.h"
#include "QskIntervalF.h"
#include <qvector.h>
#include <qpair.h>
#include <qmath.h>
// the color of graduation ticks might different, when being on top of the filling
@ -65,6 +65,19 @@ static inline bool qskHasGraduation( const QskSlider* slider )
return false;
}
static inline QPair< qreal, qreal > qskTickSpan( qreal min, qreal max, qreal length )
{
if ( length >= 0.0 )
{
// using the center of [min,max]
min += 0.5 * ( max - min - length );
max = min + length;
}
return { min, max };
}
QskSliderSkinlet::QskSliderSkinlet( QskSkin* skin )
: Inherited( skin )
{
@ -285,23 +298,21 @@ QRectF QskSliderSkinlet::tickRect( const QskSlider* slider,
{
const auto x = tickPos * r.width() - 0.5 * size.width();
QskIntervalF intv( padding.top(), r.height() - padding.bottom() );
if ( size.height() >= 0.0 )
intv.stretch( size.height() );
const auto span = qskTickSpan(
padding.top(), r.height() - padding.bottom(), size.height() );
return QRectF( r.x() + x, r.y() + intv.lowerBound(),
size.width(), intv.length() );
return QRectF( r.x() + x, r.y() + span.first,
size.width(), span.second - span.first );
}
else
{
const auto y = tickPos * r.height() + 0.5 * size.height();
QskIntervalF intv( padding.left(), r.width() - padding.right() );
if ( size.width() >= 0.0 )
intv.stretch( size.width() );
const auto span = qskTickSpan(
padding.left(), r.width() - padding.right(), size.width() );
return QRectF( r.x() + intv.lowerBound(), r.bottom() - y,
intv.length(), size.height() );
return QRectF( r.x() + span.first, r.bottom() - y,
span.second - span.first, size.height() );
}
}