Krita Source Code Documentation
Loading...
Searching...
No Matches
KarbonCalligraphicShape.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2008 Fela Winkelmolen <fela.kde@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KARBONCALLIGRAPHICSHAPE_H
8#define KARBONCALLIGRAPHICSHAPE_H
9
10#include <KoParameterShape.h>
11#include <QDebug>
12
13#define KarbonCalligraphicShapeId "KarbonCalligraphicShape"
14
16{
17public:
18 KarbonCalligraphicPoint(const QPointF &point, qreal angle, qreal width)
20
23
24 bool operator==(const KarbonCalligraphicPoint &rhs) const {
25 return m_point == rhs.m_point &&
28 }
29
30 QPointF point() const
31 {
32 return m_point;
33 }
34 qreal angle() const
35 {
36 return m_angle;
37 }
38 qreal width() const
39 {
40 return m_width;
41 }
42
43 void setPoint(const QPointF &point)
44 {
45 m_point = point;
46 }
47 void setAngle(qreal angle)
48 {
49 m_angle = angle;
50 }
51
52private:
53 QPointF m_point; // in shape coordinates
54 qreal m_angle = 0.0;
55 qreal m_width = 0.0;
56};
57
58inline QDebug operator<<(QDebug dbg, const KarbonCalligraphicPoint &pt)
59{
60 dbg.nospace() << "(" << pt.point() << ", a: " << pt.angle() << ", w: " << pt.width() << ")";
61 return dbg.space();
62}
63
64/*class KarbonCalligraphicShape::Point
65{
66public:
67 KoPainterPath(KoPathPoint *point) : m_prev(point), m_next(0) {}
68
69 // calculates the effective point
70 QPointF point() {
71 if (m_next = 0)
72 return m_prev.point();
73
74 // m_next != 0
75 qDebug() << "not implemented yet!!!!";
76 return QPointF();
77 }
78
79private:
80 KoPainterPath m_prev;
81 KoPainterPath m_next;
82 qreal m_percentage;
83};*/
84
85// the indexes of the path will be similar to:
86// 7--6--5--4 <- pointCount() / 2
87// start | | end ==> (direction of the stroke)
88// 0--1--2--3
90{
91public:
92 explicit KarbonCalligraphicShape(qreal caps = 0.0);
93 ~KarbonCalligraphicShape() override;
94
95 KoShape* cloneShape() const override;
96
97 void appendPoint(const QPointF &p1, qreal angle, qreal width);
99
100 // returns the bounding rect of what needs to be repainted
101 // after new points are added
102 const QRectF lastPieceBoundingRect();
103
104 void setSize(const QSizeF &newSize) override;
105 //virtual QPointF normalize();
106
107 QPointF normalize() override;
108
109 void simplifyPath();
110
111 void simplifyGuidePath();
112
113 // reimplemented
114 QString pathShapeId() const override;
115
116protected:
117 // reimplemented
118 void moveHandleAction(int handleId,
119 const QPointF &point,
120 Qt::KeyboardModifiers modifiers = Qt::NoModifier) override;
121
122 // reimplemented
123 void updatePath(const QSizeF &size) override;
124
125private:
127
128 // auxiliary function that actually inserts the points
129 // without doing any additional checks
130 // the points should be given in canvas coordinates
131 void appendPointsToPathAux(const QPointF &p1, const QPointF &p2);
132
133 // function to detect a flip, given the points being inserted
134 bool flipDetected(const QPointF &p1, const QPointF &p2);
135
136 void smoothLastPoints();
137 void smoothPoint(const int index);
138
139 // determine whether the points given are in counterclockwise order or not
140 // returns +1 if they are, -1 if they are given in clockwise order
141 // and 0 if they form a degenerate triangle
142 static int ccw(const QPointF &p1, const QPointF &p2, const QPointF &p3);
143
144 //
145 void addCap(int index1, int index2, int pointIndex, bool inverted = false);
146
147 struct Private;
148 QSharedDataPointer<Private> s;
149};
150
151#endif // KARBONCALLIGRAPHICSHAPE_H
152
QDebug operator<<(QDebug dbg, const KarbonCalligraphicPoint &pt)
const Params2D p
QPointF p2
QPointF p3
QPointF p1
bool operator==(const KarbonCalligraphicPoint &rhs) const
KarbonCalligraphicPoint()=default
KarbonCalligraphicPoint(const QPointF &point, qreal angle, qreal width)
KarbonCalligraphicPoint(const KarbonCalligraphicPoint &rhs)=default
void setPoint(const QPointF &point)
void setSize(const QSizeF &newSize) override
Resize the shape.
KoShape * cloneShape() const override
creates a deep copy of the shape or shape's subtree
void appendPointsToPathAux(const QPointF &p1, const QPointF &p2)
void appendPoint(const QPointF &p1, qreal angle, qreal width)
static int ccw(const QPointF &p1, const QPointF &p2, const QPointF &p3)
bool flipDetected(const QPointF &p1, const QPointF &p2)
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
QString pathShapeId() const override
void addCap(int index1, int index2, int pointIndex, bool inverted=false)
void appendPointToPath(const KarbonCalligraphicPoint &p)
QPointF normalize() override
Normalizes the path data.
void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier) override
Updates the internal state of a KoParameterShape.
QSharedDataPointer< Private > s
QSizeF size() const override
reimplemented
static bool qFuzzyCompare(half p1, half p2)