QskGradientStops introduced

This commit is contained in:
Uwe Rathmann 2021-09-17 13:35:11 +02:00
parent 2219a6fe8e
commit 341d60e39b
5 changed files with 30 additions and 28 deletions

View File

@ -206,11 +206,11 @@ void QskQml::registerTypes()
// Support (lists of) GradientStop // Support (lists of) GradientStop
QMetaType::registerConverter< QJSValue, QskGradientStop >( qskToGradientStop ); QMetaType::registerConverter< QJSValue, QskGradientStop >( qskToGradientStop );
QMetaType::registerConverter< QJSValue, QVector< QskGradientStop > >( QMetaType::registerConverter< QJSValue, QskGradientStops >(
[]( const QJSValue& value ) []( const QJSValue& value )
{ {
QVector< QskGradientStop > stops; QskGradientStops stops;
if ( value.isArray() ) if ( value.isArray() )
{ {
QJSValueIterator it( value ); QJSValueIterator it( value );

View File

@ -27,7 +27,7 @@ static inline QskGradient::Orientation qskOrientation( Qt::Orientation o )
? QskGradient::Vertical : QskGradient::Horizontal; ? QskGradient::Vertical : QskGradient::Horizontal;
} }
static inline bool qskIsGradientValid( const QVector< QskGradientStop >& stops ) static inline bool qskIsGradientValid( const QskGradientStops& stops )
{ {
if ( stops.size() < 2 ) if ( stops.size() < 2 )
return false; return false;
@ -52,7 +52,7 @@ static inline bool qskIsGradientValid( const QVector< QskGradientStop >& stops )
return true; return true;
} }
static inline bool qskIsMonochrome( const QVector< QskGradientStop >& stops ) static inline bool qskIsMonochrome( const QskGradientStops& stops )
{ {
for ( int i = 1; i < stops.size(); i++ ) for ( int i = 1; i < stops.size(); i++ )
{ {
@ -74,7 +74,7 @@ static inline QColor qskInterpolated(
} }
static inline bool qskComparePositions( static inline bool qskComparePositions(
const QVector< QskGradientStop >& s1, const QVector< QskGradientStop >& s2 ) const QskGradientStops& s1, const QskGradientStops& s2 )
{ {
if ( s1.count() != s2.count() ) if ( s1.count() != s2.count() )
return false; return false;
@ -89,15 +89,15 @@ static inline bool qskComparePositions(
return true; return true;
} }
static inline QVector< QskGradientStop > qskExpandedStops( static inline QskGradientStops qskExpandedStops(
const QVector< QskGradientStop >& s1, const QVector< QskGradientStop >& s2 ) const QskGradientStops& s1, const QskGradientStops& s2 )
{ {
// expand s1 by stops matching to the positions from s2 // expand s1 by stops matching to the positions from s2
if ( qskComparePositions( s1, s2 ) ) if ( qskComparePositions( s1, s2 ) )
return s1; return s1;
QVector< QskGradientStop > stops; QskGradientStops stops;
stops += s1.first(); stops += s1.first();
@ -120,10 +120,10 @@ static inline QVector< QskGradientStop > qskExpandedStops(
return stops; return stops;
} }
static inline QVector< QskGradientStop > qskExtractedStops( static inline QskGradientStops qskExtractedStops(
const QVector< QskGradientStop >& stops, qreal from, qreal to ) const QskGradientStops& stops, qreal from, qreal to )
{ {
QVector< QskGradientStop > extracted; QskGradientStops extracted;
if ( from == to ) if ( from == to )
extracted.reserve( 2 ); extracted.reserve( 2 );
@ -192,13 +192,13 @@ QskGradient::QskGradient( Orientation orientation,
} }
QskGradient::QskGradient( Qt::Orientation orientation, QskGradient::QskGradient( Qt::Orientation orientation,
const QVector< QskGradientStop >& stops ) const QskGradientStops& stops )
: QskGradient( qskOrientation( orientation ), stops ) : QskGradient( qskOrientation( orientation ), stops )
{ {
} }
QskGradient::QskGradient( Orientation orientation, QskGradient::QskGradient( Orientation orientation,
const QVector< QskGradientStop >& stops ) const QskGradientStops& stops )
: m_orientation( orientation ) : m_orientation( orientation )
, m_stops( stops ) , m_stops( stops )
{ {
@ -272,7 +272,7 @@ void QskGradient::setColors( const QColor& startColor, const QColor& stopColor )
m_stops.append( QskGradientStop( 1.0, stopColor ) ); m_stops.append( QskGradientStop( 1.0, stopColor ) );
} }
void QskGradient::setStops( const QVector< QskGradientStop >& stops ) void QskGradient::setStops( const QskGradientStops& stops )
{ {
if ( !qskIsGradientValid( stops ) ) if ( !qskIsGradientValid( stops ) )
{ {
@ -284,7 +284,7 @@ void QskGradient::setStops( const QVector< QskGradientStop >& stops )
m_stops = stops; m_stops = stops;
} }
QVector< QskGradientStop > QskGradient::stops() const QskGradientStops QskGradient::stops() const
{ {
return m_stops; return m_stops;
} }

View File

@ -15,12 +15,14 @@
class QVariant; class QVariant;
typedef QVector< QskGradientStop > QskGradientStops;
class QSK_EXPORT QskGradient class QSK_EXPORT QskGradient
{ {
Q_GADGET Q_GADGET
Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
Q_PROPERTY( QVector< QskGradientStop > stops READ stops WRITE setStops ) Q_PROPERTY( QskGradientStops stops READ stops WRITE setStops )
Q_PROPERTY( bool valid READ isValid ) Q_PROPERTY( bool valid READ isValid )
Q_PROPERTY( bool visible READ isVisible ) Q_PROPERTY( bool visible READ isVisible )
@ -42,10 +44,10 @@ class QSK_EXPORT QskGradient
QskGradient( QRgb ); QskGradient( QRgb );
QskGradient( const QColor& ); QskGradient( const QColor& );
QskGradient( Qt::Orientation, const QVector< QskGradientStop >& ); QskGradient( Qt::Orientation, const QskGradientStops& );
QskGradient( Qt::Orientation, const QColor&, const QColor& ); QskGradient( Qt::Orientation, const QColor&, const QColor& );
QskGradient( Orientation, const QVector< QskGradientStop >& ); QskGradient( Orientation, const QskGradientStops& );
QskGradient( Orientation, const QColor&, const QColor& ); QskGradient( Orientation, const QColor&, const QColor& );
~QskGradient(); ~QskGradient();
@ -66,8 +68,8 @@ class QSK_EXPORT QskGradient
Q_INVOKABLE QColor startColor() const; Q_INVOKABLE QColor startColor() const;
Q_INVOKABLE QColor endColor() const; Q_INVOKABLE QColor endColor() const;
Q_INVOKABLE void setStops( const QVector< QskGradientStop >& ); Q_INVOKABLE void setStops( const QskGradientStops& );
Q_INVOKABLE QVector< QskGradientStop > stops() const; Q_INVOKABLE QskGradientStops stops() const;
Q_INVOKABLE bool hasStopAt( qreal value ) const; Q_INVOKABLE bool hasStopAt( qreal value ) const;
@ -98,7 +100,7 @@ class QSK_EXPORT QskGradient
void setColorAt( int index, const QColor& color ); void setColorAt( int index, const QColor& color );
Orientation m_orientation; Orientation m_orientation;
QVector< QskGradientStop > m_stops; QskGradientStops m_stops;
}; };
Q_DECLARE_METATYPE( QskGradient ) Q_DECLARE_METATYPE( QskGradient )

View File

@ -7,11 +7,11 @@
#define QSK_RGB_PALETTE_H #define QSK_RGB_PALETTE_H
#include "QskGlobal.h" #include "QskGlobal.h"
#include "QskGradient.h"
#include <qmetaobject.h> #include <qmetaobject.h>
#include <qcolor.h> #include <qcolor.h>
class QskGradientStop;
class QSK_EXPORT QskRgbPalette class QSK_EXPORT QskRgbPalette
{ {
Q_GADGET Q_GADGET
@ -75,11 +75,11 @@ class QSK_EXPORT QskRgbPalette
return QColor::fromRgba( rgb( weight ) ); return QColor::fromRgba( rgb( weight ) );
} }
QVector< QskGradientStop > colorStops( bool discrete = false ) const; QskGradientStops colorStops( bool discrete = false ) const;
static QVector< QskGradientStop > colorStops( Theme, bool discrete = false ); static QskGradientStops colorStops( Theme, bool discrete = false );
static QVector< QskGradientStop > colorStops( static QskGradientStops colorStops(
const QVector< QRgb >&, bool discrete = false ); const QVector< QRgb >&, bool discrete = false );
protected: protected:

View File

@ -148,7 +148,7 @@ namespace QskVertex
{ {
public: public:
inline GradientColorIterator( qreal value1, qreal value2, inline GradientColorIterator( qreal value1, qreal value2,
const QVector< QskGradientStop > stops ) const QskGradientStops& stops )
: m_value1( value1 ) : m_value1( value1 )
, m_value2( value2 ) , m_value2( value2 )
, m_stops( stops ) , m_stops( stops )
@ -207,7 +207,7 @@ namespace QskVertex
} }
const qreal m_value1, m_value2; const qreal m_value1, m_value2;
QVector< QskGradientStop > m_stops; const QskGradientStops m_stops;
int m_index; int m_index;
qreal m_valueStep1, m_valueStep2, m_stepSize; qreal m_valueStep1, m_valueStep2, m_stepSize;