File indexing completed on 2024-06-09 04:20:49
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Sharaf Zaman <sharafzaz121@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef SVGMESHARRAY_H 0007 #define SVGMESHARRAY_H 0008 0009 #include <QVector> 0010 0011 #include "SvgMeshPatch.h" 0012 0013 struct SvgMeshPosition { 0014 int row; 0015 int col; 0016 SvgMeshPatch::Type segmentType; 0017 0018 SvgMeshPosition() 0019 : row(-1) 0020 , col(-1) 0021 , segmentType(SvgMeshPatch::Size) 0022 { 0023 } 0024 0025 SvgMeshPosition(int row, int col, SvgMeshPatch::Type type) 0026 : row(row) 0027 , col(col) 0028 , segmentType(type) 0029 { 0030 } 0031 0032 bool isValid() const { 0033 return row >= 0 && col >= 0; 0034 } 0035 }; 0036 0037 class KRITAFLAKE_EXPORT SvgMeshArray 0038 { 0039 public: 0040 SvgMeshArray(); 0041 0042 SvgMeshArray(const SvgMeshArray& other); 0043 0044 ~SvgMeshArray(); 0045 0046 /// creates a default mesh in OBB coordinates (because it's easier and more logical in this case) 0047 void createDefaultMesh(const int nrows, const int ncols, const QColor color, const QSizeF size); 0048 0049 void newRow(); 0050 0051 bool addPatch(QList<QPair<QString, QColor>> stops, const QPointF initialPoint); 0052 0053 /// Get the point of a node in mesharray 0054 SvgMeshStop getStop(const SvgMeshPatch::Type edge, const int row, const int col) const; 0055 0056 SvgMeshStop getStop(const SvgMeshPosition &pos) const; 0057 0058 /// Get the Path Points for a segment of the meshpatch 0059 std::array<QPointF, 4> getPath(const SvgMeshPatch::Type edge, const int row, const int col) const; 0060 0061 // overload 0062 SvgMeshPath getPath(const SvgMeshPosition &pos) const; 0063 0064 SvgMeshPatch* getPatch(const int row, const int col) const; 0065 0066 int numRows() const; 0067 int numColumns() const; 0068 0069 void setTransform(const QTransform& matrix); 0070 0071 QRectF boundingRect() const; 0072 0073 /// Return the paths connected to the corner. Can be thought of as edges connected to a vertex 0074 QVector<SvgMeshPosition> getConnectedPaths(const SvgMeshPosition &position) const; 0075 0076 void modifyHandle(const SvgMeshPosition &position, const std::array<QPointF, 4> &newPath); 0077 void modifyCorner(const SvgMeshPosition &position, const QPointF &newPos); 0078 0079 void modifyColor(const SvgMeshPosition &position, const QColor &color); 0080 0081 private: 0082 /// return the shared path between two patches. 0083 /// NOTE: Not to be confused with getConnectedPaths 0084 QVector<SvgMeshPosition> getSharedPaths(const SvgMeshPosition &position) const; 0085 0086 // get color of a stop 0087 QColor getColor(SvgMeshPatch::Type edge, int row, int col) const; 0088 0089 private: 0090 /// where each vector is a meshrow 0091 QVector<QVector<SvgMeshPatch*>> m_array; 0092 }; 0093 0094 #endif // SVGMESHARRAY_H