Qt 4.8
Public Functions | List of all members
QRadialGradient Class Reference

The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush. More...

#include <qbrush.h>

Inheritance diagram for QRadialGradient:
QGradient

Public Functions

QPointF center () const
 Returns the center of this radial gradient in logical coordinates. More...
 
qreal centerRadius () const
 Returns the center radius of this radial gradient in logical coordinates. More...
 
QPointF focalPoint () const
 Returns the focal point of this radial gradient in logical coordinates. More...
 
qreal focalRadius () const
 Returns the focal radius of this radial gradient in logical coordinates. More...
 
 QRadialGradient ()
 Constructs a simple radial gradient with the center and focal point at (0, 0) with a radius of 1. More...
 
 QRadialGradient (const QPointF &center, qreal radius, const QPointF &focalPoint)
 Constructs a simple radial gradient with the given center, radius and focalPoint. More...
 
 QRadialGradient (qreal cx, qreal cy, qreal radius, qreal fx, qreal fy)
 Constructs a simple radial gradient with the given center (cx, cy), radius and focal point (fx, fy). More...
 
 QRadialGradient (const QPointF &center, qreal radius)
 Constructs a simple radial gradient with the given center, radius and the focal point in the circle center. More...
 
 QRadialGradient (qreal cx, qreal cy, qreal radius)
 Constructs a simple radial gradient with the center at (cx, cy) and the specified radius. More...
 
 QRadialGradient (const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius)
 Constructs an extended radial gradient with the given center, centerRadius, focalPoint, and focalRadius. More...
 
 QRadialGradient (qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius)
 Constructs an extended radial gradient with the given center (cx, cy), center radius, centerRadius, focal point, (fx, fy), and focal radius focalRadius. More...
 
qreal radius () const
 Returns the radius of this radial gradient in logical coordinates. More...
 
void setCenter (const QPointF &center)
 Sets the center of this radial gradient in logical coordinates to center. More...
 
void setCenter (qreal x, qreal y)
 Sets the center of this radial gradient in logical coordinates to (x, y). More...
 
void setCenterRadius (qreal radius)
 
void setFocalPoint (const QPointF &focalPoint)
 Sets the focal point of this radial gradient in logical coordinates to focalPoint. More...
 
void setFocalPoint (qreal x, qreal y)
 Sets the focal point of this radial gradient in logical coordinates to (x, y). More...
 
void setFocalRadius (qreal radius)
 
void setRadius (qreal radius)
 
- Public Functions inherited from QGradient
CoordinateMode coordinateMode () const
 Returns the coordinate mode of this gradient. More...
 
InterpolationMode interpolationMode () const
 Returns the interpolation mode of this gradient. More...
 
bool operator!= (const QGradient &other) const
 Returns true if the gradient is the same as the other gradient specified; otherwise returns false. More...
 
bool operator== (const QGradient &gradient) const
 Returns true if the gradient is the same as the other gradient specified; otherwise returns false. More...
 
bool operator== (const QGradient &gradient)
 
 QGradient ()
 
void setColorAt (qreal pos, const QColor &color)
 Creates a stop point at the given position with the given color. More...
 
void setCoordinateMode (CoordinateMode mode)
 Sets the coordinate mode of this gradient to mode. More...
 
void setInterpolationMode (InterpolationMode mode)
 Sets the interpolation mode of this gradient to mode. More...
 
void setSpread (Spread spread)
 Specifies the spread method that should be used for this gradient. More...
 
void setStops (const QGradientStops &stops)
 Replaces the current set of stop points with the given stopPoints. More...
 
Spread spread () const
 Returns the spread method use by this gradient. More...
 
QGradientStops stops () const
 Returns the stop points for this gradient. More...
 
Type type () const
 Returns the type of gradient. More...
 

Additional Inherited Members

- Public Types inherited from QGradient
enum  CoordinateMode { LogicalMode, StretchToDeviceMode, ObjectBoundingMode }
 This enum specifies how gradient coordinates map to the paint device on which the gradient is used. More...
 
enum  InterpolationMode { ColorInterpolation, ComponentInterpolation }
 
enum  Spread { PadSpread, ReflectSpread, RepeatSpread }
 Specifies how the area outside the gradient area should be filled. More...
 
enum  Type { LinearGradient, RadialGradient, ConicalGradient, NoGradient }
 Specifies the type of gradient. More...
 

Detailed Description

The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush.

Qt supports both simple and extended radial gradients.

Simple radial gradients interpolate colors between a focal point and end points on a circle surrounding it. Extended radial gradients interpolate colors between a focal circle and a center circle. Points outside the cone defined by the two circles will be transparent. For simple radial gradients the focal point is adjusted to lie inside the center circle, whereas the focal point can have any position in an extended radial gradient.

