File indexing completed on 2024-06-23 04:27:03

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOENHANCEDPATHPARAMETER_H
0008 #define KOENHANCEDPATHPARAMETER_H
0009 
0010 #include <QString>
0011 
0012 class EnhancedPathShape;
0013 
0014 /// the different possible identifiers, taken from the odf spec
0015 enum Identifier {
0016     IdentifierUnknown,   ///< unknown identifier
0017     IdentifierPi,        ///< value of pi.
0018     IdentifierLeft,      ///< left of svg:viewBox or draw:coordinate-origin-x
0019     IdentifierTop,       ///< top of svg:viewBox or draw:coordinate-origin-y
0020     IdentifierRight,     ///< right of svg:viewBox or draw:coordinate-origin-x + draw:coordinate-width
0021     IdentifierBottom,    ///< bottom of svg:viewBox or draw:coordinate-origin-y + draw:coordinate-height
0022     IdentifierXstretch,  ///< The value of draw:path-stretchpoint-x is used.
0023     IdentifierYstretch,  ///< The value of draw:path-stretchpoint-y is used.
0024     IdentifierHasStroke, ///< If the shape has a line style, a value of 1 is used.
0025     IdentifierHasFill,   ///< If the shape has a fill style, a value of 1 is used.
0026     IdentifierWidth,     ///< The width of the svg:viewBox is used.
0027     IdentifierHeight,    ///< The height of the svg:viewBox is used.
0028     IdentifierLogwidth,  ///< The width of the svg:viewBox in 1/100th mm is used.
0029     IdentifierLogheight  ///< The height of the svg:viewBox in 1/100th mm is used.
0030 };
0031 
0032 /// The abstract parameter class
0033 class EnhancedPathParameter
0034 {
0035 public:
0036     explicit EnhancedPathParameter(EnhancedPathShape *parent);
0037     virtual ~EnhancedPathParameter();
0038     /// evaluates the parameter using the given path
0039     virtual qreal evaluate() = 0;
0040     /// modifies the parameter if possible, using the new value
0041     virtual void modify(qreal value);
0042     /// returns string representation of the parameter
0043     virtual QString toString() const = 0;
0044 protected:
0045     EnhancedPathShape *parent();
0046 private:
0047     EnhancedPathShape *m_parent;
0048 };
0049 
0050 /// A constant parameter, a fixed value (i.e. 5, 11.3, -7)
0051 class EnhancedPathConstantParameter : public EnhancedPathParameter
0052 {
0053 public:
0054     /// Constructs the constant parameter with the given value
0055     EnhancedPathConstantParameter(qreal value, EnhancedPathShape *parent);
0056     qreal evaluate() override;
0057     QString toString() const override;
0058 private:
0059     qreal m_value; ///< the constant value
0060 };
0061 
0062 /// A named parameter, one that refers to a variable of the path
0063 class EnhancedPathNamedParameter : public EnhancedPathParameter
0064 {
0065 public:
0066     /// Constructs named parameter from given identifier
0067     EnhancedPathNamedParameter(Identifier identifier, EnhancedPathShape *parent);
0068     /// Constructs named parameter from given identifier string
0069     EnhancedPathNamedParameter(const QString &identifier, EnhancedPathShape *parent);
0070     qreal evaluate() override;
0071     /// Returns identifier type from given string
0072     static Identifier identifierFromString(const QString &text);
0073     QString toString() const override;
0074 private:
0075     Identifier m_identifier; ///< the identifier type
0076 };
0077 
0078 /// A referencing parameter, one that references another formula or a modifier
0079 class EnhancedPathReferenceParameter : public EnhancedPathParameter
0080 {
0081 public:
0082     /// Constructs reference parameter from the given reference string
0083     explicit EnhancedPathReferenceParameter(const QString &reference, EnhancedPathShape *parent);
0084     qreal evaluate() override;
0085     void modify(qreal value) override;
0086     QString toString() const override;
0087 private:
0088     QString m_reference; ///< the reference, formula or modifier
0089 };
0090 
0091 #endif // KOENHANCEDPATHPARAMETER_H