qskinny/src/common/QskGradientStop.h

154 lines
4.5 KiB
C
Raw Normal View History

2021-09-16 08:01:53 +00: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>
#include <qvector.h>
2021-09-16 08:01:53 +00:00
2022-10-24 14:40:47 +00:00
typedef QPair< qreal, QColor > QGradientStop;
2021-09-16 08:01:53 +00:00
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-11-14 07:56:30 +00:00
constexpr QskGradientStop() noexcept = default;
2022-03-18 15:08:40 +00:00
constexpr QskGradientStop( qreal position, const QColor& ) noexcept;
2022-10-24 14:40:47 +00:00
constexpr QskGradientStop( const QGradientStop& ) noexcept;
2022-03-18 15:08:40 +00:00
QskGradientStop( qreal position, Qt::GlobalColor ) noexcept;
QskGradientStop( qreal position, QRgb ) noexcept;
2021-09-16 08:01:53 +00:00
2022-03-18 15:08:40 +00:00
constexpr bool operator==( const QskGradientStop& ) const noexcept;
constexpr bool operator!=( const QskGradientStop& ) const noexcept;
2021-09-16 08:01:53 +00:00
void setStop( qreal position, const QColor& ) noexcept;
void setStop( qreal position, Qt::GlobalColor ) noexcept;
2022-11-14 07:56:30 +00:00
void setStop( qreal position, QRgb ) noexcept;
2021-09-16 08:01:53 +00:00
2022-03-18 15:08:40 +00:00
constexpr qreal position() const noexcept;
2021-09-16 08:01:53 +00:00
void setPosition( qreal position ) noexcept;
void resetPosition() noexcept;
2022-03-18 15:08:40 +00:00
constexpr const QColor& color() const noexcept;
2021-10-27 13:07:17 +00:00
void setColor( const QColor& ) noexcept;
2021-09-16 08:01:53 +00:00
void resetColor() noexcept;
2022-11-14 07:56:30 +00:00
void setRgb( QRgb ) noexcept;
QRgb rgb() const noexcept;
2021-09-16 08:01:53 +00:00
static QColor interpolated(
const QskGradientStop&, const QskGradientStop&, qreal position ) noexcept;
QskHashValue hash( QskHashValue seed ) const noexcept;
2021-09-16 08:01:53 +00:00
private:
2022-11-14 07:56:30 +00:00
qreal m_position = -1.0;
QColor m_color; // using QRgb instead ?
2021-09-16 08:01:53 +00:00
};
2022-04-03 14:25:13 +00:00
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
Q_DECLARE_TYPEINFO( QskGradientStop, Q_RELOCATABLE_TYPE );
#endif
2021-09-16 08:01:53 +00:00
Q_DECLARE_METATYPE( QskGradientStop )
2022-03-18 15:08:40 +00:00
inline constexpr QskGradientStop::QskGradientStop(
2021-09-16 08:01:53 +00: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-10-24 14:40:47 +00:00
inline constexpr QskGradientStop::QskGradientStop( const QGradientStop& qtStop ) noexcept
: QskGradientStop( qtStop.first, qtStop.second )
{
}
2022-03-18 15:08:40 +00:00
inline constexpr qreal QskGradientStop::position() const noexcept
2021-09-16 08:01:53 +00:00
{
return m_position;
}
2022-03-18 15:08:40 +00:00
inline constexpr const QColor& QskGradientStop::color() const noexcept
2021-09-16 08:01:53 +00:00
{
return m_color;
}
inline QRgb QskGradientStop::rgb() const noexcept
{
return m_color.rgba();
}
2022-03-18 15:08:40 +00:00
inline constexpr bool QskGradientStop::operator==( const QskGradientStop& other ) const noexcept
2021-09-16 08:01:53 +00:00
{
return ( m_position == other.m_position ) && ( m_color == other.m_color );
}
2022-03-18 15:08:40 +00:00
inline constexpr bool QskGradientStop::operator!=( const QskGradientStop& other ) const noexcept
2021-09-16 08:01:53 +00:00
{
return ( !( *this == other ) );
}
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
QSK_EXPORT QDebug operator<<( QDebug, const QskGradientStop& );
#endif
2022-10-24 14:40:47 +00:00
typedef QVector< QskGradientStop > QskGradientStops;
QSK_EXPORT bool qskIsMonochrome( const QskGradientStops& ) noexcept;
QSK_EXPORT bool qskIsVisible( const QskGradientStops& ) noexcept;
2022-10-24 15:08:48 +00:00
QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
const QskGradientStops&, bool, const QskGradientStops&, bool,
qreal ratio );
QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
const QskGradientStops&, const QColor&, qreal ratio );
QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
const QColor&, const QskGradientStops&, qreal ratio );
QSK_EXPORT QskGradientStops qskTransparentGradientStops(
const QskGradientStops&, qreal ratio );
QSK_EXPORT QskGradientStops qskExtractedGradientStops(
const QskGradientStops&, qreal from, qreal to );
2022-10-24 14:40:47 +00:00
QSK_EXPORT QskGradientStops qskBuildGradientStops(
const QVector< QRgb >&, bool discrete = false );
QSK_EXPORT QskGradientStops qskBuildGradientStops(
const QVector< QColor >&, bool discrete = false );
QSK_EXPORT QskGradientStops qskBuildGradientStops( const QVector< QGradientStop >& );
QSK_EXPORT QVector< QGradientStop > qskToQGradientStops( const QVector< QskGradientStop >& );
2021-09-16 08:01:53 +00:00
#endif