20#include <QPainterPath>
30 , m_viewBoxOffset(0.0, 0.0)
31 , m_mirrorVertically(false)
32 , m_mirrorHorizontally(false)
33 , m_pathStretchPointX(-1)
34 , m_pathStretchPointY(-1)
35 , m_cacheResults(false)
41 m_viewBox(rhs.m_viewBox),
42 m_viewBound(rhs.m_viewBound),
43 m_viewMatrix(rhs.m_viewMatrix),
44 m_mirrorMatrix(rhs.m_mirrorMatrix),
45 m_viewBoxOffset(rhs.m_viewBoxOffset),
46 m_textArea(rhs.m_textArea),
47 m_commands(rhs.m_commands),
48 m_enhancedHandles(rhs.m_enhancedHandles),
49 m_formulae(rhs.m_formulae),
50 m_modifiers(rhs.m_modifiers),
51 m_parameters(rhs.m_parameters),
52 m_mirrorVertically(rhs.m_mirrorVertically),
53 m_mirrorHorizontally(rhs.m_mirrorHorizontally),
54 m_pathStretchPointX(rhs.m_pathStretchPointX),
55 m_pathStretchPointY(rhs.m_pathStretchPointY),
56 m_resultCache(rhs.m_resultCache),
57 m_cacheResults(rhs.m_cacheResults)
110 qreal stretchPointsScale = 1;
123 matrix.scale(stretchPointsScale, stretchPointsScale);
192 if (reference.isEmpty()) {
196 const char c = reference[0].toLatin1();
203 bool success =
false;
204 int modifierIndex = reference.mid(1).toInt(&success);
210 QString fname = reference.mid(1);
214 FormulaStore::const_iterator formulaIt =
m_formulae.constFind(fname);
240 qreal res = val.toDouble(&ok);
249 if (reference.isEmpty()) {
253 const char c = reference[0].toLatin1();
256 bool success =
false;
257 int modifierIndex = reference.mid(1).toInt(&success);
258 if (modifierIndex >= 0 && modifierIndex <
m_modifiers.count()) {
266 Q_ASSERT(! text.isEmpty());
268 ParameterStore::const_iterator parameterIt =
m_parameters.constFind(text);
270 return parameterIt.value();
273 const char c = text[0].toLatin1();
274 if (c ==
'$' || c ==
'?') {
277 bool success =
false;
278 qreal constant = text.toDouble(&success);
299 if (
name.isEmpty() || formula.isEmpty()) {
308 if (handle.isEmpty()) {
312 if (!handle.contains(
"draw:handle-position")) {
315 QVariant
position = handle.value(
"draw:handle-position");
318 if (tokens.count() < 2) {
326 if (handle.contains(
"draw:handle-polar")) {
327 QVariant polar = handle.value(
"draw:handle-polar");
328 QStringList tokens = polar.toString().simplified().split(
' ');
329 if (tokens.count() == 2) {
332 QVariant minRadius = handle.value(
"draw:handle-radius-range-minimum");
333 QVariant maxRadius = handle.value(
"draw:handle-radius-range-maximum");
334 if (minRadius.isValid() && maxRadius.isValid()) {
339 QVariant minX = handle.value(
"draw:handle-range-x-minimum");
340 QVariant maxX = handle.value(
"draw:handle-range-x-maximum");
341 if (minX.isValid() && maxX.isValid()) {
345 QVariant minY = handle.value(
"draw:handle-range-y-minimum");
346 QVariant maxY = handle.value(
"draw:handle-range-y-maximum");
347 if (minY.isValid() && maxY.isValid()) {
359 if (modifiers.isEmpty()) {
363 QStringList tokens = modifiers.simplified().split(
' ');
364 int tokenCount = tokens.count();
365 for (
int i = 0; i < tokenCount; ++i) {
377 QString commandStr = command.simplified();
378 if (commandStr.isEmpty()) {
386 commandStr = commandStr.mid(1).simplified();
389 if (!commandStr.isEmpty()) {
391 for (
int i = 0; i < tokens.count(); ++i) {
406 qreal scaleX =
size.width();
407 qreal scaleY =
size.height();
415 currPoint->
setPoint(QPointF(currPoint->
point().x() + deltaX, currPoint->
point().y()));
432 currPoint->
setPoint(QPointF(currPoint->
point().x(), currPoint->
point().y() + deltaY));
451 if (data.isEmpty()) {
456 bool separator =
true;
457 for (
int i = 0; i < data.length(); ++i) {
458 QChar ch = data.at(i);
459 ushort uni_ch = ch.unicode();
460 if (separator && (uni_ch ==
'M' || uni_ch ==
'L'
461 || uni_ch ==
'C' || uni_ch ==
'Z'
462 || uni_ch ==
'N' || uni_ch ==
'F'
463 || uni_ch ==
'S' || uni_ch ==
'T'
464 || uni_ch ==
'U' || uni_ch ==
'A'
465 || uni_ch ==
'B' || uni_ch ==
'W'
466 || uni_ch ==
'V' || uni_ch ==
'X'
467 || uni_ch ==
'Y' || uni_ch ==
'Q')) {
469 addCommand(data.mid(start, i - start),
false);
473 separator = ch.isSpace();
475 if (start < data.length()) {
504 if (!shape || shape ==
this) {
Identifier
the different possible identifiers, taken from the odf spec
@ IdentifierUnknown
unknown identifier
float value(const T *src, size_t ch)
bool execute()
Executes the command on the specified path shape.
void addParameter(EnhancedPathParameter *parameter)
Adds a new parameter to the command.
A constant parameter, a fixed value (i.e. 5, 11.3, -7)
void setPolarCenter(EnhancedPathParameter *polarX, EnhancedPathParameter *polarY)
void changePosition(const QPointF &position)
void setPosition(EnhancedPathParameter *positionX, EnhancedPathParameter *positionY)
void setRangeX(EnhancedPathParameter *minX, EnhancedPathParameter *maxX)
void setRangeY(EnhancedPathParameter *minY, EnhancedPathParameter *maxY)
void setRadiusRange(EnhancedPathParameter *minRadius, EnhancedPathParameter *maxRadius)
A named parameter, one that refers to a variable of the path.
static Identifier identifierFromString(const QString &text)
Returns identifier type from given string.
The abstract parameter class.
A referencing parameter, one that references another formula or a modifier.
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.
void setPathStretchPointX(qreal pathStretchPointX)
void addCommand(const QString &command)
Add command for instance "M 0 0".
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.
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
~EnhancedPathShape() override
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 ...
QPointF normalize() override
Normalizes the path data.
QList< QPointF > handles
the handles that the user can grab and change
int handleCount() const
return the number of handles set on the shape
void setSize(const QSizeF &size) override
reimplemented from KoShape
void setHandles(const QList< QPointF > &handles)
bool isParametricShape() const
Check if object is a parametric shape.
A KoPathPoint represents a point in a path.
void setControlPoint1(const QPointF &point)
Set the control point 1.
void setControlPoint2(const QPointF &point)
Set the control point 2.
void map(const QTransform &matrix)
apply matrix on the point
void setPoint(const QPointF &point)
alter the point
const KoSubpathList & subpaths() const
QSizeF size() const override
reimplemented
void notifyPointsChanged()
QPainterPath outline() const override
reimplemented
void clear()
Removes all subpaths and their points from the path.
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
ChangeType
Used by shapeChanged() to select which change was made.
@ ParentChanged
used after a setParent()
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
QPointF position() const
Get the position of the shape in pt.
void setPreferredTextRect(const QRectF &rect)