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 #pragma once
0006 
0007 #include <QPainterPath>
0008 #include <QQmlEngine>
0009 
0010 /**
0011  * A class for making QPainterPaths available in QML.
0012  */
0013 class QmlPainterPath
0014 {
0015     QPainterPath m_path;
0016     Q_GADGET
0017 
0018     /**
0019      * The path in the form of an SVG path string for use with a Qt Quick SvgPath.
0020      */
0021     Q_PROPERTY(QString svgPath READ svgPath FINAL)
0022 
0023     Q_PROPERTY(bool empty READ empty FINAL)
0024     Q_PROPERTY(int elementCount READ elementCount FINAL)
0025     Q_PROPERTY(QPointF start READ start FINAL)
0026     Q_PROPERTY(QPointF end READ end FINAL)
0027     Q_PROPERTY(QRectF boundingRect READ boundingRect FINAL)
0028 
0029     QML_FOREIGN(QPainterPath)
0030     QML_EXTENDED(QmlPainterPath)
0031 
0032 public:
0033     Q_INVOKABLE QString toString() const;
0034 
0035     Q_INVOKABLE bool contains(const QPointF &point) const;
0036 
0037     Q_INVOKABLE bool contains(const QRectF &rect) const;
0038 
0039     Q_INVOKABLE bool intersects(const QRectF &rect) const;
0040 
0041     Q_INVOKABLE QPainterPath map(const QMatrix4x4 &transform) const;
0042 
0043     Q_INVOKABLE QRectF mapBoundingRect(const QMatrix4x4 &transform) const;
0044 
0045     static QString toSvgPathElement(const QPainterPath::Element &element);
0046 
0047     static QString toSvgPath(const QPainterPath &path);
0048 
0049     QString svgPath() const;
0050 
0051     bool empty() const;
0052 
0053     int elementCount() const;
0054 
0055     QPointF start() const;
0056 
0057     QPointF end() const;
0058 
0059     QRectF boundingRect() const;
0060 
0061     operator QPainterPath() const;
0062 };