improving Qml support or QskGradient
This commit is contained in:
parent
47fad1be18
commit
bbfc16c609
|
@ -136,7 +136,7 @@ namespace
|
|||
stops += QskGradientStop( 1.0, Qt::darkCyan );
|
||||
|
||||
QskGradient gradient( stops );
|
||||
gradient.setRadialDirection();
|
||||
gradient.setDirection( QskGradient::Radial );
|
||||
gradient.setSpread( QGradient::PadSpread );
|
||||
|
||||
shapeItem->setGradient( gradient );
|
||||
|
@ -148,7 +148,7 @@ namespace
|
|||
shapeItem->setPen( pen( QskRgb::Indigo ) );
|
||||
|
||||
QskGradient gradient( QGradient::LilyMeadow );
|
||||
gradient.setRadialDirection( QskRadialDirection( 0.5, 0.7, 0.25 ) );
|
||||
gradient.setRadialDirection( 0.5, 0.7, 0.25 );
|
||||
gradient.setSpread( QGradient::RepeatSpread );
|
||||
|
||||
shapeItem->setGradient( gradient );
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <QskDialogWindow.h>
|
||||
#include <QskFocusIndicator.h>
|
||||
#include <QskGradient.h>
|
||||
#include <QskGradientDirection.h>
|
||||
#include <QskGraphicLabel.h>
|
||||
#include <QskIntervalF.h>
|
||||
#include <QskLayoutMetrics.h>
|
||||
|
@ -252,9 +253,13 @@ void QskQml::registerTypes()
|
|||
registerGadget< QskLayoutMetrics >();
|
||||
registerGadget< QskMargins >();
|
||||
|
||||
registerGadget< QskAspect >();
|
||||
registerGadget< QskGradient >();
|
||||
registerGadget< QskGradientStop >();
|
||||
registerGadget< QskLinearDirection >();
|
||||
registerGadget< QskConicDirection >();
|
||||
registerGadget< QskRadialDirection >();
|
||||
|
||||
registerGadget< QskAspect >();
|
||||
registerGadget< QskPlacementPolicy >();
|
||||
registerGadget< QskSizePolicy >();
|
||||
registerGadget< QskTextOptions >();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "QskGradient.h"
|
||||
#include "QskRgbValue.h"
|
||||
#include "QskGradientDirection.h"
|
||||
#include "QskFunctions.h"
|
||||
|
||||
#include <qvariant.h>
|
||||
|
||||
|
@ -137,6 +138,34 @@ void QskGradient::updateStatusBits() const
|
|||
m_isVisible = false;
|
||||
}
|
||||
|
||||
if ( m_isVisible )
|
||||
{
|
||||
switch( m_type )
|
||||
{
|
||||
case Linear:
|
||||
{
|
||||
m_isVisible = !( qskFuzzyCompare( m_values[0], m_values[2] )
|
||||
&& qskFuzzyCompare( m_values[1], m_values[3] ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case Radial:
|
||||
{
|
||||
m_isVisible = m_values[2] > 0.0; // radius
|
||||
break;
|
||||
}
|
||||
|
||||
case Conic:
|
||||
{
|
||||
m_isVisible = !qFuzzyIsNull( m_values[3] ); // spanAngle
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_isDirty = false;
|
||||
}
|
||||
|
||||
|
@ -417,11 +446,6 @@ QskLinearDirection QskGradient::linearDirection() const
|
|||
return QskLinearDirection( m_values[0], m_values[1], m_values[2], m_values[3] );
|
||||
}
|
||||
|
||||
void QskGradient::setRadialDirection()
|
||||
{
|
||||
setRadialDirection( QskRadialDirection() );
|
||||
}
|
||||
|
||||
void QskGradient::setRadialDirection( const qreal x, qreal y, qreal radius )
|
||||
{
|
||||
setRadialDirection( QskRadialDirection( x, y, radius ) );
|
||||
|
@ -478,6 +502,31 @@ QskConicDirection QskGradient::conicDirection() const
|
|||
return QskConicDirection( m_values[0], m_values[1], m_values[2], m_values[3] );
|
||||
}
|
||||
|
||||
void QskGradient::setDirection( Type type )
|
||||
{
|
||||
if ( type == m_type )
|
||||
return;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case Linear:
|
||||
setLinearDirection( QskLinearDirection() );
|
||||
break;
|
||||
|
||||
case Radial:
|
||||
setRadialDirection( QskRadialDirection() );
|
||||
break;
|
||||
|
||||
case Conic:
|
||||
setConicDirection( QskConicDirection() );
|
||||
break;
|
||||
|
||||
case Stops:
|
||||
resetDirection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QskGradient::resetDirection()
|
||||
{
|
||||
m_type = Stops;
|
||||
|
|
|
@ -74,8 +74,6 @@ class QSK_EXPORT QskGradient
|
|||
|
||||
void setRadialDirection( const QskRadialDirection& );
|
||||
void setRadialDirection( const qreal x, qreal y, qreal radius );
|
||||
void setRadialDirection();
|
||||
|
||||
QskRadialDirection radialDirection() const;
|
||||
|
||||
void setConicDirection( qreal, qreal );
|
||||
|
@ -83,6 +81,7 @@ class QSK_EXPORT QskGradient
|
|||
void setConicDirection( const QskConicDirection& );
|
||||
QskConicDirection conicDirection() const;
|
||||
|
||||
void setDirection( Type );
|
||||
void resetDirection();
|
||||
|
||||
bool isValid() const noexcept;
|
||||
|
@ -138,18 +137,14 @@ class QSK_EXPORT QskGradient
|
|||
private:
|
||||
|
||||
#if 1
|
||||
/*
|
||||
Couldn't find a way how to assign a struct to another struct
|
||||
that is used as proprty from QML without creating extra QObjects.
|
||||
So for the moment we are using lists, that are more
|
||||
error prone and less intuitive.
|
||||
|
||||
Maybe we can do something better using qmlRegisterCustomType, where we
|
||||
can register our own QQmlCustomParser. TODO ...
|
||||
*/
|
||||
Q_PROPERTY( QVector< qreal > linear READ linearAsList WRITE setLinearAsList )
|
||||
Q_PROPERTY( QVector< qreal > conic READ conicAsList WRITE setConicAsList )
|
||||
Q_PROPERTY( QVector< qreal > radial READ radialAsList WRITE setRadialAsList )
|
||||
#else
|
||||
Q_PROPERTY( QskLinearDirection linear READ linearDirection WRITE setLinearDirection )
|
||||
Q_PROPERTY( QskConicDirection conic READ conicDirection WRITE setConicDirection )
|
||||
Q_PROPERTY( QskRadialDirection radial READ radialDirection WRITE setRadialDirection )
|
||||
#endif
|
||||
|
||||
QVector< qreal > linearAsList() const;
|
||||
void setLinearAsList( const QVector< qreal >& );
|
||||
|
@ -159,7 +154,6 @@ class QSK_EXPORT QskGradient
|
|||
|
||||
QVector< qreal > conicAsList() const;
|
||||
void setConicAsList( const QVector< qreal >& );
|
||||
#endif
|
||||
|
||||
private:
|
||||
QVector< QskGradientStop > m_stops;
|
||||
|
|
|
@ -5,6 +5,15 @@
|
|||
|
||||
#include "QskGradientDirection.h"
|
||||
|
||||
static void qskRegisterGradientDirection()
|
||||
{
|
||||
qRegisterMetaType< QskLinearDirection >();
|
||||
qRegisterMetaType< QskConicDirection >();
|
||||
qRegisterMetaType< QskRadialDirection >();
|
||||
}
|
||||
|
||||
Q_CONSTRUCTOR_FUNCTION( qskRegisterGradientDirection )
|
||||
|
||||
// -- QskLinearDirection
|
||||
|
||||
void QskLinearDirection::setOrientation( Qt::Orientation orientation ) noexcept
|
||||
|
@ -89,6 +98,16 @@ void QskConicDirection::setCenter( qreal x, qreal y ) noexcept
|
|||
m_y = y;
|
||||
}
|
||||
|
||||
void QskConicDirection::setX( qreal x ) noexcept
|
||||
{
|
||||
m_x = x;
|
||||
}
|
||||
|
||||
void QskConicDirection::setY( qreal y ) noexcept
|
||||
{
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
void QskConicDirection::setStartAngle( qreal degrees ) noexcept
|
||||
{
|
||||
m_startAngle = degrees;
|
||||
|
@ -113,6 +132,16 @@ void QskRadialDirection::setCenter( qreal x, qreal y ) noexcept
|
|||
m_y = y;
|
||||
}
|
||||
|
||||
void QskRadialDirection::setX( qreal x ) noexcept
|
||||
{
|
||||
m_x = x;
|
||||
}
|
||||
|
||||
void QskRadialDirection::setY( qreal y ) noexcept
|
||||
{
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
void QskRadialDirection::setRadius( qreal radius ) noexcept
|
||||
{
|
||||
m_radius = radius;
|
||||
|
|
|
@ -69,7 +69,8 @@ class QSK_EXPORT QskConicDirection
|
|||
{
|
||||
Q_GADGET
|
||||
|
||||
Q_PROPERTY( QPointF center READ center WRITE setCenter )
|
||||
Q_PROPERTY( qreal x READ x WRITE setX )
|
||||
Q_PROPERTY( qreal y READ y WRITE setY )
|
||||
Q_PROPERTY( qreal startAngle READ startAngle WRITE setStartAngle )
|
||||
Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle )
|
||||
|
||||
|
@ -87,6 +88,12 @@ class QSK_EXPORT QskConicDirection
|
|||
void setCenter(const QPointF& center) noexcept;
|
||||
void setCenter(qreal x, qreal y) noexcept;
|
||||
|
||||
void setX( qreal ) noexcept;
|
||||
constexpr qreal x() const noexcept;
|
||||
|
||||
void setY( qreal ) noexcept;
|
||||
constexpr qreal y() const noexcept;
|
||||
|
||||
constexpr qreal startAngle() const noexcept;
|
||||
void setStartAngle( qreal ) noexcept;
|
||||
|
||||
|
@ -104,7 +111,8 @@ class QSK_EXPORT QskRadialDirection
|
|||
{
|
||||
Q_GADGET
|
||||
|
||||
Q_PROPERTY( QPointF center READ center WRITE setCenter )
|
||||
Q_PROPERTY( qreal x READ x WRITE setX )
|
||||
Q_PROPERTY( qreal y READ y WRITE setY )
|
||||
Q_PROPERTY( qreal radius READ radius WRITE setRadius )
|
||||
|
||||
public:
|
||||
|
@ -117,6 +125,12 @@ class QSK_EXPORT QskRadialDirection
|
|||
void setCenter(const QPointF& center) noexcept;
|
||||
void setCenter(qreal x, qreal y) noexcept;
|
||||
|
||||
void setX( qreal ) noexcept;
|
||||
constexpr qreal x() const noexcept;
|
||||
|
||||
void setY( qreal ) noexcept;
|
||||
constexpr qreal y() const noexcept;
|
||||
|
||||
constexpr qreal radius() const noexcept;
|
||||
void setRadius( qreal radius ) noexcept;
|
||||
|
||||
|
@ -242,6 +256,16 @@ inline constexpr qreal QskConicDirection::spanAngle() const noexcept
|
|||
return m_spanAngle;
|
||||
}
|
||||
|
||||
inline constexpr qreal QskConicDirection::x() const noexcept
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
inline constexpr qreal QskConicDirection::y() const noexcept
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
inline constexpr QskRadialDirection::QskRadialDirection(
|
||||
qreal x, qreal y, qreal radius ) noexcept
|
||||
: m_x( x )
|
||||
|
@ -261,6 +285,16 @@ inline constexpr QPointF QskRadialDirection::center() const noexcept
|
|||
return QPointF( m_x, m_y );
|
||||
}
|
||||
|
||||
inline constexpr qreal QskRadialDirection::x() const noexcept
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
inline constexpr qreal QskRadialDirection::y() const noexcept
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
inline constexpr qreal QskRadialDirection::radius() const noexcept
|
||||
{
|
||||
return m_radius;
|
||||
|
|
Loading…
Reference in New Issue