7#include <QtGui/QPainter>
15 , m_topRightRadius(-1)
16 , m_bottomLeftRadius(-1)
17 , m_bottomRightRadius(-1)
19 , m_cornerPixmapIsDirty(true)
20 , m_devicePixelRatio(1)
39 if (m_color !=
color) {
41 m_cornerPixmapIsDirty =
true;
48 if (m_penColor !=
color) {
50 m_cornerPixmapIsDirty =
true;
57 if (m_penWidth !=
width) {
59 m_cornerPixmapIsDirty =
true;
67 double distance = secondStop.first - firstStop.first;
68 double distanceDelta = newPos - firstStop.first;
69 double modifierValue = distanceDelta /
distance;
70 const auto firstStopRgbColor = firstStop.second.toRgb();
71 const auto secondStopRgbColor = secondStop.second.toRgb();
72 int redDelta = (secondStopRgbColor.red() - firstStopRgbColor.red()) * modifierValue;
73 int greenDelta = (secondStopRgbColor.green() - firstStopRgbColor.green()) * modifierValue;
74 int blueDelta = (secondStopRgbColor.blue() - firstStopRgbColor.blue()) * modifierValue;
75 int alphaDelta = (secondStopRgbColor.alpha() - firstStopRgbColor.alpha()) * modifierValue;
78 newStop.first = newPos;
79 newStop.second =
QColor(firstStopRgbColor.red() + redDelta,
80 firstStopRgbColor.green() + greenDelta,
81 firstStopRgbColor.blue() + blueDelta,
82 firstStopRgbColor.alpha() + alphaDelta);
90 bool needsNormalization =
false;
92 if (stop.first < 0.0 || stop.first > 1.0) {
93 needsNormalization =
true;
98 if (needsNormalization) {
100 if (stops.
size() == 1) {
105 normalizedStops.
append(stop);
111 for (
int i = 0;
i < stops.
size(); ++
i) {
112 if (stops.
at(
i).first < 0.0) {
114 }
else if (stops.
at(
i).first > 1.0) {
125 if (below + 1 < stops.
size()) {
129 singleStop.first = 0.0;
130 singleStop.second = stops.
at(below).second;
131 normalizedStops.
append(singleStop);
135 for (
int i = 0;
i < between.
size(); ++
i)
144 singleStop.first = 1.0;
145 singleStop.second = stops.
at(above).second;
146 normalizedStops.
append(singleStop);
151 m_stops = normalizedStops;
156 m_cornerPixmapIsDirty =
true;
162 if (m_vertical != vertical) {
163 m_vertical = vertical;
164 m_cornerPixmapIsDirty =
true;
171 if (m_radius != radius) {
173 m_cornerPixmapIsDirty =
true;
180 if (m_topLeftRadius != radius) {
181 m_topLeftRadius = radius;
182 m_cornerPixmapIsDirty =
true;
189 if (m_topRightRadius != radius) {
190 m_topRightRadius = radius;
191 m_cornerPixmapIsDirty =
true;
198 if (m_bottomLeftRadius != radius) {
199 m_bottomLeftRadius = radius;
200 m_cornerPixmapIsDirty =
true;
207 if (m_bottomRightRadius != radius) {
208 m_bottomRightRadius = radius;
209 m_cornerPixmapIsDirty =
true;
223 m_pen =
QPen(m_penColor);
230 m_brush =
QBrush(gradient);
232 m_brush =
QBrush(m_color);
235 if (m_cornerPixmapIsDirty) {
236 generateCornerPixmap();
237 m_cornerPixmapIsDirty =
false;
247 generateCornerPixmap();
256 && m_topLeftRadius <= 0
257 && m_topRightRadius <= 0
258 && m_bottomLeftRadius <= 0
259 && m_bottomRightRadius <= 0) {
265 }
else if (m_topLeftRadius < 0
266 && m_topRightRadius < 0
267 && m_bottomLeftRadius < 0
268 && m_bottomRightRadius < 0) {
273 pixmap.setDevicePixelRatio(m_devicePixelRatio);
275 paintRectangle(&pixmapPainter,
QRect(0, 0, m_rect.
width(), m_rect.
height()));
286 pixmap.setDevicePixelRatio(m_devicePixelRatio);
289 paintRectangleIndividualCorners(&pixmapPainter,
QRect(0, 0, m_rect.
width(), m_rect.
height()));
301 if (m_topLeftRadius < 0
302 && m_topRightRadius < 0
303 && m_bottomLeftRadius < 0
304 && m_bottomRightRadius < 0) {
305 paintRectangle(
painter, m_rect);
307 paintRectangleIndividualCorners(
painter, m_rect);
317 if (m_color.
alpha() < 255)
319 if (m_penWidth > 0.0f && m_penColor.
alpha() < 255)
321 if (m_stops.
size() > 0) {
323 if (stop.second.alpha() < 255)
345 if (m_penWidth > 0) {
354 if (borderWidth > radius) {
365 if (borderTopOutside.isValid())
367 if (borderTopInside.isValid())
369 if (borderBottomOutside.isValid())
371 if (borderBottomInside.isValid())
380 if (borderTop.isValid())
382 if (borderBottom.isValid())
389 if (borderLeft.isValid())
391 if (borderRight.isValid())
404 int scaledRadius =
qRound(radius * m_devicePixelRatio);
416 painter->
drawPixmap(bottomRightCorner, m_cornerPixmap,
QRectF(scaledRadius, scaledRadius, scaledRadius, scaledRadius));
423 if (brushRect.
width() < 0)
425 if (brushRect.
height() < 0)
427 double innerRectRadius =
qMax(0.0, radius - m_penWidth);
430 if (m_color.
alpha() > 0 || !m_stops.
empty()) {
431 if (innerRectRadius > 0) {
433 if (m_stops.
empty()) {
435 QRectF centerRect(
QPointF(brushRect.
x() + innerRectRadius, brushRect.
y()),
436 QPointF(brushRect.
x() + brushRect.
width() - innerRectRadius, brushRect.
y() + brushRect.
height()));
438 QRectF leftRect(
QPointF(brushRect.
x(), brushRect.
y() + innerRectRadius),
439 QPointF(brushRect.
x() + innerRectRadius, brushRect.
y() + brushRect.
height() - innerRectRadius));
441 QRectF rightRect(
QPointF(brushRect.
x() + brushRect.
width() - innerRectRadius, brushRect.
y() + innerRectRadius),
442 QPointF(brushRect.
x() + brushRect.
width(), brushRect.
y() + brushRect.
height() - innerRectRadius));
463 const float w = m_penWidth;
468 const float radiusBL =
qMin(
qMin(
rect.
width(),
rect.
height()) * 0.5f,
float(m_bottomLeftRadius < 0. ? m_radius : m_bottomLeftRadius));
469 const float radiusBR =
qMin(
qMin(
rect.
width(),
rect.
height()) * 0.5f,
float(m_bottomRightRadius < 0 ? m_radius : m_bottomRightRadius));
479 if (innerRadiusTR > 0.)
484 if (innerRadiusBR > 0.)
489 if (innerRadiusBL > 0.)
493 if (innerRadiusTL > 0.)
528void QSGSoftwareInternalRectangleNode::generateCornerPixmap()
532 const auto width =
qRound(radius * 2 * m_devicePixelRatio);
541 QPainter cornerPainter(&m_cornerPixmap);
546 if (m_penWidth > 0) {
548 cornerPainter.setBrush(m_penColor);
549 cornerPainter.drawRoundedRect(
QRectF(0, 0, radius * 2, radius *2), radius, radius);
553 if (radius > m_penWidth) {
556 cornerPainter.setBrush(m_brush);
560 QMarginsF adjustmentMargins(m_penWidth, m_penWidth, m_penWidth, m_penWidth);
562 cornerPainter.drawRoundedRect(cornerCircleRect, radius, radius);
The QColor class provides colors based on RGB, HSV or CMYK values.
int alpha() const noexcept
Returns the alpha color component of this color.
void setStops(const QGradientStops &stops)
Replaces the current set of stop points with the given stopPoints.
qsizetype size() const noexcept
bool isEmpty() const noexcept
bool empty() const noexcept
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
qreal devicePixelRatio() const
The QPainter class performs low-level painting on widgets and other paint devices.
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
const QTransform & transform() const
Alias for worldTransform().
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
void setJoinStyle(Qt::PenJoinStyle pcs)
Sets the pen's join style to the given style.
void setMiterLimit(qreal limit)
Sets the miter limit of this pen to the given limit.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
int width() const
Returns the width of the pixmap.
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the pixmap.
QRect rect() const
Returns the pixmap's enclosing rectangle.
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void moveTo(qreal x, qreal y) noexcept
Moves the rectangle, leaving the top-left corner at the given position (x, y).
QRect toAlignedRect() const noexcept
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QRectF marginsRemoved(const QMarginsF &margins) const noexcept
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
constexpr void setWidth(qreal w) noexcept
Sets the width of the rectangle to the given finite width.
constexpr void setHeight(qreal h) noexcept
Sets the height of the rectangle to the given finite height.
\inmodule QtCore\reentrant
constexpr QPoint bottomLeft() const noexcept
Returns the position of the rectangle's bottom-left corner.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr QPoint topRight() const noexcept
Returns the position of the rectangle's top-right corner.
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
constexpr int width() const noexcept
Returns the width of the rectangle.
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
The QSGMaterial class encapsulates rendering state for a shader program.
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
void setBottomRightRadius(qreal radius) override
void setRect(const QRectF &rect) override
void setRadius(qreal radius) override
void setGradientVertical(bool vertical) override
void setTopLeftRadius(qreal radius) override
QSGSoftwareInternalRectangleNode()
void setTopRightRadius(qreal radius) override
void setBottomLeftRadius(qreal radius) override
void setColor(const QColor &color) override
void setGradientStops(const QGradientStops &stops) override
void setPenWidth(qreal width) override
void setPenColor(const QColor &color) override
void setAligned(bool aligned) override
Combined button and popup list for selecting options.
QPair< qreal, QColor > QGradientStop
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLfloat GLfloat GLfloat w
[0]
GLsizei GLsizei GLfloat distance
GLsizei const GLchar *const * path
static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle)
static QGradientStop interpolateStop(const QGradientStop &firstStop, const QGradientStop &secondStop, double newPos)
static QGradientStop interpolateStop(const QGradientStop &firstStop, const QGradientStop &secondStop, double newPos)