2022-11-13 16:22:09 +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_GRDIENT_DIRECTION_H
|
|
|
|
#define QSK_GRDIENT_DIRECTION_H
|
|
|
|
|
|
|
|
#include "QskGlobal.h"
|
|
|
|
|
|
|
|
#include <qmetatype.h>
|
|
|
|
#include <qpoint.h>
|
2022-12-28 18:23:42 +00:00
|
|
|
#include <qline.h>
|
|
|
|
|
|
|
|
class QLineF;
|
2022-11-13 16:22:09 +00:00
|
|
|
|
|
|
|
class QSK_EXPORT QskLinearDirection
|
|
|
|
{
|
|
|
|
Q_GADGET
|
|
|
|
|
|
|
|
Q_PROPERTY( qreal x1 READ x1 WRITE setX1 )
|
|
|
|
Q_PROPERTY( qreal y1 READ y1 WRITE setY1 )
|
|
|
|
Q_PROPERTY( qreal x2 READ x2 WRITE setX2 )
|
|
|
|
Q_PROPERTY( qreal y2 READ y2 WRITE setY2 )
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr QskLinearDirection() noexcept = default;
|
|
|
|
|
|
|
|
constexpr QskLinearDirection( Qt::Orientation ) noexcept;
|
|
|
|
|
2022-12-28 18:23:42 +00:00
|
|
|
constexpr QskLinearDirection( const QLineF& ) noexcept;
|
2022-11-13 16:22:09 +00:00
|
|
|
constexpr QskLinearDirection( const QPointF&, const QPointF& ) noexcept;
|
|
|
|
constexpr QskLinearDirection( qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept;
|
|
|
|
|
2022-12-28 18:23:42 +00:00
|
|
|
void setVector( const QLineF& ) noexcept;
|
|
|
|
void setVector( const QPointF&, const QPointF& ) noexcept;
|
|
|
|
void setVector( qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept;
|
|
|
|
|
|
|
|
constexpr QLineF vector() const noexcept;
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
void setStart( const QPointF& ) noexcept;
|
|
|
|
void setStart( qreal x, qreal y ) noexcept;
|
|
|
|
|
|
|
|
void setStop(const QPointF& ) noexcept;
|
|
|
|
void setStop( qreal x, qreal y ) noexcept;
|
|
|
|
|
|
|
|
void setInterval( Qt::Orientation, qreal, qreal );
|
|
|
|
|
|
|
|
void setOrientation( Qt::Orientation ) noexcept;
|
|
|
|
constexpr bool isOriented( Qt::Orientation ) const noexcept;
|
|
|
|
|
|
|
|
constexpr bool isHorizontal() const noexcept;
|
|
|
|
constexpr bool isVertical() const noexcept;
|
|
|
|
constexpr bool isTilted() const noexcept;
|
|
|
|
|
|
|
|
constexpr QPointF start() const noexcept;
|
|
|
|
constexpr QPointF stop() const noexcept;
|
|
|
|
|
|
|
|
constexpr qreal x1() const noexcept;
|
|
|
|
void setX1( qreal ) noexcept;
|
|
|
|
|
|
|
|
constexpr qreal y1() const noexcept;
|
|
|
|
void setY1( qreal ) noexcept;
|
|
|
|
|
|
|
|
constexpr qreal x2() const noexcept;
|
|
|
|
void setX2( qreal ) noexcept;
|
|
|
|
|
|
|
|
constexpr qreal y2() const noexcept;
|
|
|
|
void setY2( qreal ) noexcept;
|
|
|
|
|
2023-01-24 18:40:41 +00:00
|
|
|
/*
|
|
|
|
In direction of the gradient vector, where 0.0 corresponds to
|
|
|
|
points on the perpendicular at the start and 1.0 to points on
|
2023-01-24 19:26:23 +00:00
|
|
|
the perpendicular of the end point.
|
2023-01-24 18:40:41 +00:00
|
|
|
|
|
|
|
Also corresponds to the positions of the color stops and can be
|
2023-01-24 19:26:23 +00:00
|
|
|
used to calculate the color at a specific position.
|
2023-01-24 18:40:41 +00:00
|
|
|
*/
|
|
|
|
qreal valueAt( const QPointF& ) const;
|
|
|
|
qreal valueAt( qreal x, qreal y ) const;
|
|
|
|
|
2023-01-23 09:59:34 +00:00
|
|
|
bool contains( const QRectF& ) const;
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
private:
|
|
|
|
qreal m_x1 = 0.0;
|
|
|
|
qreal m_y1 = 0.0;
|
|
|
|
qreal m_x2 = 0.0;
|
|
|
|
qreal m_y2 = 1.0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QSK_EXPORT QskConicDirection
|
|
|
|
{
|
|
|
|
Q_GADGET
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
Q_PROPERTY( qreal x READ x WRITE setX )
|
|
|
|
Q_PROPERTY( qreal y READ y WRITE setY )
|
2022-11-13 16:22:09 +00:00
|
|
|
Q_PROPERTY( qreal startAngle READ startAngle WRITE setStartAngle )
|
|
|
|
Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle )
|
|
|
|
|
|
|
|
public:
|
|
|
|
// counter-clockwise
|
|
|
|
constexpr QskConicDirection() noexcept = default;
|
|
|
|
|
|
|
|
constexpr QskConicDirection( qreal x, qreal y, qreal startAngle = 0.0 ) noexcept;
|
|
|
|
constexpr QskConicDirection( qreal x, qreal y, qreal startAngle, qreal spanAngle ) noexcept;
|
|
|
|
|
|
|
|
constexpr QskConicDirection( const QPointF&, qreal startAngle = 0.0 ) noexcept;
|
|
|
|
constexpr QskConicDirection( const QPointF&, qreal startAngle, qreal spanAngle ) noexcept;
|
|
|
|
|
|
|
|
constexpr QPointF center() const noexcept;
|
|
|
|
void setCenter(const QPointF& center) noexcept;
|
|
|
|
void setCenter(qreal x, qreal y) noexcept;
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
void setX( qreal ) noexcept;
|
|
|
|
constexpr qreal x() const noexcept;
|
|
|
|
|
|
|
|
void setY( qreal ) noexcept;
|
|
|
|
constexpr qreal y() const noexcept;
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
constexpr qreal startAngle() const noexcept;
|
|
|
|
void setStartAngle( qreal ) noexcept;
|
|
|
|
|
|
|
|
constexpr qreal spanAngle() const noexcept;
|
|
|
|
void setSpanAngle( qreal ) noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
qreal m_x = 0.5;
|
|
|
|
qreal m_y = 0.5;
|
|
|
|
qreal m_startAngle = 0.0;
|
|
|
|
qreal m_spanAngle = 360.0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QSK_EXPORT QskRadialDirection
|
|
|
|
{
|
|
|
|
Q_GADGET
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
Q_PROPERTY( qreal x READ x WRITE setX )
|
|
|
|
Q_PROPERTY( qreal y READ y WRITE setY )
|
2022-12-23 13:57:46 +00:00
|
|
|
Q_PROPERTY( qreal radiusX READ radiusX WRITE setRadiusX )
|
|
|
|
Q_PROPERTY( qreal radiusY READ radiusY WRITE setRadiusY )
|
2022-11-13 16:22:09 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr QskRadialDirection() noexcept = default;
|
|
|
|
|
|
|
|
constexpr QskRadialDirection( const QPointF& center, qreal radius ) noexcept;
|
|
|
|
constexpr QskRadialDirection( qreal cx, qreal cy, qreal radius ) noexcept;
|
2022-12-23 13:57:46 +00:00
|
|
|
constexpr QskRadialDirection( qreal cx, qreal cy, qreal radiusX, qreal radiusY ) noexcept;
|
2022-11-13 16:22:09 +00:00
|
|
|
|
|
|
|
constexpr QPointF center() const noexcept;
|
2022-12-23 13:57:46 +00:00
|
|
|
void setCenter(const QPointF& ) noexcept;
|
2022-11-13 16:22:09 +00:00
|
|
|
void setCenter(qreal x, qreal y) noexcept;
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
void setX( qreal ) noexcept;
|
|
|
|
constexpr qreal x() const noexcept;
|
|
|
|
|
|
|
|
void setY( qreal ) noexcept;
|
|
|
|
constexpr qreal y() const noexcept;
|
|
|
|
|
2022-12-23 13:57:46 +00:00
|
|
|
constexpr qreal radiusX() const noexcept;
|
|
|
|
void setRadiusX( qreal ) noexcept;
|
|
|
|
|
|
|
|
constexpr qreal radiusY() const noexcept;
|
|
|
|
void setRadiusY( qreal ) noexcept;
|
|
|
|
|
|
|
|
void setRadius( qreal ) noexcept;
|
|
|
|
void setRadius( qreal, qreal ) noexcept;
|
2022-11-13 16:22:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
qreal m_x = 0.5;
|
|
|
|
qreal m_y = 0.5;
|
2022-12-23 13:57:46 +00:00
|
|
|
qreal m_radiusX = 0.5;
|
|
|
|
qreal m_radiusY = 0.5;
|
2022-11-13 16:22:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline constexpr QskLinearDirection::QskLinearDirection(
|
|
|
|
Qt::Orientation orientation ) noexcept
|
|
|
|
: m_x2( ( orientation == Qt::Vertical ) ? 0.0 : 1.0 )
|
|
|
|
, m_y2( ( orientation == Qt::Vertical ) ? 1.0 : 0.0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-28 18:23:42 +00:00
|
|
|
inline constexpr QskLinearDirection::QskLinearDirection( const QLineF& vector ) noexcept
|
|
|
|
: QskLinearDirection( vector.x1(), vector.y1(), vector.x2(), vector.y2() )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
inline constexpr QskLinearDirection::QskLinearDirection(
|
|
|
|
const QPointF& start, const QPointF& stop ) noexcept
|
|
|
|
: QskLinearDirection( start.x(), start.y(), stop.x(), stop.y() )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskLinearDirection::QskLinearDirection(
|
|
|
|
qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept
|
|
|
|
: m_x1( x1 )
|
|
|
|
, m_y1( y1 )
|
|
|
|
, m_x2( x2 )
|
|
|
|
, m_y2( y2 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskLinearDirection::x1() const noexcept
|
|
|
|
{
|
|
|
|
return m_x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskLinearDirection::y1() const noexcept
|
|
|
|
{
|
|
|
|
return m_y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskLinearDirection::x2() const noexcept
|
|
|
|
{
|
|
|
|
return m_x2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskLinearDirection::y2() const noexcept
|
|
|
|
{
|
|
|
|
return m_y2;
|
|
|
|
}
|
|
|
|
|
2022-12-28 18:23:42 +00:00
|
|
|
inline constexpr QLineF QskLinearDirection::vector() const noexcept
|
|
|
|
{
|
|
|
|
return QLineF( m_x1, m_y1, m_x2, m_y2 );
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
inline constexpr QPointF QskLinearDirection::start() const noexcept
|
|
|
|
{
|
|
|
|
return QPointF( m_x1, m_y1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QPointF QskLinearDirection::stop() const noexcept
|
|
|
|
{
|
|
|
|
return QPointF( m_x2, m_y2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr bool QskLinearDirection::isOriented(
|
|
|
|
Qt::Orientation orientation ) const noexcept
|
|
|
|
{
|
2023-01-24 18:40:41 +00:00
|
|
|
return ( orientation == Qt::Horizontal ) ? isHorizontal() : isVertical();
|
2022-11-13 16:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr bool QskLinearDirection::isHorizontal() const noexcept
|
|
|
|
{
|
|
|
|
return !isVertical() && ( m_y1 == m_y2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr bool QskLinearDirection::isVertical() const noexcept
|
|
|
|
{
|
|
|
|
return m_x1 == m_x2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr bool QskLinearDirection::isTilted() const noexcept
|
|
|
|
{
|
|
|
|
return ( m_x1 != m_x2 ) && ( m_y1 != m_y2 );
|
|
|
|
}
|
|
|
|
|
2023-01-24 18:40:41 +00:00
|
|
|
inline qreal QskLinearDirection::valueAt( const QPointF& pos ) const
|
|
|
|
{
|
|
|
|
return valueAt( pos.x(), pos.y() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline qreal QskLinearDirection::valueAt( qreal x, qreal y ) const
|
|
|
|
{
|
2023-01-24 19:26:23 +00:00
|
|
|
// we could cache these values TODO ..
|
|
|
|
const qreal dx = m_x2 - m_x1;
|
|
|
|
const qreal dy = m_y2 - m_y1;
|
|
|
|
const qreal dot = dx * dx + dy * dy;
|
|
|
|
|
|
|
|
return ( ( x - m_x1 ) * dx + ( y - m_y1 ) * dy ) / dot;
|
2023-01-24 18:40:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
inline constexpr QskConicDirection::QskConicDirection(
|
|
|
|
qreal x, qreal y, qreal startAngle ) noexcept
|
|
|
|
: QskConicDirection( x, y, startAngle, 360.0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskConicDirection::QskConicDirection(
|
|
|
|
qreal x, qreal y, qreal startAngle, qreal spanAngle ) noexcept
|
|
|
|
: m_x( x )
|
|
|
|
, m_y( y )
|
|
|
|
, m_startAngle( startAngle )
|
|
|
|
, m_spanAngle( spanAngle )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskConicDirection::QskConicDirection(
|
|
|
|
const QPointF& pos, qreal startAngle ) noexcept
|
|
|
|
: QskConicDirection( pos.x(), pos.y(), startAngle )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskConicDirection::QskConicDirection(
|
|
|
|
const QPointF& pos, qreal startAngle, qreal spanAngle ) noexcept
|
|
|
|
: QskConicDirection( pos.x(), pos.y(), startAngle, spanAngle )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QPointF QskConicDirection::center() const noexcept
|
|
|
|
{
|
|
|
|
return QPointF( m_x, m_y );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskConicDirection::startAngle() const noexcept
|
|
|
|
{
|
|
|
|
return m_startAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskConicDirection::spanAngle() const noexcept
|
|
|
|
{
|
|
|
|
return m_spanAngle;
|
|
|
|
}
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
inline constexpr qreal QskConicDirection::x() const noexcept
|
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskConicDirection::y() const noexcept
|
|
|
|
{
|
|
|
|
return m_y;
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:22:09 +00:00
|
|
|
inline constexpr QskRadialDirection::QskRadialDirection(
|
|
|
|
qreal x, qreal y, qreal radius ) noexcept
|
|
|
|
: m_x( x )
|
|
|
|
, m_y( y )
|
2022-12-23 13:57:46 +00:00
|
|
|
, m_radiusX( radius )
|
|
|
|
, m_radiusY( radius )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskRadialDirection::QskRadialDirection(
|
|
|
|
qreal x, qreal y, qreal radiusX, qreal radiusY ) noexcept
|
|
|
|
: m_x( x )
|
|
|
|
, m_y( y )
|
|
|
|
, m_radiusX( radiusX )
|
|
|
|
, m_radiusY( radiusY )
|
2022-11-13 16:22:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QskRadialDirection::QskRadialDirection(
|
|
|
|
const QPointF& center, qreal radius ) noexcept
|
|
|
|
: QskRadialDirection( center.x(), center.y(), radius )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr QPointF QskRadialDirection::center() const noexcept
|
|
|
|
{
|
|
|
|
return QPointF( m_x, m_y );
|
|
|
|
}
|
|
|
|
|
2022-11-29 09:59:09 +00:00
|
|
|
inline constexpr qreal QskRadialDirection::x() const noexcept
|
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskRadialDirection::y() const noexcept
|
|
|
|
{
|
|
|
|
return m_y;
|
|
|
|
}
|
|
|
|
|
2022-12-23 13:57:46 +00:00
|
|
|
inline constexpr qreal QskRadialDirection::radiusX() const noexcept
|
|
|
|
{
|
|
|
|
return m_radiusX;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr qreal QskRadialDirection::radiusY() const noexcept
|
2022-11-13 16:22:09 +00:00
|
|
|
{
|
2022-12-23 13:57:46 +00:00
|
|
|
return m_radiusY;
|
2022-11-13 16:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|