1 /* 2 * Copyright (c) 2017 Dmitry Kazakov <dimula73@gmail.com> 3 * Copyright (c) 2020 Sharaf Zaman <sharafzaz121@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef __KOSHAPEMESHGRADIENTHANDLES_H_ 21 #define __KOSHAPEMESHGRADIENTHANDLES_H_ 22 23 #include <QPointF> 24 #include <KoFlake.h> 25 26 #include <SvgMeshGradient.h> 27 28 class KUndo2Command; 29 30 class KoShapeMeshGradientHandles { 31 public: 32 struct Handle { 33 enum Type { 34 None, 35 Corner, 36 BezierHandle 37 }; 38 39 enum Index { 40 First = 1, 41 Second 42 }; 43 HandleHandle44 Handle() : type(None) {} 45 Handle(Type t, const QPointF &p, int row, int col, SvgMeshPatch::Type segmentType, Index index = First) typeHandle46 : type(t) , pos(p) 47 , row(row) , col(col) 48 , segmentType(segmentType) 49 , index(index) 50 { 51 } 52 getPositionHandle53 SvgMeshPosition getPosition() const { 54 return SvgMeshPosition {row, col, segmentType}; 55 } 56 57 Type type {None}; 58 QPointF pos; 59 int row {0}; 60 int col {0}; 61 SvgMeshPatch::Type segmentType {SvgMeshPatch::Top}; 62 Index index { First }; // first or the second bezier handle 63 }; 64 65 public: 66 KoShapeMeshGradientHandles(KoFlake::FillVariant fillVariant, KoShape *shape); 67 68 /// get all nodes in the mesh, don't use this for drawing the path but use path() 69 QVector<Handle> handles() const; 70 71 /// convenience method to get a handle by its position in the mesharray 72 Handle getHandle(SvgMeshPosition position) const; 73 74 KUndo2Command* moveGradientHandle(const Handle &handle, const QPointF &newPos); 75 76 QPainterPath path() const; 77 QVector<QPainterPath> getConnectedPath(const Handle &handle) const; 78 79 private: 80 const SvgMeshGradient* gradient() const; 81 82 /// get handles including the corner 83 QVector<Handle> getHandles(const SvgMeshArray *mesharray, 84 SvgMeshPatch::Type type, 85 int row, 86 int col) const; 87 88 // get only bezier handles 89 QVector<Handle> getBezierHandles(const SvgMeshArray *mesharray, 90 SvgMeshPatch::Type type, 91 int row, 92 int col) const; 93 94 QTransform abosoluteTransformation(KoFlake::CoordinateSystem system) const; 95 96 private: 97 KoFlake::FillVariant m_fillVariant {KoFlake::Fill}; 98 KoShape *m_shape {0}; 99 }; 100 101 #endif // __KOSHAPEMESHGRADIENTHANDLES_H_ 102