File indexing completed on 2024-12-22 04:16:53
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_liquify_properties.h" 0008 0009 #include <QDomElement> 0010 0011 #include <kconfig.h> 0012 #include <kconfiggroup.h> 0013 #include <ksharedconfig.h> 0014 0015 #include "kis_debug.h" 0016 #include "kis_dom_utils.h" 0017 0018 KisLiquifyProperties::KisLiquifyProperties(const KisLiquifyProperties &rhs) 0019 { 0020 m_mode = rhs.m_mode; 0021 m_size = rhs.m_size; 0022 m_amount = rhs.m_amount; 0023 m_spacing = rhs.m_spacing; 0024 m_sizeHasPressure = rhs.m_sizeHasPressure; 0025 m_amountHasPressure = rhs.m_amountHasPressure; 0026 m_reverseDirection = rhs.m_reverseDirection; 0027 m_useWashMode = rhs.m_useWashMode; 0028 m_flow = rhs.m_flow; 0029 } 0030 0031 KisLiquifyProperties &KisLiquifyProperties::operator=(const KisLiquifyProperties &rhs) 0032 { 0033 m_mode = rhs.m_mode; 0034 m_size = rhs.m_size; 0035 m_amount = rhs.m_amount; 0036 m_spacing = rhs.m_spacing; 0037 m_sizeHasPressure = rhs.m_sizeHasPressure; 0038 m_amountHasPressure = rhs.m_amountHasPressure; 0039 m_reverseDirection = rhs.m_reverseDirection; 0040 m_useWashMode = rhs.m_useWashMode; 0041 m_flow = rhs.m_flow; 0042 0043 return *this; 0044 } 0045 0046 bool KisLiquifyProperties::operator==(const KisLiquifyProperties &other) const 0047 { 0048 return 0049 m_mode == other.m_mode && 0050 m_size == other.m_size && 0051 m_amount == other.m_amount && 0052 m_spacing == other.m_spacing && 0053 m_sizeHasPressure == other.m_sizeHasPressure && 0054 m_amountHasPressure == other.m_amountHasPressure && 0055 m_reverseDirection == other.m_reverseDirection && 0056 m_useWashMode == other.m_useWashMode && 0057 m_flow == other.m_flow; 0058 } 0059 0060 QString liquifyModeString(KisLiquifyProperties::LiquifyMode mode) 0061 { 0062 QString result; 0063 0064 switch (mode) { 0065 case KisLiquifyProperties::MOVE: 0066 result = "Move"; 0067 break; 0068 case KisLiquifyProperties::SCALE: 0069 result = "Scale"; 0070 break; 0071 case KisLiquifyProperties::ROTATE: 0072 result = "Rotate"; 0073 break; 0074 case KisLiquifyProperties::OFFSET: 0075 result = "Offset"; 0076 break; 0077 case KisLiquifyProperties::UNDO: 0078 result = "Undo"; 0079 break; 0080 case KisLiquifyProperties::N_MODES: 0081 qFatal("Unsupported mode"); 0082 } 0083 0084 return QString("LiquifyTool/%1").arg(result); 0085 } 0086 0087 void KisLiquifyProperties::saveMode() const 0088 { 0089 KConfigGroup cfg = 0090 KSharedConfig::openConfig()->group(liquifyModeString(m_mode)); 0091 0092 cfg.writeEntry("size", m_size); 0093 cfg.writeEntry("amount", m_amount); 0094 cfg.writeEntry("spacing", m_spacing); 0095 cfg.writeEntry("sizeHasPressure", m_sizeHasPressure); 0096 cfg.writeEntry("amountHasPressure", m_amountHasPressure); 0097 cfg.writeEntry("reverseDirection", m_reverseDirection); 0098 cfg.writeEntry("useWashMode", m_useWashMode); 0099 cfg.writeEntry("flow", m_flow); 0100 0101 KConfigGroup globalCfg = KSharedConfig::openConfig()->group("LiquifyTool"); 0102 globalCfg.writeEntry("mode", (int)m_mode); 0103 } 0104 0105 void KisLiquifyProperties::loadMode() 0106 { 0107 KConfigGroup cfg = 0108 KSharedConfig::openConfig()->group(liquifyModeString(m_mode)); 0109 0110 m_size = cfg.readEntry("size", m_size); 0111 m_amount = cfg.readEntry("amount", m_amount); 0112 m_spacing = cfg.readEntry("spacing", m_spacing); 0113 m_sizeHasPressure = cfg.readEntry("sizeHasPressure", m_sizeHasPressure); 0114 m_amountHasPressure = cfg.readEntry("amountHasPressure", m_amountHasPressure); 0115 m_reverseDirection = cfg.readEntry("reverseDirection", m_reverseDirection); 0116 m_useWashMode = cfg.readEntry("useWashMode", m_useWashMode); 0117 m_flow = cfg.readEntry("flow", m_flow); 0118 } 0119 0120 void KisLiquifyProperties::loadAndResetMode() 0121 { 0122 KConfigGroup globalCfg = KSharedConfig::openConfig()->group("LiquifyTool"); 0123 m_mode = (LiquifyMode) globalCfg.readEntry("mode", (int)m_mode); 0124 0125 loadMode(); 0126 } 0127 0128 void KisLiquifyProperties::toXML(QDomElement *e) const 0129 { 0130 QDomDocument doc = e->ownerDocument(); 0131 QDomElement liqEl = doc.createElement("liquify_properties"); 0132 e->appendChild(liqEl); 0133 0134 KisDomUtils::saveValue(&liqEl, "mode", (int)m_mode); 0135 KisDomUtils::saveValue(&liqEl, "size", m_size); 0136 KisDomUtils::saveValue(&liqEl, "amount", m_amount); 0137 KisDomUtils::saveValue(&liqEl, "spacing", m_spacing); 0138 KisDomUtils::saveValue(&liqEl, "sizeHasPressure", m_sizeHasPressure); 0139 KisDomUtils::saveValue(&liqEl, "amountHasPressure", m_amountHasPressure); 0140 KisDomUtils::saveValue(&liqEl, "reverseDirection", m_reverseDirection); 0141 KisDomUtils::saveValue(&liqEl, "useWashMode", m_useWashMode); 0142 KisDomUtils::saveValue(&liqEl, "flow", m_flow); 0143 } 0144 0145 KisLiquifyProperties KisLiquifyProperties::fromXML(const QDomElement &e) 0146 { 0147 KisLiquifyProperties props; 0148 bool result = false; 0149 0150 QDomElement liqEl; 0151 int newMode = 0; 0152 0153 result = 0154 KisDomUtils::findOnlyElement(e, "liquify_properties", &liqEl) && 0155 0156 KisDomUtils::loadValue(liqEl, "mode", &newMode) && 0157 KisDomUtils::loadValue(liqEl, "size", &props.m_size) && 0158 KisDomUtils::loadValue(liqEl, "amount", &props.m_amount) && 0159 KisDomUtils::loadValue(liqEl, "spacing", &props.m_spacing) && 0160 KisDomUtils::loadValue(liqEl, "sizeHasPressure", &props.m_sizeHasPressure) && 0161 KisDomUtils::loadValue(liqEl, "amountHasPressure", &props.m_amountHasPressure) && 0162 KisDomUtils::loadValue(liqEl, "reverseDirection", &props.m_reverseDirection) && 0163 KisDomUtils::loadValue(liqEl, "useWashMode", &props.m_useWashMode) && 0164 KisDomUtils::loadValue(liqEl, "flow", &props.m_flow); 0165 0166 if (result && newMode >= 0 && newMode < N_MODES) { 0167 props.m_mode = (LiquifyMode) newMode; 0168 } else { 0169 result = false; 0170 } 0171 0172 return props; 0173 } 0174 0175 0176 QDebug operator<<(QDebug dbg, const KisLiquifyProperties &props) 0177 { 0178 dbg.nospace() << "\nKisLiquifyProperties("; 0179 dbg.space() << "\n " << ppVar(props.mode()); 0180 dbg.space() << "\n " << ppVar(props.size()); 0181 dbg.space() << "\n " << ppVar(props.amount()); 0182 dbg.space() << "\n " << ppVar(props.spacing()); 0183 dbg.space() << "\n " << ppVar(props.sizeHasPressure()); 0184 dbg.space() << "\n " << ppVar(props.amountHasPressure()); 0185 dbg.space() << "\n " << ppVar(props.reverseDirection()); 0186 dbg.space() << "\n " << ppVar(props.useWashMode()); 0187 dbg.space() << "\n " << ppVar(props.flow()); 0188 dbg.space() << "\n );\n"; 0189 return dbg.nospace(); 0190 }