1 /*
2  *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KIS_ABR_TRANSLATOR_H
20 #define KIS_ABR_TRANSLATOR_H
21 
22 
23 #include <QString>
24 #include <QDomDocument>
25 const QString ABR_PRESET_START = "START";
26 
27 const QString ABR_OBJECT = "Objc";
28 const QString ABR_PRESET_NAME = "Nm  ";
29 const QString ABR_BRUSH_DIAMETER = "Dmtr";
30 const QString ABR_BRUSH_HARDNESS = "Hrdn";
31 const QString ABR_BRUSH_ANGLE = "Angl";
32 const QString ABR_BRUSH_ROUNDNESS = "Rndn";
33 const QString ABR_BRUSH_SPACING = "Spcn";
34 const QString ABR_BRUSH_INTR = "Intr";
35 const QString ABR_FLIP_X = "flipX";
36 const QString ABR_FLIP_Y = "flipY";
37 const QString ABR_USE_TIP_DYNAMICS = "useTipDynamics";
38 const QString ABR_TIP_DYNAMICS_MINUMUM_DIAMETER = "minimumDiameter";
39 const QString ABR_TIP_DYNAMICS_MINUMUM_ROUNDNESS = "minimumRoundness";
40 const QString ABR_TIP_DYNAMICS_TILT_SCALE = "tiltScale";
41 const QString ABR_SZVR = "szVr"; // size variance?
42 const QString ABR_DYNAMICS_FADE_STEP = "fStp";
43 const QString ABR_DYNAMICS_JITTER = "jitter";
44 const QString ABR_ANGLE_DYNAMICS = "angleDynamics";
45 const QString ABR_CONTROL = "bVTy"; // control of the attribute
46 const QString ABR_ROUNDNESS_DYNAMICS = "roundnessDynamics";
47 const QString ABR_USE_SCATTER = "useScatter";
48 const QString ABR_DUAL_BRUSH = "dualBrush";
49 const QString ABR_USE_DUAL_BRUSH = "useDualBrush";
50 const QString ABR_BRUSH_GROUP = "brushGroup";
51 const QString ABR_USE_BRUSH_GROUP = "useBrushGroup";
52 const QString ABR_USE_TEXTURE = "useTexture";
53 const QString ABR_USE_PAINT_DYNAMICS = "usePaintDynamics";
54 const QString ABR_USE_COLOR_DYNAMICS = "useColorDynamics";
55 const QString ABR_WET_EDGES = "Wtdg";
56 const QString ABR_NOISE = "Nose";
57 const QString ABR_AIRBRUSH = "Rpt "; // repeat
58 
59 // TODO: if string comparisons would be slow, convert it to enum
60 enum enumObjectTypes {BRUSH_PRESET, BRUSH, SIZE_VARIANCE, ANGLE_DYNAMICS, ROUNDNESS_DYNAMICS, DUAL_BRUSH, COUNT_DYNAMICS, SCATTER_DYNAMICS, BRUSH_GROUP};
61 const QString OBJECT_NAME_BRUSH_PRESET = "";
62 const QString OBJECT_NAME_BRUSH = "Brsh";
63 const QString OBJECT_NAME_SIZE_VARIANCE = "szVr";
64 const QString OBJECT_NAME_ANGLE_DYNAMICS = "angleDynamics";
65 const QString OBJECT_NAME_ROUNDNESS_DYNAMICS = "roundnessDynamics";
66 const QString OBJECT_NAME_DUAL_BRUSH = "dualBrush";
67 const QString OBJECT_NAME_COUNT_DYNAMICS = "countDynamics";
68 const QString OBJECT_NAME_SCATTER_DYNAMICS = "scatterDynamics";
69 const QString OBJECT_NAME_BRUSH_GROUP = "brushGroup";
70 const QString OBJECT_NAME_FLOW_JITTER = "prVr";
71 const QString OBJECT_NAME_OPACITY_VARIANCE = "opVr";
72 
73 const QString BRUSH_TYPE_COMPUTED = "computedBrush";
74 const QString BRUSH_TYPE_SAMPLED = "sampledBrush";
75 
76 enum enumAbrControllers { OFF, FADE, PEN_PRESSURE, PEN_TILT, STYLUS_WHEEL, ROTATION, INITIAL_DIRECTION, DIRECTION};
77 
78 
79 class AbrBrushProperties
80 {
81 public:
82     void toXML(QDomDocument& , QDomElement&) const;
83     void setupProperty(const QString &attributeName, const QString &type, const  QString &value);
84     void reset();
85 private:
86     double m_diameter;
87     double m_hardness;
88     double m_angle;
89     double m_roundness;
90     double m_spacing;
91     bool m_intr;
92     bool m_flipX;
93     bool m_flipY;
94 
95     QString m_brushType;
96 };
97 
98 
99 class AbrGroupProperties
100 {
101 public:
102     void setupProperty(const QString &attributeName, const QString &type, const  QString &value);
103 
104     enumAbrControllers m_bVTy;
105     int m_fadeStep;
106     double m_sizeJitter;
107 };
108 
109 #include <QHash>
110 
111 class AbrTipDynamicsProperties
112 {
113 public:
114     AbrTipDynamicsProperties();
115     void toXML(QDomDocument& , QDomElement&) const;
116     void setupProperty(const QString &attributeName, const QString &type, const  QString &value);
reset()117     void reset() {
118         m_groupType.clear();
119     }
120 private:
121     bool m_useTipDynamics;
122     bool m_flipX;
123     bool m_flipY;
124     double m_minumumDiameter;
125     double m_minumumRoundness;
126     double m_tiltScale;
127 
128     AbrGroupProperties m_sizeVarianceProperties;
129     AbrGroupProperties m_angleProperties;
130     AbrGroupProperties m_RoundnessProperties;
131 
132     QString m_groupType;
133 
134     QHash<QString, AbrGroupProperties*> m_groups;
135 };
136 
137 
138 class AbrDualBrushProperties
139 {
140 public:
141     bool useDualBrush;
142     void toXML(QDomDocument& , QDomElement&) const;
143 };
144 
145 class AbrBrushGroupProperties
146 {
147 public:
148     bool useBrushGroup;
149     bool useTexture;
150     bool usePaintDynamics;
151     bool useColorDynamics;
152     bool wetEdges;
153     bool noise;
154     bool repeat;
155     void toXML(QDomDocument& , QDomElement&) const;
156 };
157 
158 class KisAbrTranslator
159 {
160 public:
161     KisAbrTranslator();
162     ~KisAbrTranslator();
163 
164 
165     void addEntry(const QString &attributeName, const QString &type, const  QString &value);
166 
167     QString toString();
168     void finishPreset();
169     void clean();
170 
171 private:
172     void init();
173     void setupObjectType(const QString &type);
174     void setupBrush(const QString &attributeName, const QString &type, const  QString &value);
175 private:
176     QDomDocument m_doc;
177     QDomElement m_root;
178     QString m_currentObjectName;
179     AbrBrushProperties m_abrBrushProperties;
180     AbrTipDynamicsProperties m_abrTipDynamics;
181 };
182 
183 #endif
184