Krita

GuidesConfig.cpp
1/*
2 * SPDX-FileCopyrightText: 2024 Grum999 <grum999@grum.fr>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "GuidesConfig.h"
7
8#include <QDomDocument>
9#include <QDomElement>
10
11#include "kis_guides_config.h"
12
13struct GuidesConfig::Private {
14 Private() {}
15 KisGuidesConfig *guidesConfig;
16};
17
18GuidesConfig::GuidesConfig(KisGuidesConfig *guidesConfig)
19 : QObject(0)
20 , d(new Private)
21{
22 d->guidesConfig = guidesConfig;
23}
24
25GuidesConfig::GuidesConfig(QObject *parent)
26 : QObject(parent)
27 , d(new Private)
28{
29 d->guidesConfig = new KisGuidesConfig();
30}
31
32GuidesConfig::~GuidesConfig()
33{
34 delete d;
35}
36
37bool GuidesConfig::operator==(const GuidesConfig &other) const
38{
39 return (d->guidesConfig == other.d->guidesConfig);
40}
41
42bool GuidesConfig::operator!=(const GuidesConfig &other) const
43{
44 return !(operator==(other));
45}
46
48{
49 return d->guidesConfig->guidesColor();
50}
51
52void GuidesConfig::setColor(const QColor &color) const
53{
54 d->guidesConfig->setGuidesColor(color);
55}
56
58{
59 KisGuidesConfig::LineTypeInternal lineType = d->guidesConfig->guidesLineType();
60 if(lineType == KisGuidesConfig::LineTypeInternal::LINE_DASHED) {
61 return "dashed";
62 }
63 else if(lineType == KisGuidesConfig::LineTypeInternal::LINE_DOTTED) {
64 return "dotted";
65 }
66 return "solid";
67}
68
70{
71 if (!d->guidesConfig) return;
72
73 if(lineType == "dashed") {
74 d->guidesConfig->setGuidesLineType(KisGuidesConfig::LineTypeInternal::LINE_DASHED);
75 }
76 else if(lineType == "dotted") {
77 d->guidesConfig->setGuidesLineType(KisGuidesConfig::LineTypeInternal::LINE_DOTTED);
78 }
79 else {
80 d->guidesConfig->setGuidesLineType(KisGuidesConfig::LineTypeInternal::LINE_SOLID);
81 }
82}
83
85{
86 return d->guidesConfig->hasGuides();
87}
88
89bool GuidesConfig::hasSamePositionAs(const GuidesConfig &guideConfig) const
90{
91 return d->guidesConfig->hasSamePositionAs(guideConfig.guidesConfig());
92}
93
95{
96 return d->guidesConfig->showGuides();
97}
98
99void GuidesConfig::setVisible(const bool value)
100{
101 d->guidesConfig->setShowGuides(value);
102}
103
104bool GuidesConfig::fromXml(const QString &xmlContent) const
105{
107 QString errorMsg {""};
108 int errorLine {0}, errorColumn {0};
109
110 if(doc.setContent(xmlContent, &errorMsg, &errorLine, &errorColumn)) {
111 return d->guidesConfig->loadFromXml(doc.documentElement());
112 }
113
114 return false;
115}
116
118{
120 QDomElement elt = d->guidesConfig->saveToXml(doc, "guides");
121 doc.appendChild(elt);
122 return doc.toString(2);
123}
124
126{
127 d->guidesConfig->removeAllGuides();
128}
129
131{
132 return d->guidesConfig->lockGuides();
133}
134
135void GuidesConfig::setLocked(const bool locked)
136{
137 d->guidesConfig->setLockGuides(locked);
138}
139
141{
142 return d->guidesConfig->snapToGuides();
143}
144
146{
147 d->guidesConfig->setSnapToGuides(snap);
148}
149
151{
152 d->guidesConfig->setHorizontalGuideLines(lines);
153}
154
156{
157 d->guidesConfig->setVerticalGuideLines(lines);
158}
159
161{
162 return d->guidesConfig->horizontalGuideLines();
163}
164
166{
167 return d->guidesConfig->verticalGuideLines();
168}
169
170KisGuidesConfig GuidesConfig::guidesConfig() const
171{
172 return *d->guidesConfig;
173}
The GuidesConfig class encapsulates a Krita Guides configuration.
bool hasSamePositionAs(const GuidesConfig &guideConfig) const
indicate if position from current guides configuration match positions from another guides configurat...
QString toXml() const
Save guides definition as an XML document.
void setColor(const QColor &color) const
Define guides color.
QList< qreal > horizontalGuides() const
The horizontal guides.
QColor color() const
Guides color.
bool fromXml(const QString &xmlContent) const
Load guides definition from an XML document.
void removeAllGuides()
Remove all guides.
void setVerticalGuides(const QList< qreal > &lines)
Set the vertical guides.
void setLocked(const bool value)
Set guides lock status.
bool hasGuides() const
indicate if there's guides defined
void setVisible(const bool value)
Set guides visibility status.
QString lineType() const
Guides line type.
bool visible() const
Returns guides visibility status.
bool snap() const
Returns guide snap status.
void setHorizontalGuides(const QList< qreal > &lines)
Set the horizontal guides.
QList< qreal > verticalGuides() const
The vertical guides.
bool locked() const
Returns guide lock status.
void setSnap(const bool value)
Set guides snap status.
void setLineType(const QString &lineType)
Define guides lines type.
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QString toString(int indent) const const
QDomNode appendChild(const QDomNode &newChild)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.