Krita Source Code Documentation
Loading...
Searching...
No Matches
EnhancedPathShape.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2007, 2010, 2011 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2010 Carlos Licea <carlos@kdab.com>
4 * SPDX-FileCopyrightText: 2010 Nokia Corporation and /or its subsidiary(-ies).
5 * Contact: Suresh Chande suresh.chande@nokia.com
6 *
7 * SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
10#ifndef KOENHANCEDPATHSHAPE_H
11#define KOENHANCEDPATHSHAPE_H
12
13#include <KoParameterShape.h>
14#include <QList>
15#include <QMap>
16#include <QRectF>
17#include <QStringList>
18
19#define EnhancedPathShapeId "EnhancedPathShape"
20
27
38{
39public:
40 EnhancedPathShape(const QRect &viewBox);
41 ~EnhancedPathShape() override;
42
43 KoShape* cloneShape() const override;
44
50 qreal evaluateReference(const QString &reference);
51
58 qreal evaluateConstantOrReference(const QString &val);
59
68 void modifyReference(const QString &reference, qreal value);
69
70 // from KoShape
71 void setSize(const QSizeF &newSize) override;
72 // from KoParameterShape
73 QPointF normalize() override;
74
76 void addFormula(const QString &name, const QString &formula);
77
79 void addHandle(const QMap<QString, QVariant> &handle);
80
82 void addModifiers(const QString &modifiers);
83
85 void addCommand(const QString &command);
86
88 QRect viewBox() const;
89
91 QPointF shapeToViewbox(const QPointF &point) const;
92
94 //NOTE: in the standard nothing is mentioned about the priorities of the transformations"
95 //it's assumed like this because of the behavior shown in OOo
96 void setMirrorHorizontally(bool mirrorHorizontally);
97
99 //NOTE: in the standard nothing is mentioned about the priorities of the transformations"
100 //it's assumed like this because of the behavior shown in OOo
101 void setMirrorVertically(bool mirrorVertically);
102
103 // Sets member variable representing draw:path-stretchpoint-x attribute
104 void setPathStretchPointX(qreal pathStretchPointX);
105
106 // Sets member variable representing draw:path-stretchpoint-y attribute
107 void setPathStretchPointY(qreal pathStretchPointY);
108
110 EnhancedPathParameter *parameter(const QString &text);
111
112protected:
113 //from KoShape
114 void shapeChanged(ChangeType type, KoShape *shape = 0) override;
115 // from KoParameterShape
116 void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override;
117 // from KoParameterShape
118 void updatePath(const QSizeF &size) override;
119
120private:
122
123 void evaluateHandles();
124 void reset();
125
127 void parsePathData(const QString &data);
128
130 void addCommand(const QString &command, bool triggerUpdate);
131
133 void updateTextArea();
134
136 void enableResultCache(bool enable);
137
138 // This function checks if draw:path-stretchpoint-x or draw:path-stretchpoint-y attributes are set.
139 // If the attributes are set the path shape coordinates (m_subpaths) are changed so that the form
140 // of the shape is preserved after stretching. It is needed for example in round-rectangles, to
141 // have the corners round after stretching. Without it the corners would be elliptical.
142 // Returns true if any points were actually changed, otherwise false.
143 bool useStretchPoints(const QSizeF &size, qreal &scale);
144
145 typedef QMap<QString, EnhancedPathFormula *> FormulaStore;
147 typedef QMap<QString, EnhancedPathParameter *> ParameterStore;
148
149 QRect m_viewBox;
150 QRectF m_viewBound;
151 QTransform m_viewMatrix;
152 QTransform m_mirrorMatrix;
164 QHash<QString, qreal> m_resultCache;
166};
167
168#endif // KOENHANCEDPATHSHAPE_H
float value(const T *src, size_t ch)
The abstract parameter class.
ParameterStore m_parameters
the shared parameters
bool m_cacheResults
indicates if result cache is enabled
QList< EnhancedPathHandle * > m_enhancedHandles
the handles for modifying the shape
bool m_mirrorHorizontally
whether or not the shape is to be mirrored horizontally before transforming it
void updateTextArea()
Updates the size and position of an optionally existing text-on-shape text area.
QMap< QString, EnhancedPathParameter * > ParameterStore
void setPathStretchPointX(qreal pathStretchPointX)
void addCommand(const QString &command)
Add command for instance "M 0 0".
QMap< QString, EnhancedPathFormula * > FormulaStore
void parsePathData(const QString &data)
parses the enhanced path data
void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier) override
Updates the internal state of a KoParameterShape.
QList< qreal > ModifierStore
void setMirrorVertically(bool mirrorVertically)
Sets if the shape is to be mirrored vertically before applying any other transformations.
void addHandle(const QMap< QString, QVariant > &handle)
Add a single handle with format: x y minX maxX minY maxY.
qreal evaluateConstantOrReference(const QString &val)
FormulaStore m_formulae
the formulae
void setPathStretchPointY(qreal pathStretchPointY)
EnhancedPathShape(const QRect &viewBox)
QPointF shapeToViewbox(const QPointF &point) const
Converts from shape coordinates to viewbox coordinates.
void setMirrorHorizontally(bool mirrorHorizontally)
Sets if the shape is to be mirrored horizontally before applying any other transformations.
qreal m_pathStretchPointX
draw:path-stretchpoint-x attribute
QRectF m_viewBound
the bounding box of the path in viewbox coordinates
QTransform m_mirrorMatrix
matrix to used for mirroring
QList< EnhancedPathCommand * > m_commands
the commands creating the outline
QTransform m_viewMatrix
matrix to convert from viewbox coordinates to shape coordinates
void setSize(const QSizeF &newSize) override
Resize the shape.
ModifierStore m_modifiers
the modifier values
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
bool m_mirrorVertically
whether or not the shape is to be mirrored vertically before transforming it
void addFormula(const QString &name, const QString &formula)
Add formula with given name and textual representation.
EnhancedPathParameter * parameter(const QString &text)
Returns parameter from given textual representation.
qreal evaluateReference(const QString &reference)
void modifyReference(const QString &reference, qreal value)
KoShape * cloneShape() const override
creates a deep copy of the shape or shape's subtree
QRect m_viewBox
the viewbox rectangle
void shapeChanged(ChangeType type, KoShape *shape=0) override
bool useStretchPoints(const QSizeF &size, qreal &scale)
QPointF normalize() override
Normalizes the path data.
void enableResultCache(bool enable)
Enables caching results.
QRect viewBox() const
Returns the viewbox of the enhanced path shape.
QHash< QString, qreal > m_resultCache
cache for intermediate results used when evaluating path
qreal m_pathStretchPointY
draw:path-stretchpoint-y attribute
void addModifiers(const QString &modifiers)
Add modifiers with format: modifier0 modifier1 modifier2 ...
QSizeF size() const override
reimplemented
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:237
QString name() const
Definition KoShape.cpp:1150