Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_grid_config.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_GRID_CONFIG_H
8#define __KIS_GRID_CONFIG_H
9
10#include <QMetaType>
11
12#include <QPoint>
13#include <QColor>
14#include <QPen>
15
16#include <boost/operators.hpp>
17#include "kritaui_export.h"
18
19class QDomElement;
20class QDomDocument;
21
22
23class KRITAUI_EXPORT KisGridConfig : boost::equality_comparable<KisGridConfig>
24{
25public:
27 LINE_SOLID = 0,
30 LINE_NONE
31 };
32
33 enum GridType {
34 GRID_RECTANGULAR = 0,
36 GRID_ISOMETRIC
37 };
38
50
51public:
53 : m_showGrid(false),
54 m_snapToGrid(false),
55 m_spacing(16,16),
56 m_xSpacingActive(true),
57 m_ySpacingActive(true),
58 m_offsetActive(false),
59 m_offsetAspectLocked(true),
60 m_spacingAspectLocked(true),
61 m_angleLeft(45),
62 m_angleRight(45),
63 m_angleAspectLocked(true),
64 m_angleLeftActive(true),
65 m_angleRightActive(true),
66 m_cellSpacing(30),
67 m_cellSize(30),
68 m_gridType(GRID_RECTANGULAR),
69 m_subdivision(2),
70 m_lineTypeMain(LINE_SOLID),
71 m_lineTypeSubdivision(LINE_DOTTED),
72 m_lineTypeIsoVertical(LINE_DASHED),
73 m_colorMain(200, 200, 200, 200),
74 m_colorSubdivision(200, 200, 200, 150),
75 m_colorIsoVertical(200, 200, 200, 100),
76 m_penMain(QPen()),
77 m_penSubdivision(QPen()),
78 m_penVertical(QPen())
79 {
80 loadStaticData();
81 m_penMain.setWidth(0);
82 m_penSubdivision.setWidth(0);
83 m_penVertical.setWidth(0);
84 }
85
86 bool operator==(const KisGridConfig &rhs) const {
87 return
88 m_showGrid == rhs.m_showGrid &&
89 m_snapToGrid == rhs.m_snapToGrid &&
90 m_spacing == rhs.m_spacing &&
91 m_xSpacingActive == rhs.m_xSpacingActive &&
92 m_ySpacingActive == rhs.m_ySpacingActive &&
93 m_offsetActive == rhs.m_offsetActive &&
94 m_offset == rhs.m_offset &&
95 m_offsetAspectLocked == rhs.m_offsetAspectLocked &&
96 m_spacingAspectLocked == rhs.m_spacingAspectLocked &&
97 m_angleRight == rhs.m_angleRight &&
98 m_angleLeft == rhs.m_angleLeft &&
99 m_angleAspectLocked == rhs.m_angleAspectLocked &&
100 m_angleLeftActive == rhs.m_angleLeftActive &&
101 m_angleRightActive == rhs.m_angleRightActive &&
102 m_gridType == rhs.m_gridType &&
103 m_cellSpacing == rhs.m_cellSpacing &&
104 m_cellSize == rhs.m_cellSize &&
105 m_subdivision == rhs.m_subdivision &&
106 m_lineTypeMain == rhs.m_lineTypeMain &&
107 m_lineTypeSubdivision == rhs.m_lineTypeSubdivision &&
108 m_lineTypeIsoVertical == rhs.m_lineTypeIsoVertical &&
109 m_colorMain == rhs.m_colorMain &&
110 m_colorSubdivision == rhs.m_colorSubdivision &&
111 m_colorIsoVertical == rhs.m_colorIsoVertical;
112 }
113
114 bool showGrid() const {
115 return m_showGrid;
116 }
117 void setShowGrid(bool value) {
118 m_showGrid = value;
119 }
120
121 bool snapToGrid() const {
122 return m_snapToGrid;
123 }
124 void setSnapToGrid(bool value) {
125 m_snapToGrid = value;
126 }
127
128 bool offsetActive() const {
129 return m_offsetActive;
130 }
132 m_offsetActive = value;
133 }
134
135 QPoint offset() const {
136 return m_offset;
137 }
138 void setOffset(const QPoint &value) {
139 m_offset = value;
140 updateTrigoCache();
141 }
142
143 QPoint spacing() const {
144 return m_spacing;
145 }
146 void setSpacing(const QPoint &value) {
147 m_spacing = value;
148 }
149
150 bool xSpacingActive() const {
151 return m_xSpacingActive;
152 }
154 m_xSpacingActive = value;
155 }
156
157 bool ySpacingActive() const {
158 return m_ySpacingActive;
159 }
161 m_ySpacingActive = value;
162 }
163
164 int subdivision() const {
165 return m_subdivision;
166 }
168 m_subdivision = value;
169 }
170
171 qreal angleLeft() const {
172 return m_angleLeft;
173 }
174 void setAngleLeft(qreal angle) {
175 m_angleLeft = angle;
176 updateTrigoCache();
177 }
178
179 qreal angleRight() const {
180 return m_angleRight;
181 }
182
183 void setAngleRight(qreal angle) {
184 m_angleRight = angle;
185 updateTrigoCache();
186 }
187
188 bool angleLeftActive() const {
189 return m_angleLeftActive;
190 }
191
193 m_angleLeftActive = value;
194 }
195
196 bool angleRightActive() const {
197 return m_angleRightActive;
198 }
199
201 m_angleRightActive = value;
202 }
203
204 int cellSpacing() const {
205 return m_cellSpacing;
206 }
207 void setCellSpacing(int spacing) {
208 m_cellSpacing = spacing;
209 }
210
211 int cellSize() const {
212 return m_cellSize;
213 }
214 void setCellSize(int spacing) {
215 m_cellSize = spacing;
216 updateTrigoCache();
217 }
218
220 return m_gridType;
221 }
223 m_gridType = type;
224 }
225
226 bool offsetAspectLocked() const {
227 return m_offsetAspectLocked;
228 }
230 m_offsetAspectLocked = value;
231 }
232
233 bool spacingAspectLocked() const {
234 return m_spacingAspectLocked;
235 }
237 m_spacingAspectLocked = value;
238 }
239
240 bool angleAspectLocked() const {
241 return m_angleAspectLocked;
242 }
244 m_angleAspectLocked = value;
245 }
246
248 return m_lineTypeMain;
249 }
251 m_lineTypeMain = value;
252 updatePenStyle(&m_penMain, m_colorMain, m_lineTypeMain);
253 }
254
256 return m_lineTypeSubdivision;
257 }
258
260 m_lineTypeSubdivision = value;
261 updatePenStyle(&m_penSubdivision, m_colorSubdivision, m_lineTypeSubdivision);
262 }
263
265 return m_lineTypeIsoVertical;
266 }
267
269 m_lineTypeIsoVertical= value;
270 updatePenStyle(&m_penVertical, m_colorIsoVertical, m_lineTypeIsoVertical);
271 updateTrigoCache();
272 }
273
274 QColor colorMain() const {
275 return m_colorMain;
276 }
277 void setColorMain(const QColor &value) {
278 m_colorMain = value;
279 updatePenStyle(&m_penMain, m_colorMain, m_lineTypeMain);
280 }
281
282 QColor colorSubdivision() const {
283 return m_colorSubdivision;
284 }
285 void setColorSubdivision(const QColor &value) {
286 m_colorSubdivision = value;
287 updatePenStyle(&m_penSubdivision, m_colorSubdivision, m_lineTypeSubdivision);
288 }
289
290 QColor colorVertical() const {
291 return m_colorIsoVertical;
292 }
293 void setColorVertical(const QColor &value) {
294 m_colorIsoVertical = value;
295 updatePenStyle(&m_penVertical, m_colorIsoVertical, m_lineTypeIsoVertical);
296 }
297
298 QPen penMain() const {
299 return m_penMain;
300 }
301
302 QPen penSubdivision() const {
303 return m_penSubdivision;
304 }
305
306 QPen penVertical() const {
307 return m_penVertical;
308 }
309
311 return m_trigoCache;
312 }
313
314 void loadStaticData();
315 void saveStaticData() const;
316
317 QDomElement saveDynamicDataToXml(QDomDocument& doc, const QString &tag) const;
318 bool loadDynamicDataFromXml(const QDomElement &parent);
319
320 static const KisGridConfig& defaultGrid();
321
322 bool isDefault() const {
323 return *this == defaultGrid();
324 }
325
329 void transform(const QTransform &transform);
330
331private:
332 void updatePenStyle(QPen *pen, QColor color, LineTypeInternal type);
333 void updateTrigoCache();
334
335private:
336 // Dynamic data. Stored in KisDocument.
337
340 QPoint m_spacing;
353
356
357 QPoint m_offset;
358
359 // Static data. Stored in the Krita config.
360
364
368
372
374};
375
377
378#endif /* __KIS_GRID_CONFIG_H */
float value(const T *src, size_t ch)
LineTypeInternal lineTypeMain() const
QColor colorVertical() const
QColor m_colorIsoVertical
void setOffsetActive(bool value)
GridType gridType() const
void setSnapToGrid(bool value)
void setAngleLeft(qreal angle)
QPen penVertical() const
QPen penMain() const
QColor colorMain() const
LineTypeInternal m_lineTypeIsoVertical
QPen penSubdivision() const
void setSubdivision(int value)
bool ySpacingActive() const
void setXSpacingActive(bool value)
void setOffset(const QPoint &value)
qreal angleRight() const
void setLineTypeMain(LineTypeInternal value)
bool xSpacingActive() const
void setColorSubdivision(const QColor &value)
void setAngleLeftActive(bool value)
bool isDefault() const
void setCellSpacing(int spacing)
void setColorVertical(const QColor &value)
QPoint offset() const
LineTypeInternal lineTypeSubdivision() const
bool operator==(const KisGridConfig &rhs) const
bool angleRightActive() const
void setGridType(GridType type)
bool angleLeftActive() const
void setLineTypeVertical(LineTypeInternal value)
QColor m_colorSubdivision
int cellSize() const
void setLineTypeSubdivision(LineTypeInternal value)
TrigoCache trigoCache() const
void setAngleRight(qreal angle)
bool spacingAspectLocked() const
QColor colorSubdivision() const
void setYSpacingActive(bool value)
bool angleAspectLocked() const
void setSpacingAspectLocked(bool value)
LineTypeInternal m_lineTypeSubdivision
QPoint spacing() const
bool offsetActive() const
int subdivision() const
LineTypeInternal m_lineTypeMain
int cellSpacing() const
void setSpacing(const QPoint &value)
LineTypeInternal lineTypeVertical() const
TrigoCache m_trigoCache
void setOffsetAspectLocked(bool value)
void setCellSize(int spacing)
void setAngleRightActive(bool value)
void setShowGrid(bool value)
void setColorMain(const QColor &value)
bool snapToGrid() const
bool showGrid() const
bool offsetAspectLocked() const
qreal angleLeft() const
void setAngleAspectLocked(bool value)
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
QVariantHash defaultGrid