qskinny/src/common/QskGradientStop.h

107 lines
2.8 KiB
C
Raw Normal View History

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
*****************************************************************************/
#ifndef QSK_GRADIENT_STOP_H
#define QSK_GRADIENT_STOP_H
#include "QskGlobal.h"
#include <qcolor.h>
#include <qmetatype.h>
class QSK_EXPORT QskGradientStop
{
Q_GADGET
Q_PROPERTY( qreal position READ position WRITE setPosition RESET resetPosition )
Q_PROPERTY( QColor color READ color WRITE setColor RESET resetColor )
public:
2022-03-18 16:08:40 +01:00
constexpr QskGradientStop() noexcept;
constexpr QskGradientStop( qreal position, const QColor& ) noexcept;
QskGradientStop( qreal position, Qt::GlobalColor ) noexcept;
QskGradientStop( qreal position, QRgb ) noexcept;
2021-09-16 10:01:53 +02:00
2022-03-18 16:08:40 +01:00
constexpr bool operator==( const QskGradientStop& ) const noexcept;
constexpr bool operator!=( const QskGradientStop& ) const noexcept;
2021-09-16 10:01:53 +02:00
void setStop( qreal position, const QColor& ) noexcept;
2022-03-18 16:08:40 +01:00
constexpr qreal position() const noexcept;
2021-09-16 10:01:53 +02:00
void setPosition( qreal position ) noexcept;
void resetPosition() noexcept;
2022-03-18 16:08:40 +01:00
constexpr const QColor& color() const noexcept;
2021-10-27 15:07:17 +02:00
void setColor( const QColor& ) noexcept;
2021-09-16 10:01:53 +02:00
void resetColor() noexcept;
static QColor interpolated(
const QskGradientStop&, const QskGradientStop&, qreal position ) noexcept;
uint hash( uint seed ) const noexcept;
private:
qreal m_position;
QColor m_color; // using RGBA instead ?
};
Q_DECLARE_TYPEINFO( QskGradientStop, Q_MOVABLE_TYPE );
Q_DECLARE_METATYPE( QskGradientStop )
2022-03-18 16:08:40 +01:00
inline constexpr QskGradientStop::QskGradientStop() noexcept
2021-09-16 10:01:53 +02:00
: m_position( -1.0 )
{
}
2022-03-18 16:08:40 +01:00
inline constexpr QskGradientStop::QskGradientStop(
2021-09-16 10:01:53 +02:00
qreal position, const QColor& color ) noexcept
: m_position( position )
, m_color( color )
{
}
inline QskGradientStop::QskGradientStop(
qreal position, const Qt::GlobalColor color ) noexcept
: QskGradientStop( position, QColor( color ) )
{
}
inline QskGradientStop::QskGradientStop(
qreal position, QRgb rgb ) noexcept
: QskGradientStop( position, QColor::fromRgba( rgb ) )
{
}
2022-03-18 16:08:40 +01:00
inline constexpr qreal QskGradientStop::position() const noexcept
2021-09-16 10:01:53 +02:00
{
return m_position;
}
2022-03-18 16:08:40 +01:00
inline constexpr const QColor& QskGradientStop::color() const noexcept
2021-09-16 10:01:53 +02:00
{
return m_color;
}
2022-03-18 16:08:40 +01:00
inline constexpr bool QskGradientStop::operator==( const QskGradientStop& other ) const noexcept
2021-09-16 10:01:53 +02:00
{
return ( m_position == other.m_position ) && ( m_color == other.m_color );
}
2022-03-18 16:08:40 +01:00
inline constexpr bool QskGradientStop::operator!=( const QskGradientStop& other ) const noexcept
2021-09-16 10:01:53 +02:00
{
return ( !( *this == other ) );
}
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
QSK_EXPORT QDebug operator<<( QDebug, const QskGradientStop& );
#endif
#endif