6#include "QskGradientDirection.h"
9static void qskRegisterGradientDirection()
11 qRegisterMetaType< QskLinearDirection >();
12 qRegisterMetaType< QskConicDirection >();
13 qRegisterMetaType< QskRadialDirection >();
16Q_CONSTRUCTOR_FUNCTION( qskRegisterGradientDirection )
20void QskLinearDirection::setOrientation( Qt::Orientation orientation )
noexcept
25 if ( orientation == Qt::Vertical )
37void QskLinearDirection::setVector(
const QLineF& vector )
noexcept
46void QskLinearDirection::setVector(
const QPointF& start,
const QPointF& stop )
noexcept
55void QskLinearDirection::setVector( qreal x1, qreal y1, qreal x2, qreal y2 )
noexcept
64void QskLinearDirection::setStart(
const QPointF& pos )
noexcept
71void QskLinearDirection::setStart( qreal x, qreal y )
noexcept
78void QskLinearDirection::setStop(
const QPointF& pos )
noexcept
85void QskLinearDirection::setStop( qreal x, qreal y )
noexcept
92void QskLinearDirection::setX1( qreal x )
noexcept
98void QskLinearDirection::setY1( qreal y )
noexcept
104void QskLinearDirection::setX2( qreal x )
noexcept
110void QskLinearDirection::setY2( qreal y )
noexcept
116void QskLinearDirection::setInterval( Qt::Orientation orientation, qreal from, qreal to )
118 if ( orientation == Qt::Vertical )
131void QskLinearDirection::precalculate() const noexcept
135 m_dot = m_dx * m_dx + m_dy * m_dy;
138static inline bool qskIntersectsTop(
139 qreal vx, qreal vy, qreal m,
const QRectF& rect )
141 const auto cx = vx - ( vy - rect.top() ) / m;
142 return cx > rect.left() && cx < rect.right();
145static inline bool qskIntersectsBottom(
146 qreal vx, qreal vy, qreal m,
const QRectF& rect )
148 const auto cx = vx - ( vy - rect.bottom() ) / m;
149 return cx > rect.left() && cx < rect.right();
152static inline bool qskIntersectsLeft(
153 qreal vx, qreal vy, qreal m,
const QRectF& rect )
155 const auto cy = vy - ( vx - rect.left() ) * m;
156 return ( cy > rect.top() && cy < rect.bottom() );
159static inline bool qskIntersectsRight(
160 qreal vx, qreal vy, qreal m,
const QRectF& rect )
162 const auto cy = vy - ( vx - rect.right() ) * m;
163 return ( cy > rect.top() && cy < rect.bottom() );
166bool QskLinearDirection::contains(
const QRectF& rect )
const
170 return ( m_x1 <= rect.left() && m_x2 >= rect.right() )
171 || ( m_x1 >= rect.right() && m_x2 <= rect.left() );
176 return ( m_y1 <= rect.top() && m_y2 >= rect.bottom() )
177 || ( m_y1 >= rect.bottom() && m_y2 <= rect.top() );
182 const auto m = ( m_x2 - m_x1 ) / ( m_y1 - m_y2 );
184 const bool intersecting =
185 qskIntersectsLeft( m_x1, m_y1, m, rect ) ||
186 qskIntersectsRight( m_x1, m_y1, m, rect ) ||
187 qskIntersectsTop( m_x1, m_y1, m, rect ) ||
188 qskIntersectsBottom( m_x1, m_y1, m, rect ) ||
189 qskIntersectsLeft( m_x2, m_y2, m, rect ) ||
190 qskIntersectsRight( m_x2, m_y2, m, rect ) ||
191 qskIntersectsTop( m_x2, m_y2, m, rect ) ||
192 qskIntersectsBottom( m_x2, m_y2, m, rect );
194 return !intersecting;
199void QskConicDirection::setCenter(
const QPointF& center )
noexcept
205void QskConicDirection::setCenter( qreal x, qreal y )
noexcept
211void QskConicDirection::setX( qreal x )
noexcept
216void QskConicDirection::setY( qreal y )
noexcept
221void QskConicDirection::setStartAngle( qreal degrees )
noexcept
223 m_startAngle = degrees;
226void QskConicDirection::setSpanAngle( qreal degrees )
noexcept
228 m_spanAngle = qBound( -360.0, degrees, 360.0 );
231void QskConicDirection::setAspectRatio( qreal ratio )
noexcept
233 m_aspectRatio = qMax( ratio, 0.0 );
238void QskRadialDirection::setCenter(
const QPointF& center )
noexcept
244void QskRadialDirection::setCenter( qreal x, qreal y )
noexcept
250void QskRadialDirection::setX( qreal x )
noexcept
255void QskRadialDirection::setY( qreal y )
noexcept
260void QskRadialDirection::setRadiusX( qreal radius )
noexcept
265void QskRadialDirection::setRadiusY( qreal radius )
noexcept
270void QskRadialDirection::setRadius( qreal radius )
noexcept
272 m_radiusX = m_radiusY = radius;
275void QskRadialDirection::setRadius( qreal radiusX, qreal radiusY )
noexcept
281#include "moc_QskGradientDirection.cpp"