45 const QSizeF& r1,
const QSizeF& r2,
46 Edge edge, BorderStyle s, QBrush c)
48 const qreal pw = (edge == TopEdge || edge == BottomEdge) ? y2-y1 : x2-x1;
49 if (s == BorderStyle_Double) {
54 qDrawRoundedCorners(p, x1, y1, x2, y1+wby3, r1, r2, edge, BorderStyle_Solid, c);
55 qDrawRoundedCorners(p, x1, y2-wby3, x2, y2, r1, r2, edge, BorderStyle_Solid, c);
58 qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, LeftEdge, BorderStyle_Solid, c);
59 qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, LeftEdge, BorderStyle_Solid, c);
62 qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, RightEdge, BorderStyle_Solid, c);
63 qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, RightEdge, BorderStyle_Solid, c);
69 }
else if (s == BorderStyle_Ridge || s == BorderStyle_Groove) {
71 if (s == BorderStyle_Groove) {
72 s1 = BorderStyle_Inset;
73 s2 = BorderStyle_Outset;
75 s1 = BorderStyle_Outset;
76 s2 = BorderStyle_Inset;
78 int pwby2 = qRound(pw/2);
81 qDrawRoundedCorners(p, x1, y1, x2, y1 + pwby2, r1, r2, TopEdge, s1, c);
82 qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, TopEdge, s2, c);
85 qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, BottomEdge, s1, c);
86 qDrawRoundedCorners(p, x1, y1, x2, y2-pwby2, r1, r2, BottomEdge, s2, c);
89 qDrawRoundedCorners(p, x1, y1, x1 + pwby2, y2, r1, r2, LeftEdge, s1, c);
90 qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, LeftEdge, s2, c);
93 qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, RightEdge, s1, c);
94 qDrawRoundedCorners(p, x1, y1, x2 - pwby2, y2, r1, r2, RightEdge, s2, c);
99 }
else if ((s == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
100 || (s == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
101 c = c.color().lighter();
105 p->setBrush(Qt::NoBrush);
106 QPen pen = qPenFromStyle(c, pw, s);
107 pen.setCapStyle(Qt::SquareCap);
112 p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2,
113 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16);
115 p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2,
116 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16);
120 p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2,
121 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16);
123 p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2,
124 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16);
128 p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2,
129 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16);
131 p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2,
132 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16);
136 p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2,
137 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16);
139 p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2,
140 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16);
150 QCss::Edge edge, QCss::BorderStyle style, QBrush c)
153 const qreal width = (edge == TopEdge || edge == BottomEdge) ? (y2-y1) : (x2-x1);
155 if (width <= 2 && style == BorderStyle_Double)
156 style = BorderStyle_Solid;
159 case BorderStyle_Inset:
160 case BorderStyle_Outset:
161 if ((style == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
162 || (style == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
163 c = c.color().lighter();
165 case BorderStyle_Solid: {
166 p->setPen(Qt::NoPen);
168 if (width == 1 || (dw1 == 0 && dw2 == 0)) {
169 p->drawRect(QRectF(x1, y1, x2-x1, y2-y1));
171 std::array<QPointF, 4> quad;
174 quad = {QPointF(x1, y1), QPointF(x1 + dw1, y2),
175 QPointF(x2 - dw2, y2), QPointF(x2, y1)};
178 quad = {QPointF(x1 + dw1, y1), QPointF(x1, y2),
179 QPointF(x2, y2), QPointF(x2 - dw2, y1)};
182 quad = {QPointF(x1, y1), QPointF(x1, y2),
183 QPointF(x2, y2 - dw2), QPointF(x2, y1 + dw1)};
186 quad = {QPointF(x1, y1 + dw1), QPointF(x1, y2 - dw2),
187 QPointF(x2, y2), QPointF(x2, y1)};
192 p->drawConvexPolygon(quad.data(),
static_cast<
int>(quad.size()));
196 case BorderStyle_Dotted:
197 case BorderStyle_Dashed:
198 case BorderStyle_DotDash:
199 case BorderStyle_DotDotDash:
200 p->setPen(qPenFromStyle(c, width, style));
202 p->drawLine(QLineF(x1, y1, x2 - 1, y2 - 1));
203 else if (edge == TopEdge || edge == BottomEdge)
204 p->drawLine(QLineF(x1 + width/2, (y1 + y2)/2, x2 - width/2, (y1 + y2)/2));
206 p->drawLine(QLineF((x1+x2)/2, y1 + width/2, (x1+x2)/2, y2 - width/2));
209 case BorderStyle_Double: {
210 int wby3 = qRound(width/3);
211 int dw1by3 = qRound(dw1/3);
212 int dw2by3 = qRound(dw2/3);
215 qDrawEdge(p, x1, y1, x2, y1 + wby3, dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c);
216 qDrawEdge(p, x1 + dw1 - dw1by3, y2 - wby3, x2 - dw2 + dw1by3, y2,
217 dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c);
220 qDrawEdge(p, x1, y1, x1 + wby3, y2, dw1by3, dw2by3, LeftEdge, BorderStyle_Solid, c);
221 qDrawEdge(p, x2 - wby3, y1 + dw1 - dw1by3, x2, y2 - dw2 + dw2by3, dw1by3, dw2by3,
222 LeftEdge, BorderStyle_Solid, c);
225 qDrawEdge(p, x1 + dw1 - dw1by3, y1, x2 - dw2 + dw2by3, y1 + wby3, dw1by3, dw2by3,
226 BottomEdge, BorderStyle_Solid, c);
227 qDrawEdge(p, x1, y2 - wby3, x2, y2, dw1by3, dw2by3, BottomEdge, BorderStyle_Solid, c);
230 qDrawEdge(p, x2 - wby3, y1, x2, y2, dw1by3, dw2by3, RightEdge, BorderStyle_Solid, c);
231 qDrawEdge(p, x1, y1 + dw1 - dw1by3, x1 + wby3, y2 - dw2 + dw2by3, dw1by3, dw2by3,
232 RightEdge, BorderStyle_Solid, c);
239 case BorderStyle_Ridge:
240 case BorderStyle_Groove: {
242 if (style == BorderStyle_Groove) {
243 s1 = BorderStyle_Inset;
244 s2 = BorderStyle_Outset;
246 s1 = BorderStyle_Outset;
247 s2 = BorderStyle_Inset;
249 int dw1by2 = qFloor(dw1/2), dw2by2 = qFloor(dw2/2);
250 int wby2 = qRound(width/2);
253 qDrawEdge(p, x1, y1, x2, y1 + wby2, dw1by2, dw2by2, TopEdge, s1, c);
254 qDrawEdge(p, x1 + dw1by2, y1 + wby2, x2 - dw2by2, y2, dw1by2, dw2by2, TopEdge, s2, c);
257 qDrawEdge(p, x1, y1 + wby2, x2, y2, dw1by2, dw2by2, BottomEdge, s1, c);
258 qDrawEdge(p, x1 + dw1by2, y1, x2 - dw2by2, y1 + wby2, dw1by2, dw2by2, BottomEdge, s2, c);
261 qDrawEdge(p, x1, y1, x1 + wby2, y2, dw1by2, dw2by2, LeftEdge, s1, c);
262 qDrawEdge(p, x1 + wby2, y1 + dw1by2, x2, y2 - dw2by2, dw1by2, dw2by2, LeftEdge, s2, c);
265 qDrawEdge(p, x1 + wby2, y1, x2, y2, dw1by2, dw2by2, RightEdge, s1, c);
266 qDrawEdge(p, x1, y1 + dw1by2, x1 + wby2, y2 - dw2by2, dw1by2, dw2by2, RightEdge, s2, c);
314 const int *borders,
const QBrush *colors,
const QSize *radii)
316 const QRectF br(rect);
317 QSize tlr, trr, blr, brr;
318 qNormalizeRadii(rect, radii, &tlr, &trr, &blr, &brr);
321 if (styles[BottomEdge] != BorderStyle_None && borders[BottomEdge] > 0) {
322 qreal dw1 = (blr.width() || paintsOver(styles, colors, BottomEdge, LeftEdge)) ? 0 : borders[LeftEdge];
323 qreal dw2 = (brr.width() || paintsOver(styles, colors, BottomEdge, RightEdge)) ? 0 : borders[RightEdge];
324 qreal x1 = br.x() + blr.width();
325 qreal y1 = br.y() + br.height() - borders[BottomEdge];
326 qreal x2 = br.x() + br.width() - brr.width();
327 qreal y2 = br.y() + br.height() ;
329 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, BottomEdge, styles[BottomEdge], colors[BottomEdge]);
330 if (blr.width() || brr.width())
331 qDrawRoundedCorners(p, x1, y1, x2, y2, blr, brr, BottomEdge, styles[BottomEdge], colors[BottomEdge]);
333 if (styles[RightEdge] != BorderStyle_None && borders[RightEdge] > 0) {
334 qreal dw1 = (trr.height() || paintsOver(styles, colors, RightEdge, TopEdge)) ? 0 : borders[TopEdge];
335 qreal dw2 = (brr.height() || paintsOver(styles, colors, RightEdge, BottomEdge)) ? 0 : borders[BottomEdge];
336 qreal x1 = br.x() + br.width() - borders[RightEdge];
337 qreal y1 = br.y() + trr.height();
338 qreal x2 = br.x() + br.width();
339 qreal y2 = br.y() + br.height() - brr.height();
341 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, RightEdge, styles[RightEdge], colors[RightEdge]);
342 if (trr.height() || brr.height())
343 qDrawRoundedCorners(p, x1, y1, x2, y2, trr, brr, RightEdge, styles[RightEdge], colors[RightEdge]);
345 if (styles[LeftEdge] != BorderStyle_None && borders[LeftEdge] > 0) {
346 qreal dw1 = (tlr.height() || paintsOver(styles, colors, LeftEdge, TopEdge)) ? 0 : borders[TopEdge];
347 qreal dw2 = (blr.height() || paintsOver(styles, colors, LeftEdge, BottomEdge)) ? 0 : borders[BottomEdge];
349 qreal y1 = br.y() + tlr.height();
350 qreal x2 = br.x() + borders[LeftEdge];
351 qreal y2 = br.y() + br.height() - blr.height();
353 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, LeftEdge, styles[LeftEdge], colors[LeftEdge]);
354 if (tlr.height() || blr.height())
355 qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, blr, LeftEdge, styles[LeftEdge], colors[LeftEdge]);
357 if (styles[TopEdge] != BorderStyle_None && borders[TopEdge] > 0) {
358 qreal dw1 = (tlr.width() || paintsOver(styles, colors, TopEdge, LeftEdge)) ? 0 : borders[LeftEdge];
359 qreal dw2 = (trr.width() || paintsOver(styles, colors, TopEdge, RightEdge)) ? 0 : borders[RightEdge];
360 qreal x1 = br.x() + tlr.width();
362 qreal x2 = br.left() + br.width() - trr.width();
363 qreal y2 = br.y() + borders[TopEdge];
365 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, TopEdge, styles[TopEdge], colors[TopEdge]);
366 if (tlr.width() || trr.width())
367 qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, trr, TopEdge, styles[TopEdge], colors[TopEdge]);