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 );
|
stops += QskGradientStop( 1.0, Qt::darkCyan );
|
||||||
|
|
||||||
QskGradient gradient( stops );
|
QskGradient gradient( stops );
|
||||||
gradient.setRadialDirection();
|
gradient.setDirection( QskGradient::Radial );
|
||||||
gradient.setSpread( QGradient::PadSpread );
|
gradient.setSpread( QGradient::PadSpread );
|
||||||
|
|
||||||
shapeItem->setGradient( gradient );
|
shapeItem->setGradient( gradient );
|
||||||
|
@ -148,7 +148,7 @@ namespace
|
||||||
shapeItem->setPen( pen( QskRgb::Indigo ) );
|
shapeItem->setPen( pen( QskRgb::Indigo ) );
|
||||||
|
|
||||||
QskGradient gradient( QGradient::LilyMeadow );
|
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 );
|
gradient.setSpread( QGradient::RepeatSpread );
|
||||||
|
|
||||||
shapeItem->setGradient( gradient );
|
shapeItem->setGradient( gradient );
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <QskDialogWindow.h>
|
#include <QskDialogWindow.h>
|
||||||
#include <QskFocusIndicator.h>
|
#include <QskFocusIndicator.h>
|
||||||
#include <QskGradient.h>
|
#include <QskGradient.h>
|
||||||
|
#include <QskGradientDirection.h>
|
||||||
#include <QskGraphicLabel.h>
|
#include <QskGraphicLabel.h>
|
||||||
#include <QskIntervalF.h>
|
#include <QskIntervalF.h>
|
||||||
#include <QskLayoutMetrics.h>
|
#include <QskLayoutMetrics.h>
|
||||||
|
@ -252,9 +253,13 @@ void QskQml::registerTypes()
|
||||||
registerGadget< QskLayoutMetrics >();
|
registerGadget< QskLayoutMetrics >();
|
||||||
registerGadget< QskMargins >();
|
registerGadget< QskMargins >();
|
||||||
|
|
||||||
registerGadget< QskAspect >();
|
|
||||||
registerGadget< QskGradient >();
|
registerGadget< QskGradient >();
|
||||||
registerGadget< QskGradientStop >();
|
registerGadget< QskGradientStop >();
|
||||||
|
registerGadget< QskLinearDirection >();
|
||||||
|
registerGadget< QskConicDirection >();
|
||||||
|
registerGadget< QskRadialDirection >();
|
||||||
|
|
||||||
|
registerGadget< QskAspect >();
|
||||||
registerGadget< QskPlacementPolicy >();
|
registerGadget< QskPlacementPolicy >();
|
||||||
registerGadget< QskSizePolicy >();
|
registerGadget< QskSizePolicy >();
|
||||||
registerGadget< QskTextOptions >();
|
registerGadget< QskTextOptions >();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "QskGradient.h"
|
#include "QskGradient.h"
|
||||||
#include "QskRgbValue.h"
|
#include "QskRgbValue.h"
|
||||||
#include "QskGradientDirection.h"
|
#include "QskGradientDirection.h"
|
||||||
|
#include "QskFunctions.h"
|
||||||
|
|
||||||
#include <qvariant.h>
|
#include <qvariant.h>
|
||||||
|
|
||||||
|
@ -137,6 +138,34 @@ void QskGradient::updateStatusBits() const
|
||||||
m_isVisible = false;
|
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;
|
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] );
|
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 )
|
void QskGradient::setRadialDirection( const qreal x, qreal y, qreal radius )
|
||||||
{
|
{
|
||||||
setRadialDirection( QskRadialDirection( x, y, 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] );
|
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()
|
void QskGradient::resetDirection()
|
||||||
{
|
{
|
||||||
m_type = Stops;
|
m_type = Stops;
|
||||||
|
|
|
@ -74,8 +74,6 @@ class QSK_EXPORT QskGradient
|
||||||
|
|
||||||
void setRadialDirection( const QskRadialDirection& );
|
void setRadialDirection( const QskRadialDirection& );
|
||||||
void setRadialDirection( const qreal x, qreal y, qreal radius );
|
void setRadialDirection( const qreal x, qreal y, qreal radius );
|
||||||
void setRadialDirection();
|
|
||||||
|
|
||||||
QskRadialDirection radialDirection() const;
|
QskRadialDirection radialDirection() const;
|
||||||
|
|
||||||
void setConicDirection( qreal, qreal );
|
void setConicDirection( qreal, qreal );
|
||||||
|
@ -83,6 +81,7 @@ class QSK_EXPORT QskGradient
|
||||||
void setConicDirection( const QskConicDirection& );
|
void setConicDirection( const QskConicDirection& );
|
||||||
QskConicDirection conicDirection() const;
|
QskConicDirection conicDirection() const;
|
||||||
|
|
||||||
|
void setDirection( Type );
|
||||||
void resetDirection();
|
void resetDirection();
|
||||||
|
|
||||||
bool isValid() const noexcept;
|
bool isValid() const noexcept;
|
||||||
|
@ -138,18 +137,14 @@ class QSK_EXPORT QskGradient
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#if 1
|
#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 > linear READ linearAsList WRITE setLinearAsList )
|
||||||
Q_PROPERTY( QVector< qreal > conic READ conicAsList WRITE setConicAsList )
|
Q_PROPERTY( QVector< qreal > conic READ conicAsList WRITE setConicAsList )
|
||||||
Q_PROPERTY( QVector< qreal > radial READ radialAsList WRITE setRadialAsList )
|
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;
|
QVector< qreal > linearAsList() const;
|
||||||
void setLinearAsList( const QVector< qreal >& );
|
void setLinearAsList( const QVector< qreal >& );
|
||||||
|
@ -159,7 +154,6 @@ class QSK_EXPORT QskGradient
|
||||||
|
|
||||||
QVector< qreal > conicAsList() const;
|
QVector< qreal > conicAsList() const;
|
||||||
void setConicAsList( const QVector< qreal >& );
|
void setConicAsList( const QVector< qreal >& );
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector< QskGradientStop > m_stops;
|
QVector< QskGradientStop > m_stops;
|
||||||
|
|
|
@ -5,6 +5,15 @@
|
||||||
|
|
||||||
#include "QskGradientDirection.h"
|
#include "QskGradientDirection.h"
|
||||||
|
|
||||||
|
static void qskRegisterGradientDirection()
|
||||||
|
{
|
||||||
|
qRegisterMetaType< QskLinearDirection >();
|
||||||
|
qRegisterMetaType< QskConicDirection >();
|
||||||
|
qRegisterMetaType< QskRadialDirection >();
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_CONSTRUCTOR_FUNCTION( qskRegisterGradientDirection )
|
||||||
|
|
||||||
// -- QskLinearDirection
|
// -- QskLinearDirection
|
||||||
|
|
||||||
void QskLinearDirection::setOrientation( Qt::Orientation orientation ) noexcept
|
void QskLinearDirection::setOrientation( Qt::Orientation orientation ) noexcept
|
||||||
|
@ -89,6 +98,16 @@ void QskConicDirection::setCenter( qreal x, qreal y ) noexcept
|
||||||
m_y = y;
|
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
|
void QskConicDirection::setStartAngle( qreal degrees ) noexcept
|
||||||
{
|
{
|
||||||
m_startAngle = degrees;
|
m_startAngle = degrees;
|
||||||
|
@ -113,6 +132,16 @@ void QskRadialDirection::setCenter( qreal x, qreal y ) noexcept
|
||||||
m_y = y;
|
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
|
void QskRadialDirection::setRadius( qreal radius ) noexcept
|
||||||
{
|
{
|
||||||
m_radius = radius;
|
m_radius = radius;
|
||||||
|
|
|
@ -69,7 +69,8 @@ class QSK_EXPORT QskConicDirection
|
||||||
{
|
{
|
||||||
Q_GADGET
|
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 startAngle READ startAngle WRITE setStartAngle )
|
||||||
Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle )
|
Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle )
|
||||||
|
|
||||||
|
@ -87,6 +88,12 @@ class QSK_EXPORT QskConicDirection
|
||||||
void setCenter(const QPointF& center) noexcept;
|
void setCenter(const QPointF& center) noexcept;
|
||||||
void setCenter(qreal x, qreal y) 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;
|
constexpr qreal startAngle() const noexcept;
|
||||||
void setStartAngle( qreal ) noexcept;
|
void setStartAngle( qreal ) noexcept;
|
||||||
|
|
||||||
|
@ -104,7 +111,8 @@ class QSK_EXPORT QskRadialDirection
|
||||||
{
|
{
|
||||||
Q_GADGET
|
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 )
|
Q_PROPERTY( qreal radius READ radius WRITE setRadius )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -117,6 +125,12 @@ class QSK_EXPORT QskRadialDirection
|
||||||
void setCenter(const QPointF& center) noexcept;
|
void setCenter(const QPointF& center) noexcept;
|
||||||
void setCenter(qreal x, qreal y) 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;
|
constexpr qreal radius() const noexcept;
|
||||||
void setRadius( qreal radius ) noexcept;
|
void setRadius( qreal radius ) noexcept;
|
||||||
|
|
||||||
|
@ -242,6 +256,16 @@ inline constexpr qreal QskConicDirection::spanAngle() const noexcept
|
||||||
return m_spanAngle;
|
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(
|
inline constexpr QskRadialDirection::QskRadialDirection(
|
||||||
qreal x, qreal y, qreal radius ) noexcept
|
qreal x, qreal y, qreal radius ) noexcept
|
||||||
: m_x( x )
|
: m_x( x )
|
||||||
|
@ -261,6 +285,16 @@ inline constexpr QPointF QskRadialDirection::center() const noexcept
|
||||||
return QPointF( m_x, m_y );
|
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
|
inline constexpr qreal QskRadialDirection::radius() const noexcept
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
|
|
Loading…
Reference in New Issue