Outside the end points the gradient is either padded, reflected or repeated depending on the currently set QGradient::Spread{spread} method:

qradialgradient-pad.png
qradialgradient-reflect.png
qradialgradient-repeat.png
QGradient::PadSpread{PadSpread} (default) QGradient::ReflectSpread{ReflectSpread} QGradient::RepeatSpread{RepeatSpread}

The colors in a gradient is defined using stop points of the QGradientStop type, i.e. a position and a color. Use the QGradient::setColorAt() or the QGradient::setStops() function to define the stop points. It is the gradient's complete set of stop points that describes how the gradient area should be filled. If no stop points have been specified, a gradient of black at 0 to white at 1 is used.

In addition to the functions inherited from QGradient, the QRadialGradient class provides the center(), focalPoint() and radius() functions returning the gradient's center, focal point and radius respectively.

See also
QLinearGradient, QConicalGradient, {demos/gradients}{The Gradients Demo}

Definition at line 297 of file qbrush.h.

Constructors and Destructors

◆ QRadialGradient() [1/7]

QRadialGradient::QRadialGradient ( )

Constructs a simple radial gradient with the center and focal point at (0, 0) with a radius of 1.

Definition at line 2040 of file qbrush.cpp.

2041 {
2043  m_spread = PadSpread;
2044  m_data.radial.cx = 0;
2045  m_data.radial.cy = 0;
2046  m_data.radial.cradius = 1;
2047  m_data.radial.fx = 0;
2048  m_data.radial.fy = 0;
2049 }
Type m_type
Definition: qbrush.h:260
union QGradient::@216 m_data
Spread m_spread
Definition: qbrush.h:261

◆ QRadialGradient() [2/7]

QRadialGradient::QRadialGradient ( const QPointF center,
qreal  radius,
const QPointF focalPoint 
)

Constructs a simple radial gradient with the given center, radius and focalPoint.

Note
If the given focal point is outside the circle defined by the center point and radius, it will be re-adjusted to lie at a point on the circle where it intersects with the line from center to focalPoint.
See also
QGradient::setColorAt(), QGradient::setStops()

Definition at line 1959 of file qbrush.cpp.

1960 {
1962  m_spread = PadSpread;
1963  m_data.radial.cx = center.x();
1964  m_data.radial.cy = center.y();
1965  m_data.radial.cradius = radius;
1966 
1967  QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(center, radius, focalPoint);
1968  m_data.radial.fx = adapted_focal.x();
1969  m_data.radial.fy = adapted_focal.y();
1970 }
Type m_type
Definition: qbrush.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF &center, qreal radius, const QPointF &focalPoint)
Definition: qbrush.cpp:1933
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
Spread m_spread
Definition: qbrush.h:261

◆ QRadialGradient() [3/7]

QRadialGradient::QRadialGradient ( qreal  cx,
qreal  cy,
qreal  radius,
qreal  fx,
qreal  fy 
)

Constructs a simple radial gradient with the given center (cx, cy), radius and focal point (fx, fy).

Note
If the given focal point is outside the circle defined by the center (cx, cy) and the radius it will be re-adjusted to the intersection between the line from the center to the focal point and the circle.
See also
QGradient::setColorAt(), QGradient::setStops()

Definition at line 2002 of file qbrush.cpp.

2003 {
2005  m_spread = PadSpread;
2006  m_data.radial.cx = cx;
2007  m_data.radial.cy = cy;
2008  m_data.radial.cradius = radius;
2009 
2011  radius,
2012  QPointF(fx, fy));
2013 
2014  m_data.radial.fx = adapted_focal.x();
2015  m_data.radial.fy = adapted_focal.y();
2016 }
qreal fx
Definition: qbrush.h:268
Type m_type
Definition: qbrush.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal cy
Definition: qbrush.h:268
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF &center, qreal radius, const QPointF &focalPoint)
Definition: qbrush.cpp:1933
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal cx
Definition: qbrush.h:268
Spread m_spread
Definition: qbrush.h:261
qreal fy
Definition: qbrush.h:268

◆ QRadialGradient() [4/7]

QRadialGradient::QRadialGradient ( const QPointF center,
qreal  radius 
)

Constructs a simple radial gradient with the given center, radius and the focal point in the circle center.

See also
QGradient::setColorAt(), QGradient::setStops()

Definition at line 1978 of file qbrush.cpp.

1979 {
1981  m_spread = PadSpread;
1982  m_data.radial.cx = center.x();
1983  m_data.radial.cy = center.y();
1984  m_data.radial.cradius = radius;
1985  m_data.radial.fx = center.x();
1986  m_data.radial.fy = center.y();
1987 }
Type m_type
Definition: qbrush.h:260
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
Spread m_spread
Definition: qbrush.h:261

◆ QRadialGradient() [5/7]

