Krita

GridConfig.cpp
1/*
2 * SPDX-FileCopyrightText: 2024 Grum999 <grum999@grum.fr>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "GridConfig.h"
7
8#include <QDomDocument>
9#include <QDomElement>
10
11#include "kis_grid_config.h"
12#include "kis_debug.h"
13
14struct GridConfig::Private {
15 Private() {}
16 KisGridConfig *gridConfig;
17};
18
19GridConfig::GridConfig(KisGridConfig *gridConfig)
20 : QObject(0)
21 , d(new Private)
22{
23 d->gridConfig = gridConfig;
24}
25
26GridConfig::GridConfig(QObject *parent)
27 : QObject(parent)
28 , d(new Private)
29{
30 d->gridConfig = new KisGridConfig();
31}
32
33GridConfig::~GridConfig()
34{
35 delete d;
36}
37
38bool GridConfig::operator==(const GridConfig &other) const
39{
40 return (d->gridConfig == other.d->gridConfig);
41}
42
43bool GridConfig::operator!=(const GridConfig &other) const
44{
45 return !(operator==(other));
46}
47
48
50{
51 return d->gridConfig->showGrid();
52}
53
54void GridConfig::setVisible(bool visible)
55{
56 d->gridConfig->setShowGrid(visible);
57}
58
59bool GridConfig::snap() const
60{
61 return d->gridConfig->showGrid();
62}
63
64void GridConfig::setSnap(bool snap)
65{
66 d->gridConfig->setSnapToGrid(snap);
67}
68
70{
71 return d->gridConfig->offset();
72}
73
75{
76 QPoint rangeOffset = QPoint(offset);
77 rangeOffset.setX(qBound(0, rangeOffset.x(), 500));
78 rangeOffset.setY(qBound(0, rangeOffset.y(), 500));
79 d->gridConfig->setOffset(rangeOffset);
80}
81
83{
84 return d->gridConfig->spacing();
85}
86
88{
89 QPoint rangeSpacing = QPoint(spacing);
90 if (rangeSpacing.x() < 1) {
91 rangeSpacing.setX(1);
92 }
93 if (rangeSpacing.y() < 1) {
94 rangeSpacing.setY(1);
95 }
96 d->gridConfig->setSpacing(rangeSpacing);
97}
98
100{
101 return d->gridConfig->xSpacingActive();
102}
103
105{
106 d->gridConfig->setXSpacingActive(active);
107}
108
110{
111 return d->gridConfig->ySpacingActive();
112}
113
115{
116 d->gridConfig->setYSpacingActive(active);
117}
118
120{
121 return d->gridConfig->subdivision();
122}
123
124void GridConfig::setSubdivision(int subdivision)
125{
126 d->gridConfig->setSubdivision(qBound(1, subdivision, 10));
127}
128
130{
131 return d->gridConfig->angleLeft();
132}
133
134void GridConfig::setAngleLeft(qreal angleLeft)
135{
136 d->gridConfig->setAngleLeft(qBound(0.0, angleLeft, 89.0));
137}
138
140{
141 return d->gridConfig->angleRight();
142}
143
144void GridConfig::setAngleRight(qreal angleRight)
145{
146 d->gridConfig->setAngleRight(qBound(0.0, angleRight, 89.0));
147}
148
150{
151 return d->gridConfig->angleLeftActive();
152}
153
155{
156 d->gridConfig->setAngleLeftActive(active);
157}
158
160{
161 return d->gridConfig->angleRightActive();
162}
163
165{
166 d->gridConfig->setAngleRightActive(active);
167}
168
170{
171 return d->gridConfig->cellSpacing();
172}
173
174void GridConfig::setCellSpacing(int cellSpacing)
175{
176 d->gridConfig->setCellSpacing(qBound(10, cellSpacing, 1000));
177}
178
180{
181 return d->gridConfig->cellSize();
182}
183
184void GridConfig::setCellSize(int cellSize)
185{
186 d->gridConfig->setCellSize(qBound(10, cellSize, 1000));
187}
188
190{
191 KisGridConfig::GridType type = d->gridConfig->gridType();
192 if(type == KisGridConfig::GridType::GRID_ISOMETRIC) {
193 return "isometric";
194 }
195 else if(type == KisGridConfig::GridType::GRID_ISOMETRIC_LEGACY) {
196 return "isometric_legacy";
197 }
198 return "rectangular";
199}
200
201void GridConfig::setType(const QString &gridType)
202{
203 if(gridType == "isometric") {
204 d->gridConfig->setGridType(KisGridConfig::GridType::GRID_ISOMETRIC);
205 }
206 else if(gridType == "isometric_legacy") {
207 d->gridConfig->setGridType(KisGridConfig::GridType::GRID_ISOMETRIC_LEGACY);
208 }
209 else {
210 d->gridConfig->setGridType(KisGridConfig::GridType::GRID_RECTANGULAR);
211 }
212}
213
215{
216 return d->gridConfig->offsetAspectLocked();
217}
218
219void GridConfig::setOffsetAspectLocked(bool offsetAspectLocked)
220{
221 d->gridConfig->setOffsetAspectLocked(offsetAspectLocked);
222}
223
225{
226 return d->gridConfig->spacingAspectLocked();
227}
228
229void GridConfig::setSpacingAspectLocked(bool spacingAspectLocked)
230{
231 d->gridConfig->setSpacingAspectLocked(spacingAspectLocked);
232}
233
235{
236 return d->gridConfig->angleAspectLocked();
237}
238
239void GridConfig::setAngleAspectLocked(bool angleAspectLocked)
240{
241 d->gridConfig->setAngleAspectLocked(angleAspectLocked);
242}
243
245{
246 KisGridConfig::LineTypeInternal type = d->gridConfig->lineTypeMain();
247 if(type == KisGridConfig::LineTypeInternal::LINE_DASHED) {
248 return "dashed";
249 }
250 else if(type == KisGridConfig::LineTypeInternal::LINE_DOTTED) {
251 return "dotted";
252 }
253 return "solid";
254}
255
257{
258 if(lineType == "dashed") {
259 d->gridConfig->setLineTypeMain(KisGridConfig::LineTypeInternal::LINE_DASHED);
260 }
261 else if(lineType == "dotted") {
262 d->gridConfig->setLineTypeMain(KisGridConfig::LineTypeInternal::LINE_DOTTED);
263 }
264 else {
265 d->gridConfig->setLineTypeMain(KisGridConfig::LineTypeInternal::LINE_SOLID);
266 }
267}
268
270{
271 KisGridConfig::LineTypeInternal type = d->gridConfig->lineTypeSubdivision();
272 if(type == KisGridConfig::LineTypeInternal::LINE_DASHED) {
273 return "dashed";
274 }
275 else if(type == KisGridConfig::LineTypeInternal::LINE_DOTTED) {
276 return "dotted";
277 }
278 return "solid";
279}
280
282{
283 if(lineType == "dashed") {
284 d->gridConfig->setLineTypeSubdivision(KisGridConfig::LineTypeInternal::LINE_DASHED);
285 }
286 else if(lineType == "dotted") {
287 d->gridConfig->setLineTypeSubdivision(KisGridConfig::LineTypeInternal::LINE_DOTTED);
288 }
289 else {
290 d->gridConfig->setLineTypeSubdivision(KisGridConfig::LineTypeInternal::LINE_SOLID);
291 }
292}
293
295{
296 KisGridConfig::LineTypeInternal type = d->gridConfig->lineTypeVertical();
297 if(type == KisGridConfig::LineTypeInternal::LINE_DASHED) {
298 return "dashed";
299 }
300 else if(type == KisGridConfig::LineTypeInternal::LINE_DOTTED) {
301 return "dotted";
302 }
303 else if(type == KisGridConfig::LineTypeInternal::LINE_NONE) {
304 return "none";
305 }
306 return "solid";
307}
308
310{
311 if(lineType == "dashed") {
312 d->gridConfig->setLineTypeVertical(KisGridConfig::LineTypeInternal::LINE_DASHED);
313 }
314 else if(lineType == "dotted") {
315 d->gridConfig->setLineTypeVertical(KisGridConfig::LineTypeInternal::LINE_DOTTED);
316 }
317 else if(lineType == "none") {
318 d->gridConfig->setLineTypeVertical(KisGridConfig::LineTypeInternal::LINE_NONE);
319 }
320 else {
321 d->gridConfig->setLineTypeVertical(KisGridConfig::LineTypeInternal::LINE_SOLID);
322 }
323}
324
325
327{
328 return d->gridConfig->colorMain();
329}
330
332{
333 d->gridConfig->setColorMain(colorMain);
334}
335
337{
338 return d->gridConfig->colorSubdivision();
339}
340
342{
343 d->gridConfig->setColorSubdivision(colorSubdivision);
344}
345
347{
348 return d->gridConfig->colorVertical();
349}
350
352{
353 d->gridConfig->setColorVertical(colorVertical);
354}
355
356bool GridConfig::fromXml(const QString &xmlContent) const
357{
359 QString errorMsg {""};
360 int errorLine {0}, errorColumn {0};
361
362 if(doc.setContent(xmlContent, &errorMsg, &errorLine, &errorColumn)) {
363
364 return d->gridConfig->loadDynamicDataFromXml(doc.documentElement());
365 }
366
367 return false;
368}
369
371{
373 QDomElement elt = d->gridConfig->saveDynamicDataToXml(doc, "grid");
374 doc.appendChild(elt);
375 return doc.toString(2);
376}
377
378
379KisGridConfig GridConfig::gridConfig() const
380{
381 return *d->gridConfig;
382}
383
384
The GridConfig class encapsulates a Krita Guides configuration.
Definition GridConfig.h:20
void setLineTypeSubdivision(const QString &lineType)
Set grid subdivision line type.
void setVisible(bool visible)
Set grid visibility for document.
void setSpacingAspectLocked(bool spacingAspectLocked)
Set status of "Aspect locked" property for spacing values (X and Y values are linked to keep ratio) S...
bool angleLeftActive() const
Returns if left angle grid is active.
void setOffsetAspectLocked(bool offsetAspectLocked)
Set status of "Aspect locked" property for offset values (X and Y values are linked to keep ratio)
bool visible() const
Returns grid visibility for document.
void setSnap(bool snap)
Activate or deactivate snap to grid for document.
QPoint offset() const
Returns grid offset (in pixels, from origin) for document.
QPoint spacing() const
Returns grid spacing (in pixels) for document.
QString toXml() const
Save grid definition as an XML document.
QColor colorMain() const
Returns grid main line color.
void setAngleRightActive(bool active)
Set right angle grid active.
void setAngleAspectLocked(bool angleAspectLocked)
Set status of "Aspect locked" property for angles values (left and right angles values are linked to ...
QString lineTypeMain() const
Returns grid main line type.
bool spacingAspectLocked() const
Returns status of "Aspect locked" property for spacing values (mean, X and Y values are linked to kee...
int subdivision() const
Returns number of grid subdivision for document.
void setOffset(QPoint offset)
Define grid offset (in pixels, from origin) for document.
qreal angleLeft() const
Returns left angle (in degrees) of isometric grid for document.
void setAngleRight(qreal angleRight)
Set right angle (in degrees) of isometric grid for document.
void setColorSubdivision(QColor colorSubdivision)
Set grid subdivision line color ColorSubdivision value is used for grid type "rectangular".
QString lineTypeSubdivision() const
Returns grid subdivision line type.
bool snap() const
Returns snap to grid status for document.
void setLineTypeMain(const QString &lineType)
Set grid main line type.
bool angleRightActive() const
Returns if right angle grid is active.
void setSubdivision(int subdivision)
Set number of grid subdivision for document.
void setCellSize(int cellSize)
Set grid cell size (in pixels) for document.
bool fromXml(const QString &xmlContent) const
Load grid definition from an XML document.
QColor colorSubdivision() const
Returns grid subdivision line color ColorSubdivision value is used for grid type "rectangular".
QString lineTypeVertical() const
Returns grid vertical line type.
bool spacingActiveHorizontal() const
Returns if horizontal grid spacing is active.
void setType(const QString &gridType)
Set current grid type applied for document.
QString type() const
Returns current grid type applied for document.
void setSpacingActiveVertical(bool active)
Set vertical grid spacing active.
void setAngleLeft(qreal angleLeft)
Set left angle (in degrees) of isometric grid for document.
void setColorMain(QColor colorMain)
Set grid main line color.
bool offsetAspectLocked() const
Returns status of "Aspect locked" property for offset values (X and Y values are linked to keep ratio...
bool spacingActiveVertical() const
Returns if vertical grid spacing is active.
void setAngleLeftActive(bool active)
Set left angle grid active.
void setCellSpacing(int cellSpacing)
Set grid cell spacing for document.
void setColorVertical(QColor colorVertical)
Set grid vertical line color ColorSubdivision value is used for grid type "isometric".
void setLineTypeVertical(const QString &lineType)
Set grid vertical line type.
bool angleAspectLocked() const
Returns status of "Aspect locked" property for angles values (mean, left and right angles values are ...
int cellSpacing() const
Returns grid cell spacing (in pixels) for document.
QColor colorVertical() const
Returns grid vertical line color ColorSubdivision value is used for grid type "isometric".
qreal angleRight() const
Returns right angle (in degrees) of isometric grid for document.
void setSpacingActiveHorizontal(bool active)
Set horizontal grid spacing active.
int cellSize() const
Returns grid cell border size (in pixels) for document.
void setSpacing(QPoint spacing)
Set grid spacing (in pixels) for document.
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QString toString(int indent) const const
QDomNode appendChild(const QDomNode &newChild)
void setX(int x)
void setY(int y)
int x() const const
int y() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:51:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.