All Classes Namespaces Functions Variables Enumerations Properties Pages
vectorimage.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #ifndef VECTORIMAGE_H
18 #define VECTORIMAGE_H
19 
20 #include <QTransform>
21 
22 #include "bezierarea.h"
23 #include "beziercurve.h"
24 #include "vertexref.h"
25 #include "keyframe.h"
26 
27 class Object;
28 class QPainter;
29 class QImage;
30 
31 
32 class VectorImage : public KeyFrame
33 {
34 public:
35  VectorImage();
36  VectorImage(const VectorImage&);
37  ~VectorImage() override;
38  VectorImage& operator=(const VectorImage& a);
39 
40  VectorImage* clone() const override;
41 
42  void setObject(Object* pObj) { mObject = pObj; }
43 
44  bool read(QString filePath);
45  Status write(QString filePath, QString format);
46 
48  void loadDomElement(QDomElement element);
49 
50  BezierCurve& curve(int i);
51 
52  void insertCurve(int position, BezierCurve& newCurve, qreal factor, bool interacts);
53  void addCurve(BezierCurve& newCurve, qreal factor, bool interacts = true);
54  void removeCurveAt(int i);
55  void select(QRectF rectangle);
56  void setSelected(int curveNumber, bool YesOrNo);
57  void setSelected(int curveNumber, int vertexNumber, bool YesOrNo);
58  void setSelected(VertexRef vertexRef, bool YesOrNo);
59  void setSelected(QList<int> curveList, bool YesOrNo);
60  void setSelected(QList<VertexRef> vertexList, bool YesOrNo);
61  bool isSelected(int curveNumber);
62  bool isSelected(int curveNumber, int vertexNumber);
63  bool isSelected(VertexRef vertexRef);
64  bool isSelected(QList<int> curveList);
65  bool isSelected(QList<VertexRef> vertexList);
66  bool isAnyCurveSelected();
67  void setAreaSelected(int areaNumber, bool YesOrNo);
68  bool isAreaSelected(int areaNumber);
69  bool isPathFilled();
70 
74  void selectAll();
75  void deselectAll();
76  QRectF getSelectionRect() { return mSelectionRect; }
77  void setSelectionRect(QRectF rectange);
79  void deleteSelection();
80  void deleteSelectedPoints();
81  void removeVertex(int curve, int vertex);
82 
83  bool isEmpty() const { return mCurves.isEmpty(); }
84 
85  void paste(VectorImage&);
86 
87  QColor getColor(int i);
88  int getColorNumber(QPointF point);
89  bool usesColor(int index);
90  void removeColor(int index);
91  int getCurvesColor(int curve);
92  bool isCurveVisible(int curve);
93  void moveColor(int start, int end);
94 
95  void paintImage(QPainter& painter, bool simplified, bool showThinCurves, bool antialiasing);
96  void outputImage(QImage* image, QTransform myView, bool simplified, bool showThinCurves, bool antialiasing); // uses paintImage
97 
98  void clear();
99  void clean();
100  void setSelectionTransformation(QTransform transform);
103  void applyColorToSelectedCurve(int colorNumber);
104  void applyColorToSelectedArea(int colorNumber);
105  void applyWidthToSelection(qreal width);
106  void applyFeatherToSelection(qreal feather);
107  void applyOpacityToSelection(qreal opacity);
108  void applyInvisibilityToSelection(bool YesOrNo);
109  void applyVariableWidthToSelection(bool YesOrNo);
110  void fillContour(QList<QPointF> contourPath, int color);
111  void fillSelectedPath(int color);
112  // void fill(QPointF point, int color, float tolerance);
113  void addArea(BezierArea bezierArea);
114  int getFirstAreaNumber(QPointF point);
115  int getLastAreaNumber(QPointF point);
116  int getLastAreaNumber(QPointF point, int maxAreaNumber);
117  int getLastCurveNumber();
119  void removeArea(QPointF point);
120  void removeAreaInCurve(int curve, int areaNumber);
121  void updateArea(BezierArea& bezierArea);
122 
123  QList<int> getCurvesCloseTo(QPointF thisPoint, qreal maxDistance);
126  BezierArea getSelectedArea(QPointF currentPoint);
127  VertexRef getClosestVertexTo(const BezierCurve& curve, int curveNum, QPointF thisPoint);
128  QList<VertexRef> getCurveVertices(int curveNumber);
129  QList<VertexRef> getVerticesCloseTo(QPointF thisPoint, qreal maxDistance);
130  QList<VertexRef> getVerticesCloseTo(QPointF thisPoint, qreal maxDistance, QList<VertexRef>* listOfPoints);
131  QList<VertexRef> getVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance);
132  QList<VertexRef> getVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance, QList<VertexRef>* listOfPoints);
133  QList<VertexRef> getAndRemoveVerticesCloseTo(QPointF thisPoint, qreal maxDistance, QList<VertexRef>* listOfPoints);
134  QList<VertexRef> getAndRemoveVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance, QList<VertexRef>* listOfPoints);
135  QPointF getVertex(int curveNumber, int vertexNumber);
136  QPointF getVertex(VertexRef vertexRef);
137  QPointF getC1(int curveNumber, int vertexNumber);
138  QPointF getC1(VertexRef vertexRef);
139  QPointF getC2(int curveNumber, int vertexNumber);
140  QPointF getC2(VertexRef vertexRef);
142  int getCurveSize(int curveNumber);
143 
144  QPainterPath getStrokedPath() { return mGetStrokedPath; }
145 
146  QList<BezierArea> mArea;
147  QList<int> mCurveDisplayOrders;
148 
149  qreal getDistance(VertexRef r1, VertexRef r2);
150 
151  QSize getSize() { return mSize; }
152 
153  void setOpacity(qreal opacity) { mOpacity = opacity; }
154  qreal getOpacity() const { return mOpacity; }
155 
156 private:
157  void addPoint(int curveNumber, int vertexNumber, qreal fraction);
158 
159  void checkCurveExtremity(BezierCurve& newCurve, qreal tolerance);
160  void checkCurveIntersections(BezierCurve& newCurve, qreal tolerance);
161 
162  void updateImageSize(BezierCurve& updatedCurve);
163  QPainterPath mGetStrokedPath;
164 
165 private:
166  QList<BezierCurve> mCurves;
167 
168  Object* mObject = nullptr;
169  QRectF mSelectionRect;
170  QTransform mSelectionTransformation;
171  QSize mSize;
172  qreal mOpacity = 1.0;
173 };
174 
175 #endif
176 
QList< VertexRef > getAllVertices()
VectorImage::getAllVertices.
void insertCurve(int position, BezierCurve &newCurve, qreal factor, bool interacts)
VectorImage::insertCurve.
void updateArea(BezierArea &bezierArea)
VectorImage::updateArea.
void paintImage(QPainter &painter, bool simplified, bool showThinCurves, bool antialiasing)
VectorImage::paintImage.
int getFirstSelectedCurve()
VectorImage::getFirstSelectedCurve.
qreal getDistance(VertexRef r1, VertexRef r2)
VectorImage::getDistance.
int getNumOfCurvesSelected()
VectorImage::numOfCurvesSelected.
void applyColorToSelectedArea(int colorNumber)
VectorImage::applyColorToSelectedArea.
void checkCurveIntersections(BezierCurve &newCurve, qreal tolerance)
VectorImage::checkCurveIntersections.
void applyInvisibilityToSelection(bool YesOrNo)
VectorImage::applyInvisibilityToSelection.
void checkCurveExtremity(BezierCurve &newCurve, qreal tolerance)
VectorImage::checkCurveExtremity.
int getCurveSize(int curveNumber)
VectorImage::getCurveSize.
int getLastAreaNumber(QPointF point)
VectorImage::getLastAreaNumber.
void clear()
VectorImage::clear.
void calculateSelectionRect()
VectorImage::calculateSelectionRect.
bool isPathFilled()
VectorImage::isPathFilled.
QList< VertexRef > getVerticesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getVerticesCloseTo.
bool read(QString filePath)
VectorImage::read.
Definition: vectorimage.cpp:74
int getCurvesColor(int curve)
VectorImage::getCurvesColor.
QList< int > getCurvesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getCurvesCloseTo.
void loadDomElement(QDomElement element)
VectorImage::loadDomElement.
void fillSelectedPath(int color)
VectorImage::fillSelectedPath.
void fillContour(QList< QPointF > contourPath, int color)
VectorImage::fillContour.
void deselectAll()
VectorImage::deselectAll.
void applyVariableWidthToSelection(bool YesOrNo)
VectorImage::applyVariableWidthToSelection.
QPointF getC1(int curveNumber, int vertexNumber)
VectorImage::getC1.
BezierCurve getLastCurve()
VectorImage::getLastCurve.
QList< BezierCurve > getSelectedCurves()
VectorImage::getSelectedCurve.
void removeAreaInCurve(int curve, int areaNumber)
VectorImage::removeAreaInCurve.
int getColorNumber(QPointF point)
VectorImage::getColorNumber.
void selectAll()
VectorImage::selectAll.
int getFirstSelectedArea()
VectorImage::getFirstSelectedArea.
void addPoint(int curveNumber, int vertexNumber, qreal fraction)
VectorImage::addPoint.
void removeVertex(int curve, int vertex)
VectorImage::removeVertex.
bool isAnyCurveSelected()
VectorImage::isAnyCurveSelected.
bool isEmpty() const const
QPointF getVertex(int curveNumber, int vertexNumber)
VectorImage::getVertex.
bool isSelected(int curveNumber)
VectorImage::isSelected.
QList< VertexRef > getCurveVertices(int curveNumber)
VectorImage::getCurveVertices.
bool usesColor(int index)
VectorImage::usesColor.
void addCurve(BezierCurve &newCurve, qreal factor, bool interacts=true)
VectorImage::addCurve.
QColor getColor(int i)
VectorImage::getColor.
void clean()
VectorImage::clean.
void deleteSelectedPoints()
VectorImage::deleteSelectedPoints.
void applyWidthToSelection(qreal width)
VectorImage::applyWidthToSelection.
BezierArea getSelectedArea(QPointF currentPoint)
VectorImage::getSelectedArea.
void removeArea(QPointF point)
VectorImage::removeArea.
int getFirstAreaNumber(QPointF point)
VectorImage::getFirstAreaNumber.
Status write(QString filePath, QString format)
VectorImage::write.
void applyColorToSelectedCurve(int colorNumber)
VectorImage::applyColorToSelectedCurve.
QPointF getC2(int curveNumber, int vertexNumber)
VectorImage::getC2.
void setSelectionTransformation(QTransform transform)
VectorImage::setSelectionTransformation.
bool isAreaSelected(int areaNumber)
VectorImage::isAreaSelected.
void updateImageSize(BezierCurve &updatedCurve)
VectorImage::updateImageSize.
void paste(VectorImage &)
VectorImage::paste.
void setAreaSelected(int areaNumber, bool YesOrNo)
VectorImage::setAreaSelected.
void addArea(BezierArea bezierArea)
VectorImage::addArea.
void applyFeatherToSelection(qreal feather)
VectorImage::applyFeatherToSelection.
QList< VertexRef > getAndRemoveVerticesCloseTo(QPointF thisPoint, qreal maxDistance, QList< VertexRef > *listOfPoints)
VectorImage::getAndRemoveVerticesCloseTo.
void removeCurveAt(int i)
VectorImage::removeCurveAt.
Status createDomElement(QXmlStreamWriter &doc)
VectorImage::createDomElement.
QList< int > getSelectedCurveNumbers()
VectorImage::getSelectedCurveNumber.
void applySelectionTransformation()
VectorImage::applySelectionTransformation.
Definition: object.h:41
int getLastCurveNumber()
VectorImage::getLastCurveNumber.
void removeColor(int index)
VectorImage::removeColor.
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.
void applyOpacityToSelection(qreal opacity)
VectorImage::applyOpacityToSelection.
void outputImage(QImage *image, QTransform myView, bool simplified, bool showThinCurves, bool antialiasing)
VectorImage::outputImage.
void deleteSelection()
VectorImage::deleteSelection.
VertexRef getClosestVertexTo(const BezierCurve &curve, int curveNum, QPointF thisPoint)
VectorImage::getClosestVertexTo.
void setSelectionRect(QRectF rectange)
VectorImage::setSelectionRect.