MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / roundRect

Method roundRect

app/src/UI/Widgets/PainterContext.cpp:979–1008  ·  view source on GitHub ↗

* @brief Adds a rounded-rectangle subpath. radii may be a number or [tl, tr, br, bl]. */

Source from the content-addressed store, hash-verified

977 * @brief Adds a rounded-rectangle subpath. radii may be a number or [tl, tr, br, bl].
978 */
979void Widgets::PainterContext::roundRect(qreal x, qreal y, qreal w, qreal h, const QJSValue& radii)
980{
981 qreal tl = 0.0, tr = 0.0, br = 0.0, bl = 0.0;
982 if (radii.isNumber())
983 tl = tr = br = bl = radii.toNumber();
984 else if (radii.isArray())
985 parseRoundRectRadiiArray(radii, tl, tr, br, bl);
986
987 const qreal maxR = qMin(std::abs(w), std::abs(h)) * 0.5;
988 tl = qBound<qreal>(0.0, tl, maxR);
989 tr = qBound<qreal>(0.0, tr, maxR);
990 br = qBound<qreal>(0.0, br, maxR);
991 bl = qBound<qreal>(0.0, bl, maxR);
992
993 if (qFuzzyIsNull(tl) && qFuzzyIsNull(tr) && qFuzzyIsNull(br) && qFuzzyIsNull(bl)) {
994 m_path.addRect(x, y, w, h);
995 return;
996 }
997
998 m_path.moveTo(x + tl, y);
999 m_path.lineTo(x + w - tr, y);
1000 m_path.arcTo(x + w - 2 * tr, y, 2 * tr, 2 * tr, 90, -90);
1001 m_path.lineTo(x + w, y + h - br);
1002 m_path.arcTo(x + w - 2 * br, y + h - 2 * br, 2 * br, 2 * br, 0, -90);
1003 m_path.lineTo(x + bl, y + h);
1004 m_path.arcTo(x, y + h - 2 * bl, 2 * bl, 2 * bl, -90, -90);
1005 m_path.lineTo(x, y + tl);
1006 m_path.arcTo(x, y, 2 * tl, 2 * tl, 180, -90);
1007 m_path.closeSubpath();
1008}
1009
1010/**
1011 * @brief Adds a circular arc to the path (Canvas2D semantics).

Callers

nothing calls this directly

Calls 5

parseRoundRectRadiiArrayFunction · 0.85
absFunction · 0.85
moveToMethod · 0.80
lineToMethod · 0.80
arcToMethod · 0.80

Tested by

no test coverage detected