QRadialGradient::QRadialGradient ( qreal  cx,
qreal  cy,
qreal  radius 
)

Constructs a simple radial gradient with the center at (cx, cy) and the specified radius.

The focal point lies at the center of the circle.

See also
QGradient::setColorAt(), QGradient::setStops()

Definition at line 2024 of file qbrush.cpp.

2025 {
2027  m_spread = PadSpread;
2028  m_data.radial.cx = cx;
2029  m_data.radial.cy = cy;
2030  m_data.radial.cradius = radius;
2031  m_data.radial.fx = cx;
2032  m_data.radial.fy = cy;
2033 }
Type m_type
Definition: qbrush.h:260
qreal cy
Definition: qbrush.h:268
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal cx
Definition: qbrush.h:268
Spread m_spread
Definition: qbrush.h:261

◆ QRadialGradient() [6/7]

QRadialGradient::QRadialGradient ( const QPointF center,
qreal  centerRadius,
const QPointF focalPoint,
qreal  focalRadius 
)

Constructs an extended radial gradient with the given center, centerRadius, focalPoint, and focalRadius.

Since
4.8

Definition at line 2060 of file qbrush.cpp.

2061 {
2063  m_spread = PadSpread;
2064  m_data.radial.cx = center.x();
2065  m_data.radial.cy = center.y();
2066  m_data.radial.cradius = centerRadius;
2067 
2068  m_data.radial.fx = focalPoint.x();
2069  m_data.radial.fy = focalPoint.y();
2071 }
qreal focalRadius() const
Returns the focal radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2211
Type m_type
Definition: qbrush.h:260
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
union QGradient::@216 m_data
void setFocalRadius(qreal radius)
Definition: qbrush.cpp:2228
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
Spread m_spread
Definition: qbrush.h:261
qreal centerRadius() const
Returns the center radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2182

◆ QRadialGradient() [7/7]

QRadialGradient::QRadialGradient ( qreal  cx,
qreal  cy,
qreal  centerRadius,
qreal  fx,
qreal  fy,
qreal  focalRadius 
)

Constructs an extended radial gradient with the given center (cx, cy), center radius, centerRadius, focal point, (fx, fy), and focal radius focalRadius.

Since
4.8

Definition at line 2083 of file qbrush.cpp.

2084 {
2086  m_spread = PadSpread;
2087  m_data.radial.cx = cx;
2088  m_data.radial.cy = cy;
2089  m_data.radial.cradius = centerRadius;
2090 
2091  m_data.radial.fx = fx;
2092  m_data.radial.fy = fy;
2094 }
qreal focalRadius() const
Returns the focal radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2211
qreal fx
Definition: qbrush.h:268
Type m_type
Definition: qbrush.h:260
qreal cy
Definition: qbrush.h:268
union QGradient::@216 m_data
void setFocalRadius(qreal radius)
Definition: qbrush.cpp:2228
qreal cx
Definition: qbrush.h:268
Spread m_spread
Definition: qbrush.h:261
qreal centerRadius() const
Returns the center radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2182
qreal fy
Definition: qbrush.h:268

Functions

◆ center()

QPointF QRadialGradient::center ( ) const

Returns the center of this radial gradient in logical coordinates.

See also
QGradient::stops()

Definition at line 2102 of file qbrush.cpp.

Referenced by qt_isExtendedRadialGradient(), QSvgPaintEngine::saveRadialGradientBrush(), QVGPaintEnginePrivate::setBrush(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), QSpanData::setup(), QGL2PaintEngineExPrivate::updateBrushUniforms(), and QOpenGLPaintEnginePrivate::updateGradient().

2103 {
2105  return QPointF(m_data.radial.cx, m_data.radial.cy);
2106 }
Type m_type
Definition: qbrush.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data

◆ centerRadius()

qreal QRadialGradient::centerRadius ( ) const

Returns the center radius of this radial gradient in logical coordinates.

Since
4.8
See also
QGradient::stops()

Definition at line 2182 of file qbrush.cpp.

Referenced by QSpanData::setup(), and QGL2PaintEngineExPrivate::updateBrushUniforms().

