-
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
244 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,9 @@ class QSK_EXPORT QskAspect | |
|
||
Shadow, | ||
Shape, | ||
Border | ||
Border, | ||
|
||
Graduation | ||
}; | ||
Q_ENUM( Primitive ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "QskGraduationMetrics.h" | ||
|
||
#include <qvariant.h> | ||
|
||
static void qskRegisterGraduationMetrics() | ||
{ | ||
qRegisterMetaType< QskGraduationMetrics >(); | ||
|
||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) | ||
QMetaType::registerEqualsComparator< QskGraduationMetrics >(); | ||
#endif | ||
} | ||
|
||
Q_CONSTRUCTOR_FUNCTION( qskRegisterGraduationMetrics ) | ||
|
||
static inline qreal qskInterpolated( qreal from, qreal to, qreal ratio ) | ||
{ | ||
return from + ( to - from ) * ratio; | ||
} | ||
|
||
QskGraduationMetrics QskGraduationMetrics::interpolated( | ||
const QskGraduationMetrics& to, const qreal ratio ) const noexcept | ||
{ | ||
if ( ( *this == to ) ) | ||
return to; | ||
|
||
return { qskInterpolated( m_tickLengths[0], to.m_tickLengths[0], ratio ), | ||
qskInterpolated( m_tickLengths[1], to.m_tickLengths[1], ratio ), | ||
qskInterpolated( m_tickLengths[2], to.m_tickLengths[2], ratio ) }; | ||
} | ||
|
||
QVariant QskGraduationMetrics::interpolate( | ||
const QskGraduationMetrics& from, const QskGraduationMetrics& to, const qreal progress ) | ||
{ | ||
return QVariant::fromValue( from.interpolated( to, progress ) ); | ||
} | ||
|
||
#ifndef QT_NO_DEBUG_STREAM | ||
|
||
#include <qdebug.h> | ||
|
||
QDebug operator<<( QDebug debug, const QskGraduationMetrics& metrics ) | ||
{ | ||
const char s[] = ", "; | ||
|
||
QDebugStateSaver saver( debug ); | ||
debug.nospace(); | ||
|
||
debug << "Graduation"; | ||
debug << '('; | ||
debug << metrics.minorTickLength() << s << metrics.mediumTickLength() | ||
<< s << metrics.majorTickLength(); | ||
debug << ')'; | ||
|
||
return debug; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/****************************************************************************** | ||
* QSkinny - Copyright (C) 2016 Uwe Rathmann | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*****************************************************************************/ | ||
|
||
#ifndef QSK_GRADUATION_METRICS_H | ||
#define QSK_GRADUATION_METRICS_H | ||
|
||
#include "QskScaleTickmarks.h" | ||
#include "QskFunctions.h" | ||
#include <algorithm> | ||
#include <qmetatype.h> | ||
|
||
class QSK_EXPORT QskGraduationMetrics | ||
{ | ||
Q_GADGET | ||
Q_PROPERTY( qreal majorTickLength READ majorTickLength WRITE setMajorTickLength ) | ||
Q_PROPERTY( qreal mediumTickLength READ mediumTickLength WRITE setMediumTickLength ) | ||
Q_PROPERTY( qreal minorTickLength READ minorTickLength WRITE setMinorTickLength ) | ||
|
||
public: | ||
using TickType = QskScaleTickmarks::TickType; | ||
|
||
constexpr QskGraduationMetrics() noexcept = default; | ||
constexpr QskGraduationMetrics( qreal minorTickLength, | ||
qreal mediumTickLength, qreal majorTickLength ) noexcept; | ||
constexpr QskGraduationMetrics( const QskGraduationMetrics& ) noexcept = default; | ||
constexpr QskGraduationMetrics( QskGraduationMetrics&& ) noexcept = default; | ||
|
||
constexpr QskGraduationMetrics& operator=( const QskGraduationMetrics& ) noexcept = default; | ||
constexpr QskGraduationMetrics& operator=( QskGraduationMetrics&& ) noexcept = default; | ||
|
||
[[nodiscard]] constexpr bool operator==( const QskGraduationMetrics& rhs ) const noexcept; | ||
[[nodiscard]] constexpr bool operator!=( const QskGraduationMetrics& rhs ) const noexcept; | ||
|
||
constexpr void setTickLength( TickType, qreal ) noexcept; | ||
[[nodiscard]] constexpr qreal tickLength( TickType ) const noexcept; | ||
|
||
constexpr void setMinorTickLength( qreal ) noexcept; | ||
[[nodiscard]] constexpr qreal minorTickLength() const noexcept; | ||
|
||
constexpr void setMediumTickLength( qreal ) noexcept; | ||
[[nodiscard]] constexpr qreal mediumTickLength() const noexcept; | ||
|
||
constexpr void setMajorTickLength( qreal ) noexcept; | ||
[[nodiscard]] constexpr qreal majorTickLength() const noexcept; | ||
|
||
[[nodiscard]] QskGraduationMetrics interpolated( | ||
const QskGraduationMetrics&, qreal progress ) const noexcept; | ||
|
||
[[nodiscard]] static QVariant interpolate( | ||
const QskGraduationMetrics&, const QskGraduationMetrics&, qreal progress ); | ||
|
||
[[nodiscard]] QskHashValue hash( QskHashValue seed = 0 ) const noexcept; | ||
|
||
private: | ||
static inline constexpr qreal constrainedLength( qreal length ) | ||
{ | ||
return std::max( 0.0, length ); | ||
} | ||
|
||
qreal m_tickLengths[3] = {}; | ||
}; | ||
|
||
inline constexpr QskGraduationMetrics::QskGraduationMetrics( | ||
qreal minorTickLength, qreal mediumTickLength, qreal majorTickLength ) noexcept | ||
: m_tickLengths{ constrainedLength( minorTickLength ), | ||
constrainedLength( mediumTickLength ), constrainedLength( majorTickLength ) } | ||
{ | ||
} | ||
|
||
inline constexpr qreal QskGraduationMetrics::majorTickLength() const noexcept | ||
{ | ||
return tickLength( QskScaleTickmarks::MajorTick ); | ||
} | ||
|
||
inline constexpr qreal QskGraduationMetrics::mediumTickLength() const noexcept | ||
{ | ||
return tickLength( QskScaleTickmarks::MediumTick ); | ||
} | ||
|
||
inline constexpr qreal QskGraduationMetrics::minorTickLength() const noexcept | ||
{ | ||
return tickLength( QskScaleTickmarks::MinorTick ); | ||
} | ||
|
||
inline constexpr void QskGraduationMetrics::setMajorTickLength( qreal length ) noexcept | ||
{ | ||
setTickLength( QskScaleTickmarks::MajorTick, length ); | ||
} | ||
|
||
inline constexpr void QskGraduationMetrics::setMediumTickLength( qreal length ) noexcept | ||
{ | ||
setTickLength( QskScaleTickmarks::MediumTick, length ); | ||
} | ||
|
||
inline constexpr void QskGraduationMetrics::setMinorTickLength( qreal length ) noexcept | ||
{ | ||
setTickLength( QskScaleTickmarks::MinorTick, length ); | ||
} | ||
|
||
inline constexpr bool QskGraduationMetrics::operator==( | ||
const QskGraduationMetrics& other ) const noexcept | ||
{ | ||
return qskFuzzyCompare( m_tickLengths[0], other.m_tickLengths[0] ) && | ||
qskFuzzyCompare( m_tickLengths[1], other.m_tickLengths[1] ) && | ||
qskFuzzyCompare( m_tickLengths[2], other.m_tickLengths[2] ); | ||
} | ||
|
||
inline constexpr bool QskGraduationMetrics::operator!=( | ||
const QskGraduationMetrics& rhs ) const noexcept | ||
{ | ||
return !( *this == rhs ); | ||
} | ||
|
||
inline constexpr qreal QskGraduationMetrics::tickLength( | ||
const QskScaleTickmarks::TickType type ) const noexcept | ||
{ | ||
return m_tickLengths[ type ]; | ||
} | ||
|
||
inline constexpr void QskGraduationMetrics::setTickLength( | ||
TickType type, qreal length ) noexcept | ||
{ | ||
m_tickLengths[ type ] = constrainedLength( length ); | ||
} | ||
|
||
inline QskHashValue QskGraduationMetrics::hash( const QskHashValue seed ) const noexcept | ||
{ | ||
auto hash = qHash( m_tickLengths[0], seed ); | ||
hash = qHash( m_tickLengths[1], hash ); | ||
hash = qHash( m_tickLengths[2], hash ); | ||
return hash; | ||
} | ||
|
||
#ifndef QT_NO_DEBUG_STREAM | ||
|
||
class QDebug; | ||
QSK_EXPORT QDebug operator<<( QDebug, const QskGraduationMetrics& ); | ||
|
||
#endif | ||
|
||
Q_DECLARE_TYPEINFO( QskGraduationMetrics, Q_MOVABLE_TYPE ); | ||
Q_DECLARE_METATYPE( QskGraduationMetrics ) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.