Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_liquify_properties.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QDomElement>
10
11#include <kconfig.h>
12#include <kconfiggroup.h>
13#include <ksharedconfig.h>
14
15#include "kis_debug.h"
16#include "kis_dom_utils.h"
17
30
45
47{
48 return
49 m_mode == other.m_mode &&
50 m_size == other.m_size &&
51 m_amount == other.m_amount &&
52 m_spacing == other.m_spacing &&
57 m_flow == other.m_flow;
58}
59
61{
62 QString result;
63
64 switch (mode) {
66 result = "Move";
67 break;
69 result = "Scale";
70 break;
72 result = "Rotate";
73 break;
75 result = "Offset";
76 break;
78 result = "Undo";
79 break;
81 qFatal("Unsupported mode");
82 }
83
84 return QString("LiquifyTool/%1").arg(result);
85}
86
88{
89 KConfigGroup cfg =
90 KSharedConfig::openConfig()->group(liquifyModeString(m_mode));
91
92 cfg.writeEntry("size", m_size);
93 cfg.writeEntry("amount", m_amount);
94 cfg.writeEntry("spacing", m_spacing);
95 cfg.writeEntry("sizeHasPressure", m_sizeHasPressure);
96 cfg.writeEntry("amountHasPressure", m_amountHasPressure);
97 cfg.writeEntry("reverseDirection", m_reverseDirection);
98 cfg.writeEntry("useWashMode", m_useWashMode);
99 cfg.writeEntry("flow", m_flow);
100
101 KConfigGroup globalCfg = KSharedConfig::openConfig()->group("LiquifyTool");
102 globalCfg.writeEntry("mode", (int)m_mode);
103}
104
106{
107 KConfigGroup cfg =
108 KSharedConfig::openConfig()->group(liquifyModeString(m_mode));
109
110 m_size = cfg.readEntry("size", m_size);
111 m_amount = cfg.readEntry("amount", m_amount);
112 m_spacing = cfg.readEntry("spacing", m_spacing);
113 m_sizeHasPressure = cfg.readEntry("sizeHasPressure", m_sizeHasPressure);
114 m_amountHasPressure = cfg.readEntry("amountHasPressure", m_amountHasPressure);
115 m_reverseDirection = cfg.readEntry("reverseDirection", m_reverseDirection);
116 m_useWashMode = cfg.readEntry("useWashMode", m_useWashMode);
117 m_flow = cfg.readEntry("flow", m_flow);
118}
119
121{
122 KConfigGroup globalCfg = KSharedConfig::openConfig()->group("LiquifyTool");
123 m_mode = (LiquifyMode) globalCfg.readEntry("mode", (int)m_mode);
124
125 loadMode();
126}
127
128void KisLiquifyProperties::toXML(QDomElement *e) const
129{
130 QDomDocument doc = e->ownerDocument();
131 QDomElement liqEl = doc.createElement("liquify_properties");
132 e->appendChild(liqEl);
133
134 KisDomUtils::saveValue(&liqEl, "mode", (int)m_mode);
135 KisDomUtils::saveValue(&liqEl, "size", m_size);
136 KisDomUtils::saveValue(&liqEl, "amount", m_amount);
137 KisDomUtils::saveValue(&liqEl, "spacing", m_spacing);
138 KisDomUtils::saveValue(&liqEl, "sizeHasPressure", m_sizeHasPressure);
139 KisDomUtils::saveValue(&liqEl, "amountHasPressure", m_amountHasPressure);
140 KisDomUtils::saveValue(&liqEl, "reverseDirection", m_reverseDirection);
141 KisDomUtils::saveValue(&liqEl, "useWashMode", m_useWashMode);
142 KisDomUtils::saveValue(&liqEl, "flow", m_flow);
143}
144
146{
148 bool result = false;
149
150 QDomElement liqEl;
151 int newMode = 0;
152
153 result =
154 KisDomUtils::findOnlyElement(e, "liquify_properties", &liqEl) &&
155
156 KisDomUtils::loadValue(liqEl, "mode", &newMode) &&
157 KisDomUtils::loadValue(liqEl, "size", &props.m_size) &&
158 KisDomUtils::loadValue(liqEl, "amount", &props.m_amount) &&
159 KisDomUtils::loadValue(liqEl, "spacing", &props.m_spacing) &&
160 KisDomUtils::loadValue(liqEl, "sizeHasPressure", &props.m_sizeHasPressure) &&
161 KisDomUtils::loadValue(liqEl, "amountHasPressure", &props.m_amountHasPressure) &&
162 KisDomUtils::loadValue(liqEl, "reverseDirection", &props.m_reverseDirection) &&
163 KisDomUtils::loadValue(liqEl, "useWashMode", &props.m_useWashMode) &&
164 KisDomUtils::loadValue(liqEl, "flow", &props.m_flow);
165
166 if (result && newMode >= 0 && newMode < N_MODES) {
167 props.m_mode = (LiquifyMode) newMode;
168 } else {
169 result = false;
170 }
171
172 return props;
173}
174
175
176QDebug operator<<(QDebug dbg, const KisLiquifyProperties &props)
177{
178 dbg.nospace() << "\nKisLiquifyProperties(";
179 dbg.space() << "\n " << ppVar(props.mode());
180 dbg.space() << "\n " << ppVar(props.size());
181 dbg.space() << "\n " << ppVar(props.amount());
182 dbg.space() << "\n " << ppVar(props.spacing());
183 dbg.space() << "\n " << ppVar(props.sizeHasPressure());
184 dbg.space() << "\n " << ppVar(props.amountHasPressure());
185 dbg.space() << "\n " << ppVar(props.reverseDirection());
186 dbg.space() << "\n " << ppVar(props.useWashMode());
187 dbg.space() << "\n " << ppVar(props.flow());
188 dbg.space() << "\n );\n";
189 return dbg.nospace();
190}
bool operator==(const KisLiquifyProperties &other) const
static KisLiquifyProperties fromXML(const QDomElement &e)
KisLiquifyProperties & operator=(const KisLiquifyProperties &rhs)
void toXML(QDomElement *e) const
#define ppVar(var)
Definition kis_debug.h:155
QDebug operator<<(QDebug dbg, const KisLiquifyProperties &props)
QString liquifyModeString(KisLiquifyProperties::LiquifyMode mode)
void saveValue(QDomElement *parent, const QString &tag, const QSize &size)
bool findOnlyElement(const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)
bool loadValue(const QDomElement &e, float *v)