2021-09-16 10:01:53 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2021-10-27 15:07:17 +02:00
|
|
|
#include "QskGradientStop.h"
|
2021-09-16 10:01:53 +02:00
|
|
|
#include "QskRgbValue.h"
|
|
|
|
|
|
|
|
#include <qhashfunctions.h>
|
|
|
|
#include <qvariant.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
static void qskRegisterGradientStop()
|
|
|
|
{
|
|
|
|
qRegisterMetaType< QskGradientStop >();
|
2022-03-30 18:30:22 +02:00
|
|
|
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
|
|
|
QMetaType::registerEqualsComparator< QskGradientStop >();
|
|
|
|
#endif
|
2021-09-16 10:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_CONSTRUCTOR_FUNCTION( qskRegisterGradientStop )
|
|
|
|
|
|
|
|
void QskGradientStop::setPosition( qreal position ) noexcept
|
|
|
|
{
|
|
|
|
m_position = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGradientStop::resetPosition() noexcept
|
|
|
|
{
|
|
|
|
m_position = -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGradientStop::setColor( const QColor& color ) noexcept
|
|
|
|
{
|
|
|
|
m_color = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGradientStop::resetColor() noexcept
|
|
|
|
{
|
|
|
|
m_color = QColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGradientStop::setStop( qreal position, const QColor& color ) noexcept
|
|
|
|
{
|
|
|
|
m_position = position;
|
|
|
|
m_color = color;
|
|
|
|
}
|
|
|
|
|
2022-03-25 10:28:06 +01:00
|
|
|
QskHashValue QskGradientStop::hash( QskHashValue seed ) const noexcept
|
2021-09-16 10:01:53 +02:00
|
|
|
{
|
2022-03-25 10:28:06 +01:00
|
|
|
auto hash = qHashBits( &m_position, sizeof( m_position ), seed );
|
2021-09-16 10:01:53 +02:00
|
|
|
return qHashBits( &m_color, sizeof( m_color ), hash );
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor QskGradientStop::interpolated(
|
|
|
|
const QskGradientStop& s1, const QskGradientStop& s2, qreal position ) noexcept
|
|
|
|
{
|
|
|
|
if ( s1.color() == s2.color() )
|
|
|
|
return s1.color();
|
|
|
|
|
|
|
|
auto min = &s1;
|
|
|
|
auto max = &s2;
|
|
|
|
|
|
|
|
if ( min->position() > max->position() )
|
|
|
|
std::swap( min, max );
|
|
|
|
|
|
|
|
if ( position <= min->position() )
|
|
|
|
return min->color();
|
|
|
|
|
|
|
|
if ( position >= max->position() )
|
|
|
|
return max->color();
|
|
|
|
|
|
|
|
const qreal r = ( position - min->position() ) / ( max->position() - min->position() );
|
|
|
|
return QskRgb::interpolated( min->color(), max->color(), r );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
|
|
|
|
#include <qdebug.h>
|
|
|
|
|
|
|
|
QDebug operator<<( QDebug debug, const QskGradientStop& stop )
|
|
|
|
{
|
2022-03-30 12:28:45 +02:00
|
|
|
QDebugStateSaver saver( debug );
|
|
|
|
debug.nospace();
|
|
|
|
|
|
|
|
debug << stop.position() << ": ";
|
|
|
|
QskRgb::debugColor( debug, stop.color() );
|
|
|
|
|
2021-09-16 10:01:53 +02:00
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "moc_QskGradientStop.cpp"
|