* @brief Updates the stroke style. Accepts a CSS color string OR a gradient/pattern object. */
| 581 | * @brief Updates the stroke style. Accepts a CSS color string OR a gradient/pattern object. |
| 582 | */ |
| 583 | void Widgets::PainterContext::setStrokeStyle(const QJSValue& value) |
| 584 | { |
| 585 | if (value.isString()) { |
| 586 | const QString spec = value.toString(); |
| 587 | const QColor c = parseColor(spec); |
| 588 | if (!c.isValid()) |
| 589 | return; |
| 590 | |
| 591 | m_state.strokeSpec = spec; |
| 592 | m_state.strokeStyleValue = value; |
| 593 | m_state.strokePen.setColor(c); |
| 594 | m_state.strokePen.setBrush(QBrush(c)); |
| 595 | rebindStrokeBrush(); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | if (value.isQObject()) { |
| 600 | if (auto* g = qobject_cast<PainterGradient*>(value.toQObject())) { |
| 601 | m_state.strokePen.setBrush(g->brush()); |
| 602 | m_state.strokeStyleValue = value; |
| 603 | rebindStrokeBrush(); |
| 604 | return; |
| 605 | } |
| 606 | if (auto* p = qobject_cast<PainterPattern*>(value.toQObject())) { |
| 607 | m_state.strokePen.setBrush(p->brush()); |
| 608 | m_state.strokeStyleValue = value; |
| 609 | rebindStrokeBrush(); |
| 610 | return; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * @brief Updates the line width. |