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