46 const QSizeF& r1,
const QSizeF& r2,
47 Edge edge, BorderStyle s, QBrush c)
49 const qreal pw = (edge == TopEdge || edge == BottomEdge) ? y2-y1 : x2-x1;
50 if (s == BorderStyle_Double) {
55 qDrawRoundedCorners(p, x1, y1, x2, y1+wby3, r1, r2, edge, BorderStyle_Solid, c);
56 qDrawRoundedCorners(p, x1, y2-wby3, x2, y2, r1, r2, edge, BorderStyle_Solid, c);
59 qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, LeftEdge, BorderStyle_Solid, c);
60 qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, LeftEdge, BorderStyle_Solid, c);
63 qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, RightEdge, BorderStyle_Solid, c);
64 qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, RightEdge, BorderStyle_Solid, c);
70 }
else if (s == BorderStyle_Ridge || s == BorderStyle_Groove) {
72 if (s == BorderStyle_Groove) {
73 s1 = BorderStyle_Inset;
74 s2 = BorderStyle_Outset;
76 s1 = BorderStyle_Outset;
77 s2 = BorderStyle_Inset;
79 int pwby2 = qRound(pw/2);
82 qDrawRoundedCorners(p, x1, y1, x2, y1 + pwby2, r1, r2, TopEdge, s1, c);
83 qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, TopEdge, s2, c);
86 qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, BottomEdge, s1, c);
87 qDrawRoundedCorners(p, x1, y1, x2, y2-pwby2, r1, r2, BottomEdge, s2, c);
90 qDrawRoundedCorners(p, x1, y1, x1 + pwby2, y2, r1, r2, LeftEdge, s1, c);
91 qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, LeftEdge, s2, c);
94 qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, RightEdge, s1, c);
95 qDrawRoundedCorners(p, x1, y1, x2 - pwby2, y2, r1, r2, RightEdge, s2, c);
100 }
else if ((s == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
101 || (s == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
102 c = c.color().lighter();
106 p->setBrush(Qt::NoBrush);
107 QPen pen = qPenFromStyle(c, pw, s);
108 pen.setCapStyle(Qt::SquareCap);
113 p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2,
114 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16);
116 p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2,
117 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16);
121 p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2,
122 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16);
124 p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2,
125 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16);
129 p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2,
130 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16);
132 p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2,
133 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16);
137 p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2,
138 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16);
140 p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2,
141 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16);
151 QCss::Edge edge, QCss::BorderStyle style, QBrush c)
154 const qreal width = (edge == TopEdge || edge == BottomEdge) ? (y2-y1) : (x2-x1);
156 if (width <= 2 && style == BorderStyle_Double)
157 style = BorderStyle_Solid;
160 case BorderStyle_Inset:
161 case BorderStyle_Outset:
162 if ((style == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
163 || (style == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
164 c = c.color().lighter();
166 case BorderStyle_Solid: {
167 p->setPen(Qt::NoPen);
169 if (width == 1 || (dw1 == 0 && dw2 == 0)) {
170 p->drawRect(QRectF(x1, y1, x2-x1, y2-y1));
172 std::array<QPointF, 4> quad;
175 quad = {QPointF(x1, y1), QPointF(x1 + dw1, y2),
176 QPointF(x2 - dw2, y2), QPointF(x2, y1)};
179 quad = {QPointF(x1 + dw1, y1), QPointF(x1, y2),
180 QPointF(x2, y2), QPointF(x2 - dw2, y1)};
183 quad = {QPointF(x1, y1), QPointF(x1, y2),
184 QPointF(x2, y2 - dw2), QPointF(x2, y1 + dw1)};
187 quad = {QPointF(x1, y1 + dw1), QPointF(x1, y2 - dw2),
188 QPointF(x2, y2), QPointF(x2, y1)};
193 p->drawConvexPolygon(quad.data(),
static_cast<
int>(quad.size()));
197 case BorderStyle_Dotted:
198 case BorderStyle_Dashed:
199 case BorderStyle_DotDash:
200 case BorderStyle_DotDotDash:
201 p->setPen(qPenFromStyle(c, width, style));
203 p->drawLine(QLineF(x1, y1, x2 - 1, y2 - 1));
204 else if (edge == TopEdge || edge == BottomEdge)
205 p->drawLine(QLineF(x1 + width/2, (y1 + y2)/2, x2 - width/2, (y1 + y2)/2));
207 p->drawLine(QLineF((x1+x2)/2, y1 + width/2, (x1+x2)/2, y2 - width/2));
210 case BorderStyle_Double: {
211 int wby3 = qRound(width/3);
212 int dw1by3 = qRound(dw1/3);
213 int dw2by3 = qRound(dw2/3);
216 qDrawEdge(p, x1, y1, x2, y1 + wby3, dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c);
217 qDrawEdge(p, x1 + dw1 - dw1by3, y2 - wby3, x2 - dw2 + dw1by3, y2,
218 dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c);
221 qDrawEdge(p, x1, y1, x1 + wby3, y2, dw1by3, dw2by3, LeftEdge, BorderStyle_Solid, c);
222 qDrawEdge(p, x2 - wby3, y1 + dw1 - dw1by3, x2, y2 - dw2 + dw2by3, dw1by3, dw2by3,
223 LeftEdge, BorderStyle_Solid, c);
226 qDrawEdge(p, x1 + dw1 - dw1by3, y1, x2 - dw2 + dw2by3, y1 + wby3, dw1by3, dw2by3,
227 BottomEdge, BorderStyle_Solid, c);
228 qDrawEdge(p, x1, y2 - wby3, x2, y2, dw1by3, dw2by3, BottomEdge, BorderStyle_Solid, c);
231 qDrawEdge(p, x2 - wby3, y1, x2, y2, dw1by3, dw2by3, RightEdge, BorderStyle_Solid, c);
232 qDrawEdge(p, x1, y1 + dw1 - dw1by3, x1 + wby3, y2 - dw2 + dw2by3, dw1by3, dw2by3,
233 RightEdge, BorderStyle_Solid, c);
240 case BorderStyle_Ridge:
241 case BorderStyle_Groove: {
243 if (style == BorderStyle_Groove) {
244 s1 = BorderStyle_Inset;
245 s2 = BorderStyle_Outset;
247 s1 = BorderStyle_Outset;
248 s2 = BorderStyle_Inset;
250 int dw1by2 = qFloor(dw1/2), dw2by2 = qFloor(dw2/2);
251 int wby2 = qRound(width/2);
254 qDrawEdge(p, x1, y1, x2, y1 + wby2, dw1by2, dw2by2, TopEdge, s1, c);
255 qDrawEdge(p, x1 + dw1by2, y1 + wby2, x2 - dw2by2, y2, dw1by2, dw2by2, TopEdge, s2, c);
258 qDrawEdge(p, x1, y1 + wby2, x2, y2, dw1by2, dw2by2, BottomEdge, s1, c);
259 qDrawEdge(p, x1 + dw1by2, y1, x2 - dw2by2, y1 + wby2, dw1by2, dw2by2, BottomEdge, s2, c);
262 qDrawEdge(p, x1, y1, x1 + wby2, y2, dw1by2, dw2by2, LeftEdge, s1, c);
263 qDrawEdge(p, x1 + wby2, y1 + dw1by2, x2, y2 - dw2by2, dw1by2, dw2by2, LeftEdge, s2, c);
266 qDrawEdge(p, x1 + wby2, y1, x2, y2, dw1by2, dw2by2, RightEdge, s1, c);
267 qDrawEdge(p, x1, y1 + dw1by2, x1 + wby2, y2 - dw2by2, dw1by2, dw2by2, RightEdge, s2, c);
315 const int *borders,
const QBrush *colors,
const QSize *radii)
317 const QRectF br(rect);
318 QSize tlr, trr, blr, brr;
319 qNormalizeRadii(rect, radii, &tlr, &trr, &blr, &brr);
322 if (styles[BottomEdge] != BorderStyle_None && borders[BottomEdge] > 0) {
323 qreal dw1 = (blr.width() || paintsOver(styles, colors, BottomEdge, LeftEdge)) ? 0 : borders[LeftEdge];
324 qreal dw2 = (brr.width() || paintsOver(styles, colors, BottomEdge, RightEdge)) ? 0 : borders[RightEdge];
325 qreal x1 = br.x() + blr.width();
326 qreal y1 = br.y() + br.height() - borders[BottomEdge];
327 qreal x2 = br.x() + br.width() - brr.width();
328 qreal y2 = br.y() + br.height() ;
330 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, BottomEdge, styles[BottomEdge], colors[BottomEdge]);
331 if (blr.width() || brr.width())
332 qDrawRoundedCorners(p, x1, y1, x2, y2, blr, brr, BottomEdge, styles[BottomEdge], colors[BottomEdge]);
334 if (styles[RightEdge] != BorderStyle_None && borders[RightEdge] > 0) {
335 qreal dw1 = (trr.height() || paintsOver(styles, colors, RightEdge, TopEdge)) ? 0 : borders[TopEdge];
336 qreal dw2 = (brr.height() || paintsOver(styles, colors, RightEdge, BottomEdge)) ? 0 : borders[BottomEdge];
337 qreal x1 = br.x() + br.width() - borders[RightEdge];
338 qreal y1 = br.y() + trr.height();
339 qreal x2 = br.x() + br.width();
340 qreal y2 = br.y() + br.height() - brr.height();
342 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, RightEdge, styles[RightEdge], colors[RightEdge]);
343 if (trr.height() || brr.height())
344 qDrawRoundedCorners(p, x1, y1, x2, y2, trr, brr, RightEdge, styles[RightEdge], colors[RightEdge]);
346 if (styles[LeftEdge] != BorderStyle_None && borders[LeftEdge] > 0) {
347 qreal dw1 = (tlr.height() || paintsOver(styles, colors, LeftEdge, TopEdge)) ? 0 : borders[TopEdge];
348 qreal dw2 = (blr.height() || paintsOver(styles, colors, LeftEdge, BottomEdge)) ? 0 : borders[BottomEdge];
350 qreal y1 = br.y() + tlr.height();
351 qreal x2 = br.x() + borders[LeftEdge];
352 qreal y2 = br.y() + br.height() - blr.height();
354 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, LeftEdge, styles[LeftEdge], colors[LeftEdge]);
355 if (tlr.height() || blr.height())
356 qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, blr, LeftEdge, styles[LeftEdge], colors[LeftEdge]);
358 if (styles[TopEdge] != BorderStyle_None && borders[TopEdge] > 0) {
359 qreal dw1 = (tlr.width() || paintsOver(styles, colors, TopEdge, LeftEdge)) ? 0 : borders[LeftEdge];
360 qreal dw2 = (trr.width() || paintsOver(styles, colors, TopEdge, RightEdge)) ? 0 : borders[RightEdge];
361 qreal x1 = br.x() + tlr.width();
363 qreal x2 = br.left() + br.width() - trr.width();
364 qreal y2 = br.y() + borders[TopEdge];
366 qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, TopEdge, styles[TopEdge], colors[TopEdge]);
367 if (tlr.width() || trr.width())
368 qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, trr, TopEdge, styles[TopEdge], colors[TopEdge]);