File indexing completed on 2024-06-23 04:28:11
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com> 0003 * SPDX-FileCopyrightText: 2020 Sharaf Zaman <sharafzaz121@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef __KOSHAPEMESHGRADIENTHANDLES_H_ 0009 #define __KOSHAPEMESHGRADIENTHANDLES_H_ 0010 0011 #include <QPointF> 0012 #include <KoFlake.h> 0013 0014 #include <SvgMeshGradient.h> 0015 0016 class KUndo2Command; 0017 0018 class KoShapeMeshGradientHandles { 0019 public: 0020 struct Handle { 0021 enum Type { 0022 None, 0023 Corner, 0024 BezierHandle 0025 }; 0026 0027 enum Index { 0028 First = 1, 0029 Second 0030 }; 0031 0032 Handle() : type(None) {} 0033 Handle(Type t, const QPointF &p, int row, int col, SvgMeshPatch::Type segmentType, Index index = First) 0034 : type(t) , pos(p) 0035 , row(row) , col(col) 0036 , segmentType(segmentType) 0037 , index(index) 0038 { 0039 } 0040 0041 SvgMeshPosition getPosition() const { 0042 return SvgMeshPosition {row, col, segmentType}; 0043 } 0044 0045 Type type {None}; 0046 QPointF pos; 0047 int row {0}; 0048 int col {0}; 0049 SvgMeshPatch::Type segmentType {SvgMeshPatch::Top}; 0050 Index index { First }; // first or the second bezier handle 0051 }; 0052 0053 public: 0054 KoShapeMeshGradientHandles(KoFlake::FillVariant fillVariant, KoShape *shape); 0055 0056 /// get all nodes in the mesh, don't use this for drawing the path but use path() 0057 QVector<Handle> handles() const; 0058 0059 /// convenience method to get a handle by its position in the mesharray 0060 Handle getHandle(SvgMeshPosition position) const; 0061 0062 KUndo2Command* moveGradientHandle(const Handle &handle, const QPointF &newPos); 0063 0064 QPainterPath path() const; 0065 QVector<QPainterPath> getConnectedPath(const Handle &handle) const; 0066 0067 /// get the attached corner node of the bezierHandle 0068 QPointF getAttachedCorner(const Handle &bezierHandle) const; 0069 0070 private: 0071 const SvgMeshGradient* gradient() const; 0072 0073 /// get handles including the corner 0074 QVector<Handle> getHandles(const SvgMeshArray *mesharray, 0075 SvgMeshPatch::Type type, 0076 int row, 0077 int col) const; 0078 0079 // get only bezier handles 0080 QVector<Handle> getBezierHandles(const SvgMeshArray *mesharray, 0081 SvgMeshPatch::Type type, 0082 int row, 0083 int col) const; 0084 0085 QTransform absoluteTransformation(KoFlake::CoordinateSystem system) const; 0086 0087 private: 0088 KoFlake::FillVariant m_fillVariant {KoFlake::Fill}; 0089 KoShape *m_shape {0}; 0090 }; 0091 0092 #endif // __KOSHAPEMESHGRADIENTHANDLES_H_