QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraduationMetrics.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskGraduationMetrics.h"
7#include <qvariant.h>
8
9static void qskRegisterGraduationMetrics()
10{
11 qRegisterMetaType< QskGraduationMetrics >();
12
13#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
14 QMetaType::registerEqualsComparator< QskGraduationMetrics >();
15#endif
16}
17
18Q_CONSTRUCTOR_FUNCTION( qskRegisterGraduationMetrics )
19
20static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio )
21{
22 return from + ( to - from ) * ratio;
23}
24
25QskGraduationMetrics QskGraduationMetrics::interpolated(
26 const QskGraduationMetrics& to, const qreal ratio ) const noexcept
27{
28 if ( ( *this == to ) )
29 return to;
30
31 return { qskInterpolated( m_tickLengths[0], to.m_tickLengths[0], ratio ),
32 qskInterpolated( m_tickLengths[1], to.m_tickLengths[1], ratio ),
33 qskInterpolated( m_tickLengths[2], to.m_tickLengths[2], ratio ),
34 qskInterpolated( m_tickWidth, to.m_tickWidth, ratio ) };
35}
36
37QVariant QskGraduationMetrics::interpolate(
38 const QskGraduationMetrics& from, const QskGraduationMetrics& to, const qreal progress )
39{
40 return QVariant::fromValue( from.interpolated( to, progress ) );
41}
42
43#ifndef QT_NO_DEBUG_STREAM
44
45#include <qdebug.h>
46
47QDebug operator<<( QDebug debug, const QskGraduationMetrics& metrics )
48{
49 const char s[] = ", ";
50
51 QDebugStateSaver saver( debug );
52 debug.nospace();
53
54 debug << "Graduation";
55 debug << '(';
56 debug << metrics.minorTickLength() << s << metrics.mediumTickLength()
57 << s << metrics.majorTickLength() << "W:" << metrics.tickWidth();
58 debug << ')';
59
60 return debug;
61}
62
63#endif