2017-07-21 18:21:34 +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_H
|
|
|
|
#define QSK_GRADIENT_H
|
|
|
|
|
|
|
|
#include "QskGlobal.h"
|
2021-09-16 10:01:53 +02:00
|
|
|
#include "QskGradientStop.h"
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2022-03-18 16:50:34 +01:00
|
|
|
#include <qbrush.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <qmetatype.h>
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qvector.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
class QVariant;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2021-10-27 15:08:06 +02:00
|
|
|
/*
|
|
|
|
Don't use QskGradientStops for definitions seen by moc
|
|
|
|
Otherwise exporting these interfaces to QML does not work.
|
|
|
|
*/
|
2021-09-17 13:35:11 +02:00
|
|
|
typedef QVector< QskGradientStop > QskGradientStops;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
class QSK_EXPORT QskGradient
|
|
|
|
{
|
|
|
|
Q_GADGET
|
|
|
|
|
|
|
|
Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
|
2021-10-27 15:08:06 +02:00
|
|
|
Q_PROPERTY( QVector< QskGradientStop > stops READ stops WRITE setStops )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-05-10 08:09:48 +02:00
|
|
|
Q_PROPERTY( bool valid READ isValid )
|
|
|
|
Q_PROPERTY( bool visible READ isVisible )
|
|
|
|
Q_PROPERTY( bool monochrome READ isMonochrome )
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
// TODO: radial/canonical gradients + other diagonal linear gradients
|
|
|
|
enum Orientation
|
|
|
|
{
|
|
|
|
Horizontal,
|
|
|
|
Vertical,
|
|
|
|
Diagonal
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUM( Orientation )
|
|
|
|
|
|
|
|
QskGradient();
|
2022-01-21 07:29:07 +01:00
|
|
|
QskGradient( Orientation );
|
2017-10-17 17:34:00 +02:00
|
|
|
QskGradient( Qt::GlobalColor );
|
|
|
|
QskGradient( QRgb );
|
2017-07-21 18:21:34 +02:00
|
|
|
QskGradient( const QColor& );
|
2022-03-18 16:50:34 +01:00
|
|
|
QskGradient( QGradient::Preset );
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2021-10-27 15:08:06 +02:00
|
|
|
QskGradient( Qt::Orientation, const QVector< QskGradientStop >& );
|
2020-07-31 12:42:36 +02:00
|
|
|
QskGradient( Qt::Orientation, const QColor&, const QColor& );
|
|
|
|
|
2021-10-27 15:08:06 +02:00
|
|
|
QskGradient( Orientation, const QVector< QskGradientStop >& );
|
2017-07-21 18:21:34 +02:00
|
|
|
QskGradient( Orientation, const QColor&, const QColor& );
|
2022-03-18 16:50:34 +01:00
|
|
|
QskGradient( Orientation, QGradient::Preset );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
~QskGradient();
|
|
|
|
|
2020-07-31 12:42:36 +02:00
|
|
|
void setOrientation( Qt::Orientation );
|
2017-07-21 18:21:34 +02:00
|
|
|
void setOrientation( Orientation );
|
|
|
|
Orientation orientation() const;
|
|
|
|
|
|
|
|
bool isValid() const;
|
2020-07-31 12:42:36 +02:00
|
|
|
Q_INVOKABLE void invalidate();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
bool operator==( const QskGradient& ) const;
|
|
|
|
bool operator!=( const QskGradient& ) const;
|
|
|
|
|
|
|
|
void setColor( const QColor& );
|
|
|
|
void setColors( const QColor&, const QColor& );
|
|
|
|
|
2020-07-31 12:42:36 +02:00
|
|
|
Q_INVOKABLE QColor startColor() const;
|
|
|
|
Q_INVOKABLE QColor endColor() const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2021-10-27 15:08:06 +02:00
|
|
|
Q_INVOKABLE void setStops( const QVector< QskGradientStop >& );
|
2022-03-24 10:39:33 +01:00
|
|
|
Q_INVOKABLE const QVector< QskGradientStop >& stops() const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-07-31 12:42:36 +02:00
|
|
|
Q_INVOKABLE bool hasStopAt( qreal value ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
|
|
|
void setAlpha( int alpha );
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
bool isMonochrome() const;
|
|
|
|
bool isVisible() const;
|
|
|
|
|
2020-07-31 12:42:36 +02:00
|
|
|
void reverse();
|
|
|
|
QskGradient reversed() const;
|
|
|
|
|
|
|
|
// all stops between [from, to] with positions streched into [0,1]
|
|
|
|
QskGradient extracted( qreal from, qreal start ) const;
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QskGradient interpolated( const QskGradient&, qreal value ) const;
|
|
|
|
|
|
|
|
static QVariant interpolate( const QskGradient&,
|
|
|
|
const QskGradient&, qreal progress );
|
|
|
|
|
2022-03-25 10:28:06 +01:00
|
|
|
QskHashValue hash( QskHashValue seed ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-07-31 12:42:36 +02:00
|
|
|
Q_INVOKABLE qreal stopAt( int index ) const;
|
|
|
|
Q_INVOKABLE QColor colorAt( int index ) const;
|
2021-02-19 12:42:05 +01:00
|
|
|
Q_INVOKABLE int stopCount() const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-04-18 16:11:05 +02:00
|
|
|
private:
|
|
|
|
void setStopAt( int index, qreal stop );
|
2017-07-21 18:21:34 +02:00
|
|
|
void setColorAt( int index, const QColor& color );
|
|
|
|
|
2022-01-21 07:29:07 +01:00
|
|
|
void updateStatusBits() const;
|
|
|
|
|
2021-10-27 15:08:06 +02:00
|
|
|
QVector< QskGradientStop > m_stops;
|
2022-01-21 07:29:07 +01:00
|
|
|
|
|
|
|
int m_orientation : 4;
|
|
|
|
|
|
|
|
mutable bool m_isDirty : 1;
|
|
|
|
mutable bool m_isValid : 1;
|
|
|
|
mutable bool m_isMonchrome : 1;
|
|
|
|
mutable bool m_isVisible : 1;
|
2017-07-21 18:21:34 +02:00
|
|
|
};
|
|
|
|
|
2021-09-16 10:01:53 +02:00
|
|
|
Q_DECLARE_METATYPE( QskGradient )
|
|
|
|
|
2022-01-21 07:29:07 +01:00
|
|
|
inline QskGradient::QskGradient()
|
|
|
|
: QskGradient( Vertical )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
inline QskGradient::QskGradient( Qt::GlobalColor color )
|
|
|
|
: QskGradient( QColor( color ) )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
inline QskGradient::QskGradient( QRgb rgb )
|
|
|
|
: QskGradient( QColor::fromRgba( rgb ) )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-18 16:50:34 +01:00
|
|
|
inline QskGradient::QskGradient( QGradient::Preset preset )
|
|
|
|
: QskGradient( Vertical, preset )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-21 07:29:07 +01:00
|
|
|
inline QskGradient::Orientation QskGradient::orientation() const
|
|
|
|
{
|
|
|
|
return static_cast< Orientation >( m_orientation );
|
|
|
|
}
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
inline QColor QskGradient::startColor() const
|
|
|
|
{
|
|
|
|
return ( m_stops.size() >= 2 ) ? m_stops.first().color() : QColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QColor QskGradient::endColor() const
|
|
|
|
{
|
|
|
|
return ( m_stops.size() >= 2 ) ? m_stops.last().color() : QColor();
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
inline bool QskGradient::operator==( const QskGradient& other ) const
|
|
|
|
{
|
|
|
|
return ( m_orientation == other.m_orientation ) && ( m_stops == other.m_stops );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool QskGradient::operator!=( const QskGradient& other ) const
|
|
|
|
{
|
|
|
|
return ( !( *this == other ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
|
2021-09-16 10:01:53 +02:00
|
|
|
class QDebug;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_EXPORT QDebug operator<<( QDebug, const QskGradient& );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|