* @brief Sets the dash pattern. Empty array means a solid line. */
| 1417 | * @brief Sets the dash pattern. Empty array means a solid line. |
| 1418 | */ |
| 1419 | void Widgets::PainterContext::setLineDash(const QJSValue& segments) |
| 1420 | { |
| 1421 | m_state.lineDash.clear(); |
| 1422 | if (segments.isArray()) { |
| 1423 | const int n = segments.property(QStringLiteral("length")).toInt(); |
| 1424 | m_state.lineDash.reserve(n); |
| 1425 | for (int i = 0; i < n; ++i) { |
| 1426 | const qreal v = segments.property(static_cast<quint32>(i)).toNumber(); |
| 1427 | if (v < 0.0) |
| 1428 | return; |
| 1429 | |
| 1430 | m_state.lineDash.push_back(v); |
| 1431 | } |
| 1432 | |
| 1433 | if ((n & 1) != 0) { |
| 1434 | const int dup = n; |
| 1435 | for (int i = 0; i < dup; ++i) |
| 1436 | m_state.lineDash.push_back(m_state.lineDash[i]); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | applyDashToPen(); |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * @brief Returns the active dash pattern as a JS-friendly variant list. |