2183 {
2185  return m_data.radial.cradius;
2186 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data

◆ focalPoint()

QPointF QRadialGradient::focalPoint ( ) const

Returns the focal point of this radial gradient in logical coordinates.

See also
QGradient::stops()

Definition at line 2251 of file qbrush.cpp.

Referenced by qt_isExtendedRadialGradient(), QSvgPaintEngine::saveRadialGradientBrush(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), QSpanData::setup(), QGL2PaintEngineExPrivate::updateBrushUniforms(), and QOpenGLPaintEnginePrivate::updateGradient().

2252 {
2254  return QPointF(m_data.radial.fx, m_data.radial.fy);
2255 }
Type m_type
Definition: qbrush.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data

◆ focalRadius()

qreal QRadialGradient::focalRadius ( ) const

Returns the focal radius of this radial gradient in logical coordinates.

Since
4.8
See also
QGradient::stops()

Definition at line 2211 of file qbrush.cpp.

Referenced by qt_isExtendedRadialGradient(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), QSpanData::setup(), and QGL2PaintEngineExPrivate::updateBrushUniforms().

2212 {
2215 
2216  // mask away low three bits
2217  union { float f; quint32 i; } u;
2218  u.i = i & ~0x07;
2219  return u.f;
2220 }
#define Q_DUMMY_ACCESSOR
Definition: qbrush.cpp:1530
Type m_type
Definition: qbrush.h:260
quint16 u
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int quint32
Definition: qglobal.h:938

◆ radius()

qreal QRadialGradient::radius ( ) const

Returns the radius of this radial gradient in logical coordinates.

Equivalent to centerRadius()

See also
QGradient::stops()

Definition at line 2150 of file qbrush.cpp.

Referenced by qt_isExtendedRadialGradient(), QSvgPaintEngine::saveRadialGradientBrush(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), and QOpenGLPaintEnginePrivate::updateGradient().

2151 {
2153  return m_data.radial.cradius;
2154 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data

◆ setCenter() [1/2]

void QRadialGradient::setCenter ( const QPointF center)

Sets the center of this radial gradient in logical coordinates to center.

Since
4.2
See also
center()

Definition at line 2134 of file qbrush.cpp.

2135 {
2137  m_data.radial.cx = center.x();
2138  m_data.radial.cy = center.y();
2139 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
union QGradient::@216 m_data
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ setCenter() [2/2]

void QRadialGradient::setCenter ( qreal  x,
qreal  y 
)
inline

Sets the center of this radial gradient in logical coordinates to (x, y).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.2
See also
center()

Definition at line 312 of file qbrush.h.

Referenced by setCenter().

312 { setCenter(QPointF(x, y)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setCenter(const QPointF &center)
Sets the center of this radial gradient in logical coordinates to center.
Definition: qbrush.cpp:2134

◆ setCenterRadius()

void QRadialGradient::setCenterRadius ( qreal  radius)
Since
4.8

Sets the center radius of this radial gradient in logical coordinates to radius

Definition at line 2194 of file qbrush.cpp.

2195 {
2197  m_data.radial.cradius = radius;
2198 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150

◆ setFocalPoint() [1/2]

void QRadialGradient::setFocalPoint ( const QPointF focalPoint)

Sets the focal point of this radial gradient in logical coordinates to focalPoint.

Since
4.2
See also
focalPoint()

Definition at line 2283 of file qbrush.cpp.

2284 {
2286  m_data.radial.fx = focalPoint.x();
2287  m_data.radial.fy = focalPoint.y();
2288 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
union QGradient::@216 m_data
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ setFocalPoint() [2/2]

void QRadialGradient::setFocalPoint ( qreal  x,
qreal  y 
)
inline

Sets the focal point of this radial gradient in logical coordinates to (x, y).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.2
See also
focalPoint()

Definition at line 316 of file qbrush.h.

Referenced by setFocalPoint().

316 { setFocalPoint(QPointF(x, y)); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setFocalPoint(const QPointF &focalPoint)
Sets the focal point of this radial gradient in logical coordinates to focalPoint.
Definition: qbrush.cpp:2283

◆ setFocalRadius()

void QRadialGradient::setFocalRadius ( qreal  radius)
Since
4.8

Sets the focal radius of this radial gradient in logical coordinates to radius

Definition at line 2228 of file qbrush.cpp.

2229 {
2232 
2233  // Since there's no QGradientData, we only have the dummy void * to
2234  // store additional data in. The three lowest bits are already
2235  // taken, thus we cut the three lowest bits from the significand
2236  // and store the radius as a float.
2237  union { float f; quint32 i; } u;
2238  u.f = float(radius);
2239  // add 0x04 to round up when we drop the three lowest bits
2240  i |= (u.i + 0x04) & ~0x07;
2241  dummy = p;
2242 }
#define Q_DUMMY_ACCESSOR
Definition: qbrush.cpp:1530
Type m_type
Definition: qbrush.h:260
quint16 u
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int quint32
Definition: qglobal.h:938
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
void * dummy
Definition: qbrush.h:274

◆ setRadius()

void QRadialGradient::setRadius ( qreal  radius)
Since
4.2

Sets the radius of this radial gradient in logical coordinates to radius

Equivalent to setCenterRadius()

Definition at line 2165 of file qbrush.cpp.

2166 {
2168  m_data.radial.cradius = radius;
2169 }
Type m_type
Definition: qbrush.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
union QGradient::@216 m_data
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150

The documentation for this class was generated from the following files: