File indexing completed on 2025-02-02 04:26:10
0001 /* SPDX-FileCopyrightText: 2024 Noah Davis <noahadvs@gmail.com> 0002 * SPDX-License-Identifier: LGPL-2.0-or-later 0003 */ 0004 0005 #include "QmlPainterPath.h" 0006 #include <QMatrix4x4> 0007 0008 QString QmlPainterPath::toString() const 0009 { 0010 return QStringLiteral("QPainterPath(%1)").arg(svgPath()); 0011 } 0012 0013 bool QmlPainterPath::contains(const QPointF &point) const 0014 { 0015 return m_path.contains(point); 0016 } 0017 0018 bool QmlPainterPath::contains(const QRectF &rect) const 0019 { 0020 return m_path.contains(rect); 0021 } 0022 0023 bool QmlPainterPath::intersects(const QRectF &rect) const 0024 { 0025 return m_path.intersects(rect); 0026 } 0027 0028 QPainterPath QmlPainterPath::map(const QMatrix4x4 &transform) const 0029 { 0030 return transform.toTransform().map(m_path); 0031 } 0032 0033 QRectF QmlPainterPath::mapBoundingRect(const QMatrix4x4 &transform) const 0034 { 0035 return transform.toTransform().mapRect(m_path.boundingRect()); 0036 } 0037 0038 QString QmlPainterPath::toSvgPathElement(const QPainterPath::Element &element) 0039 { 0040 switch (element.type) { 0041 case QPainterPath::MoveToElement: 0042 return QStringLiteral("M %1,%2").arg(element.x, 0, 'f').arg(element.y, 0, 'f'); 0043 case QPainterPath::LineToElement: 0044 return QStringLiteral("L %1,%2").arg(element.x, 0, 'f').arg(element.y, 0, 'f'); 0045 case QPainterPath::CurveToElement: 0046 return QStringLiteral("C %1,%2").arg(element.x, 0, 'f').arg(element.y, 0, 'f'); 0047 case QPainterPath::CurveToDataElement: 0048 return QStringLiteral("%1,%2").arg(element.x, 0, 'f').arg(element.y, 0, 'f'); 0049 } 0050 return {}; 0051 } 0052 0053 QString QmlPainterPath::toSvgPath(const QPainterPath &path) 0054 { 0055 QString svgPath; 0056 for (int i = 0; i < path.elementCount(); ++i) { 0057 svgPath.append(toSvgPathElement(path.elementAt(i)) % u' '); 0058 } 0059 return svgPath; 0060 } 0061 0062 QString QmlPainterPath::svgPath() const 0063 { 0064 return toSvgPath(m_path); 0065 } 0066 0067 bool QmlPainterPath::empty() const 0068 { 0069 return m_path.isEmpty(); 0070 } 0071 0072 int QmlPainterPath::elementCount() const 0073 { 0074 return m_path.elementCount(); 0075 } 0076 0077 QPointF QmlPainterPath::start() const 0078 { 0079 return m_path.elementCount() > 0 ? m_path.elementAt(0) : QPointF{}; 0080 } 0081 0082 QPointF QmlPainterPath::end() const 0083 { 0084 return m_path.currentPosition(); 0085 } 0086 0087 QRectF QmlPainterPath::boundingRect() const 0088 { 0089 return m_path.boundingRect(); 0090 } 0091 0092 QmlPainterPath::operator QPainterPath() const 0093 { 0094 return m_path; 0095 } 0096 0097 #include "moc_QmlPainterPath.cpp"