File indexing completed on 2026-08-09 08:17:43

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2018 Kevin Ottens <ervin@kde.org>
0003 
0004 #ifndef STROKE_H
0005 #define STROKE_H
0006 
0007 #include <QColor>
0008 #include <QObject>
0009 #include <QRectF>
0010 #include <QVector2D>
0011 #include <QVector>
0012 
0013 class StrokeSample
0014 {
0015     Q_GADGET
0016     Q_PROPERTY(QVector2D position MEMBER position)
0017     Q_PROPERTY(float width MEMBER width)
0018 public:
0019     QVector2D position;
0020     float width = 1.0f;
0021 
0022     bool operator==(const StrokeSample &other) const;
0023 };
0024 
0025 class Stroke
0026 {
0027     Q_GADGET
0028     Q_PROPERTY(Stroke::Type type READ type WRITE setType)
0029     Q_PROPERTY(QColor color READ color WRITE setColor)
0030 public:
0031     enum class Type { Outline, Fill };
0032     Q_ENUM(Type)
0033 
0034     Type type() const;
0035     void setType(Type type);
0036 
0037     QColor color() const;
0038     void setColor(const QColor &color);
0039 
0040     QVector<StrokeSample> samples() const;
0041     Q_INVOKABLE void addSample(const StrokeSample &sample);
0042     void addSamples(const QVector<StrokeSample> &samples);
0043 
0044     QVector<Stroke> eraseArea(const QVector2D &center, float radius);
0045 
0046     Q_INVOKABLE QRectF boundingRect() const;
0047 
0048 private:
0049     Type m_type = Type::Outline;
0050     QColor m_color = Qt::black;
0051     QVector<StrokeSample> m_samples;
0052     mutable QRectF m_boundingRectCache;
0053 };
0054 
0055 #endif // STROKE_H