Paints the background using the given fill path.
51{
52 if (
color().isValid()) {
53
55 }
56
57 const QRectF targetRect = fillPath.boundingRect();
58 painter.save();
59 painter.setClipPath(fillPath);
60 QPen pen(
d->lineColor);
61
62 pen.setWidthF(0.5);
63 painter.setPen(pen);
65
66
67
68
69
70 const int angleOffset[] = {-90, 0, -45 };
71
73
74 for (int i = 0; i < loops; ++i) {
75 int angle =
d->angle - angleOffset[i];
76 qreal cosAngle = ::cos(angle/180.0*
M_PI);
77
78 if (qAbs(cosAngle) > 0.00001) {
79 qreal xDiff = tan(angle/180.0*
M_PI) * targetRect.height();
80
81
82 qreal xOffset = qAbs(
d->distance / cosAngle);
83
84
85 qreal xStart = 0;
86 while (-xDiff < xStart) {
87 xStart -= xOffset;
88 }
89
90
91 qreal xEndOffset = 0;
92 if (xDiff < 0) {
93 while (xDiff < -xEndOffset) {
94 xEndOffset += xOffset;
95 }
96 }
97
98 lines.reserve(lines.size() + int((targetRect.width() + xEndOffset - xStart) / xOffset) + 1);
99 for (qreal x = xStart;
x < targetRect.width() + xEndOffset;
x += xOffset) {
100 lines.append(QLineF(x, 0, x + xDiff, targetRect.height()));
101 }
102 }
103 else {
104
105 lines.reserve(lines.size() +
int(targetRect.height()/
d->distance) + 1);
106 for (qreal y = 0;
y < targetRect.height();
y +=
d->distance) {
107 lines.append(QLineF(0, y, targetRect.width(), y));
108 }
109 }
110 }
111
112 painter.drawLines(lines);
113 painter.restore();
114}
void paint(QPainter &painter, const QPainterPath &fillPath) const override
Paints the background using the given fill path.
Qt::BrushStyle style() const
Returns the background style.
QColor color() const
Returns the background color.