File indexing completed on 2024-04-21 03:57:50
0001 /* 0002 SPDX-FileCopyrightText: 2011-2018 Dominik Haumann <dhaumann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "variableitem.h" 0008 #include "variableeditor.h" 0009 0010 // BEGIN class VariableItem 0011 VariableItem::VariableItem(const QString &variable) 0012 : m_variable(variable) 0013 , m_active(false) 0014 { 0015 } 0016 0017 QString VariableItem::variable() const 0018 { 0019 return m_variable; 0020 } 0021 0022 QString VariableItem::helpText() const 0023 { 0024 return m_helpText; 0025 } 0026 0027 void VariableItem::setHelpText(const QString &text) 0028 { 0029 m_helpText = text; 0030 } 0031 0032 bool VariableItem::isActive() const 0033 { 0034 return m_active; 0035 } 0036 0037 void VariableItem::setActive(bool active) 0038 { 0039 m_active = active; 0040 } 0041 // END class VariableItem 0042 0043 // BEGIN class VariableIntItem 0044 VariableIntItem::VariableIntItem(const QString &variable, int value) 0045 : VariableItem(variable) 0046 , m_value(value) 0047 , m_minValue(-20000) 0048 , m_maxValue(20000) 0049 { 0050 } 0051 0052 int VariableIntItem::value() const 0053 { 0054 return m_value; 0055 } 0056 0057 void VariableIntItem::setValue(int newValue) 0058 { 0059 m_value = newValue; 0060 } 0061 0062 void VariableIntItem::setValueByString(const QString &value) 0063 { 0064 setValue(value.toInt()); 0065 } 0066 0067 QString VariableIntItem::valueAsString() const 0068 { 0069 return QString::number(value()); 0070 } 0071 0072 VariableEditor *VariableIntItem::createEditor(QWidget *parent) 0073 { 0074 return new VariableIntEditor(this, parent); 0075 } 0076 0077 void VariableIntItem::setRange(int minValue, int maxValue) 0078 { 0079 m_minValue = minValue; 0080 m_maxValue = maxValue; 0081 } 0082 0083 int VariableIntItem::minValue() const 0084 { 0085 return m_minValue; 0086 } 0087 0088 int VariableIntItem::maxValue() const 0089 { 0090 return m_maxValue; 0091 } 0092 // END class VariableIntItem 0093 0094 // BEGIN class VariableStringListItem 0095 VariableStringListItem::VariableStringListItem(const QString &variable, const QStringList &slist, const QString &value) 0096 : VariableItem(variable) 0097 , m_list(slist) 0098 , m_value(value) 0099 { 0100 } 0101 0102 QStringList VariableStringListItem::stringList() const 0103 { 0104 return m_list; 0105 } 0106 0107 QString VariableStringListItem::value() const 0108 { 0109 return m_value; 0110 } 0111 0112 void VariableStringListItem::setValue(const QString &newValue) 0113 { 0114 m_value = newValue; 0115 } 0116 0117 void VariableStringListItem::setValueByString(const QString &value) 0118 { 0119 setValue(value); 0120 } 0121 0122 QString VariableStringListItem::valueAsString() const 0123 { 0124 return value(); 0125 } 0126 0127 VariableEditor *VariableStringListItem::createEditor(QWidget *parent) 0128 { 0129 return new VariableStringListEditor(this, parent); 0130 } 0131 // END class VariableStringListItem 0132 0133 // BEGIN class VariableBoolItem 0134 VariableBoolItem::VariableBoolItem(const QString &variable, bool value) 0135 : VariableItem(variable) 0136 , m_value(value) 0137 { 0138 } 0139 0140 bool VariableBoolItem::value() const 0141 { 0142 return m_value; 0143 } 0144 0145 void VariableBoolItem::setValue(bool enabled) 0146 { 0147 m_value = enabled; 0148 } 0149 0150 void VariableBoolItem::setValueByString(const QString &value) 0151 { 0152 QString tmp = value.trimmed().toLower(); 0153 bool enabled = (tmp == QLatin1String("on")) || (tmp == QLatin1String("1")) || (tmp == QLatin1String("true")); 0154 setValue(enabled); 0155 } 0156 0157 QString VariableBoolItem::valueAsString() const 0158 { 0159 return value() ? QStringLiteral("true") : QStringLiteral("false"); 0160 } 0161 0162 VariableEditor *VariableBoolItem::createEditor(QWidget *parent) 0163 { 0164 return new VariableBoolEditor(this, parent); 0165 } 0166 // END class VariableBoolItem 0167 0168 // BEGIN class VariableColorItem 0169 VariableColorItem::VariableColorItem(const QString &variable, const QColor &value) 0170 : VariableItem(variable) 0171 , m_value(value) 0172 { 0173 } 0174 0175 QColor VariableColorItem::value() const 0176 { 0177 return m_value; 0178 } 0179 0180 void VariableColorItem::setValue(const QColor &value) 0181 { 0182 m_value = value; 0183 } 0184 0185 void VariableColorItem::setValueByString(const QString &value) 0186 { 0187 setValue(QColor(value)); 0188 } 0189 0190 QString VariableColorItem::valueAsString() const 0191 { 0192 return value().name(); 0193 } 0194 0195 VariableEditor *VariableColorItem::createEditor(QWidget *parent) 0196 { 0197 return new VariableColorEditor(this, parent); 0198 } 0199 // END class VariableColorItem 0200 0201 // BEGIN class VariableFontItem 0202 VariableFontItem::VariableFontItem(const QString &variable, const QFont &value) 0203 : VariableItem(variable) 0204 , m_value(value) 0205 { 0206 } 0207 0208 QFont VariableFontItem::value() const 0209 { 0210 return m_value; 0211 } 0212 0213 void VariableFontItem::setValue(const QFont &value) 0214 { 0215 m_value = value; 0216 } 0217 0218 void VariableFontItem::setValueByString(const QString &value) 0219 { 0220 setValue(QFont(value)); 0221 } 0222 0223 QString VariableFontItem::valueAsString() const 0224 { 0225 return value().family(); 0226 } 0227 0228 VariableEditor *VariableFontItem::createEditor(QWidget *parent) 0229 { 0230 return new VariableFontEditor(this, parent); 0231 } 0232 // END class VariableFontItem 0233 0234 // BEGIN class VariableStringItem 0235 VariableStringItem::VariableStringItem(const QString &variable, const QString &value) 0236 : VariableItem(variable) 0237 , m_value(value) 0238 { 0239 } 0240 0241 void VariableStringItem::setValue(const QString &value) 0242 { 0243 m_value = value; 0244 } 0245 0246 void VariableStringItem::setValueByString(const QString &value) 0247 { 0248 m_value = value; 0249 } 0250 0251 QString VariableStringItem::value() const 0252 { 0253 return m_value; 0254 } 0255 0256 QString VariableStringItem::valueAsString() const 0257 { 0258 return m_value; 0259 } 0260 0261 VariableEditor *VariableStringItem::createEditor(QWidget *parent) 0262 { 0263 return new VariableStringEditor(this, parent); 0264 } 0265 // END class VariableStringItem 0266 0267 // BEGIN class VariableSpellCheckItem 0268 VariableSpellCheckItem::VariableSpellCheckItem(const QString &variable, const QString &value) 0269 : VariableItem(variable) 0270 , m_value(value) 0271 { 0272 } 0273 0274 QString VariableSpellCheckItem::value() const 0275 { 0276 return m_value; 0277 } 0278 0279 void VariableSpellCheckItem::setValue(const QString &value) 0280 { 0281 m_value = value; 0282 } 0283 0284 QString VariableSpellCheckItem::valueAsString() const 0285 { 0286 return m_value; 0287 } 0288 0289 void VariableSpellCheckItem::setValueByString(const QString &value) 0290 { 0291 m_value = value; 0292 } 0293 0294 VariableEditor *VariableSpellCheckItem::createEditor(QWidget *parent) 0295 { 0296 return new VariableSpellCheckEditor(this, parent); 0297 } 0298 // END class VariableSpellCheckItem 0299 0300 // BEGIN class VariableRemoveSpacesItem 0301 VariableRemoveSpacesItem::VariableRemoveSpacesItem(const QString &variable, int value) 0302 : VariableItem(variable) 0303 , m_value(value) 0304 { 0305 } 0306 0307 int VariableRemoveSpacesItem::value() const 0308 { 0309 return m_value; 0310 } 0311 0312 void VariableRemoveSpacesItem::setValue(int value) 0313 { 0314 m_value = value; 0315 } 0316 0317 QString VariableRemoveSpacesItem::valueAsString() const 0318 { 0319 if (m_value == 2) { 0320 return QStringLiteral("all"); 0321 } else if (m_value == 1) { 0322 return QStringLiteral("modified"); 0323 } else { 0324 return QStringLiteral("none"); 0325 } 0326 } 0327 0328 void VariableRemoveSpacesItem::setValueByString(const QString &value) 0329 { 0330 QString tmp = value.trimmed().toLower(); 0331 0332 if (tmp == QLatin1String("1") || tmp == QLatin1String("modified") || tmp == QLatin1String("mod") || tmp == QLatin1String("+")) { 0333 m_value = 1; 0334 } else if (tmp == QLatin1String("2") || tmp == QLatin1String("all") || tmp == QLatin1String("*")) { 0335 m_value = 2; 0336 } else { 0337 m_value = 0; 0338 } 0339 } 0340 0341 VariableEditor *VariableRemoveSpacesItem::createEditor(QWidget *parent) 0342 { 0343 return new VariableRemoveSpacesEditor(this, parent); 0344 } 0345 // END class VariableRemoveSpacesItem