1 /* 2 * Copyright (c) 2020 Sharaf Zaman <sharafzaz121@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 #ifndef SVGMESHARRAY_H 19 #define SVGMESHARRAY_H 20 21 #include <QVector> 22 23 #include "SvgMeshPatch.h" 24 25 struct SvgMeshPosition { 26 int row; 27 int col; 28 SvgMeshPatch::Type segmentType; 29 SvgMeshPositionSvgMeshPosition30 SvgMeshPosition() 31 : row(-1) 32 , col(-1) 33 , segmentType(SvgMeshPatch::Size) 34 { 35 } 36 SvgMeshPositionSvgMeshPosition37 SvgMeshPosition(int row, int col, SvgMeshPatch::Type type) 38 : row(row) 39 , col(col) 40 , segmentType(type) 41 { 42 } 43 isValidSvgMeshPosition44 bool isValid() const { 45 return row >= 0 && col >= 0; 46 } 47 }; 48 49 class KRITAFLAKE_EXPORT SvgMeshArray 50 { 51 public: 52 SvgMeshArray(); 53 54 SvgMeshArray(const SvgMeshArray& other); 55 56 ~SvgMeshArray(); 57 58 /// creates a default mesh in OBB coordinates (because it's easier and more logical in this case) 59 void createDefaultMesh(const int nrows, const int ncols, const QColor color, const QSizeF size); 60 61 void newRow(); 62 63 bool addPatch(QList<QPair<QString, QColor>> stops, const QPointF initialPoint); 64 65 /// Get the point of a node in mesharray 66 SvgMeshStop getStop(const SvgMeshPatch::Type edge, const int row, const int col) const; 67 68 SvgMeshStop getStop(const SvgMeshPosition &pos) const; 69 70 /// Get the Path Points for a segment of the meshpatch 71 std::array<QPointF, 4> getPath(const SvgMeshPatch::Type edge, const int row, const int col) const; 72 73 // overload 74 SvgMeshPath getPath(const SvgMeshPosition &pos) const; 75 76 SvgMeshPatch* getPatch(const int row, const int col) const; 77 78 int numRows() const; 79 int numColumns() const; 80 81 void setTransform(const QTransform& matrix); 82 83 QRectF boundingRect() const; 84 85 /// Return the paths connected to the corner. Can be thought of as edges connected to a vertex 86 QVector<SvgMeshPosition> getConnectedPaths(const SvgMeshPosition &position) const; 87 88 void modifyHandle(const SvgMeshPosition &position, const std::array<QPointF, 4> &newPath); 89 void modifyCorner(const SvgMeshPosition &position, const QPointF &newPos); 90 91 void modifyColor(const SvgMeshPosition &position, const QColor &color); 92 93 private: 94 /// return the shared path between two patches. 95 /// NOTE: Not to be confused with getConnectedPaths 96 QVector<SvgMeshPosition> getSharedPaths(const SvgMeshPosition &position) const; 97 98 // get color of a stop 99 QColor getColor(SvgMeshPatch::Type edge, int row, int col) const; 100 101 private: 102 /// where each vector is a meshrow 103 QVector<QVector<SvgMeshPatch*>> m_array; 104 }; 105 106 #endif // SVGMESHARRAY_H 107