Krita Source Code Documentation
Loading...
Searching...
No Matches
EnhancedPathParameter.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
9#include "EnhancedPathShape.h"
10#include <KoShapeBackground.h>
11#include <KoUnit.h>
12#include <math.h>
13
14QString identifierData[] = {
15 "", // IdentifierUnknown
16 "pi", // IdentifierPi
17 "left", // IdentifierLeft
18 "top", // IdentifierTop
19 "right", // IdentifierRight
20 "bottom", // IdentifierBottom
21 "xstretch", // IdentifierXstretch
22 "ystretch", // IdentifierYstretch
23 "hasstroke", // IdentifierHasStroke
24 "hasfill", // IdentifierHasFill
25 "width", // IdentifierWidth
26 "height", // IdentifierHeight
27 "logwidth", // IdentifierLogwidth
28 "logheight" // IdentifierLogheight
29};
30
32 : m_parent(parent)
33{
34 Q_ASSERT(m_parent);
35}
36
40
45
47{
48 return 0.0;
49}
50
52{
53 Q_UNUSED(value);
54}
55
61
66
68{
69 return QString::number(m_value);
70}
71
73 : EnhancedPathParameter(parent)
74 , m_identifier(identifier)
75{
76}
77
83
85{
86 const QRect &viewBox = parent()->viewBox();
87
88 switch (m_identifier) {
89 case IdentifierPi:
90 return M_PI;
91 break;
92 case IdentifierLeft:
93 return viewBox.left();
94 break;
95 case IdentifierTop:
96 return viewBox.top();
97 break;
98 case IdentifierRight:
99 return viewBox.right();
100 break;
101 case IdentifierBottom:
102 return viewBox.bottom();
103 break;
105 break;
107 break;
109 return parent()->stroke() ? 1.0 : 0.0;
110 break;
112 return parent()->background() ? 0.0 : 1.0;
113 break;
114 case IdentifierWidth:
115 return viewBox.width();
116 break;
117 case IdentifierHeight:
118 return viewBox.height();
119 break;
121 // TODO: ? viewBox does not have any unit or const relation to mm
122 return KoUnit(KoUnit::Millimeter).toUserValue(viewBox.width()) * 100;
123 break;
125 // TODO: ? viewBox does not have any unit or const relation to mm
126 return KoUnit(KoUnit::Millimeter).toUserValue(viewBox.height()) * 100;
127 break;
128 default:
129 break;
130 }
131 return 0.0;
132}
133
135{
136 if (text.isEmpty()) {
137 return IdentifierUnknown;
138 } else if (text == "pi") {
139 return IdentifierPi;
140 } else if (text == "left") {
141 return IdentifierLeft;
142 } else if (text == "top") {
143 return IdentifierTop;
144 } else if (text == "right") {
145 return IdentifierRight;
146 } else if (text == "bottom") {
147 return IdentifierBottom;
148 } else if (text == "xstretch") {
149 return IdentifierXstretch;
150 } else if (text == "ystretch") {
151 return IdentifierYstretch;
152 } else if (text == "hasstroke") {
153 return IdentifierHasStroke;
154 } else if (text == "hasfill") {
155 return IdentifierHasFill;
156 } else if (text == "width") {
157 return IdentifierWidth;
158 } else if (text == "height") {
159 return IdentifierHeight;
160 } else if (text == "logwidth") {
161 return IdentifierLogwidth;
162 } else if (text == "logheight") {
163 return IdentifierLogheight;
164 } else {
165 return IdentifierUnknown;
166 }
167}
168
173
175 : EnhancedPathParameter(parent)
176 , m_reference(reference)
177{
178}
179
184
189
191{
192 return m_reference;
193}
194
QString identifierData[]
Identifier
the different possible identifiers, taken from the odf spec
@ IdentifierYstretch
The value of draw:path-stretchpoint-y is used.
@ IdentifierLogwidth
The width of the svg:viewBox in 1/100th mm is used.
@ IdentifierTop
top of svg:viewBox or draw:coordinate-origin-y
@ IdentifierRight
right of svg:viewBox or draw:coordinate-origin-x + draw:coordinate-width
@ IdentifierXstretch
The value of draw:path-stretchpoint-x is used.
@ IdentifierBottom
bottom of svg:viewBox or draw:coordinate-origin-y + draw:coordinate-height
@ IdentifierHasStroke
If the shape has a line style, a value of 1 is used.
@ IdentifierPi
value of pi.
@ IdentifierHasFill
If the shape has a fill style, a value of 1 is used.
@ IdentifierHeight
The height of the svg:viewBox is used.
@ IdentifierLogheight
The height of the svg:viewBox in 1/100th mm is used.
@ IdentifierLeft
left of svg:viewBox or draw:coordinate-origin-x
@ IdentifierWidth
The width of the svg:viewBox is used.
@ IdentifierUnknown
unknown identifier
float value(const T *src, size_t ch)
EnhancedPathConstantParameter(qreal value, EnhancedPathShape *parent)
Constructs the constant parameter with the given value.
qreal evaluate() override
evaluates the parameter using the given path
QString toString() const override
returns string representation of the parameter
EnhancedPathNamedParameter(Identifier identifier, EnhancedPathShape *parent)
Constructs named parameter from given identifier.
qreal evaluate() override
evaluates the parameter using the given path
QString toString() const override
returns string representation of the parameter
static Identifier identifierFromString(const QString &text)
Returns identifier type from given string.
Identifier m_identifier
the identifier type
The abstract parameter class.
virtual qreal evaluate()=0
evaluates the parameter using the given path
EnhancedPathParameter(EnhancedPathShape *parent)
virtual void modify(qreal value)
modifies the parameter if possible, using the new value
EnhancedPathShape * parent()
EnhancedPathShape * m_parent
QString m_reference
the reference, formula or modifier
void modify(qreal value) override
modifies the parameter if possible, using the new value
QString toString() const override
returns string representation of the parameter
qreal evaluate() override
evaluates the parameter using the given path
EnhancedPathReferenceParameter(const QString &reference, EnhancedPathShape *parent)
Constructs reference parameter from the given reference string.
qreal evaluateReference(const QString &reference)
void modifyReference(const QString &reference, qreal value)
QRect viewBox() const
Returns the viewbox of the enhanced path shape.
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926
@ Millimeter
Definition KoUnit.h:75
qreal toUserValue(qreal ptValue, bool rounding=true) const
Definition KoUnit.cpp:186
#define M_PI
Definition kis_global.h:111