| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2011-2018 Dominik Haumann <dhaumann@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "variableitem.h" |
| 8 | #include "variableeditor.h" |
| 9 | |
| 10 | // BEGIN class VariableItem |
| 11 | VariableItem::VariableItem(const QString &variable) |
| 12 | : m_variable(variable) |
| 13 | , m_active(false) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | QString VariableItem::variable() const |
| 18 | { |
| 19 | return m_variable; |
| 20 | } |
| 21 | |
| 22 | QString VariableItem::helpText() const |
| 23 | { |
| 24 | return m_helpText; |
| 25 | } |
| 26 | |
| 27 | void VariableItem::setHelpText(const QString &text) |
| 28 | { |
| 29 | m_helpText = text; |
| 30 | } |
| 31 | |
| 32 | bool VariableItem::isActive() const |
| 33 | { |
| 34 | return m_active; |
| 35 | } |
| 36 | |
| 37 | void VariableItem::setActive(bool active) |
| 38 | { |
| 39 | m_active = active; |
| 40 | } |
| 41 | // END class VariableItem |
| 42 | |
| 43 | // BEGIN class VariableIntItem |
| 44 | VariableIntItem::VariableIntItem(const QString &variable, int value) |
| 45 | : VariableItem(variable) |
| 46 | , m_value(value) |
| 47 | , m_minValue(-20000) |
| 48 | , m_maxValue(20000) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | int VariableIntItem::value() const |
| 53 | { |
| 54 | return m_value; |
| 55 | } |
| 56 | |
| 57 | void VariableIntItem::setValue(int newValue) |
| 58 | { |
| 59 | m_value = newValue; |
| 60 | } |
| 61 | |
| 62 | void VariableIntItem::setValueByString(const QString &value) |
| 63 | { |
| 64 | setValue(value.toInt()); |
| 65 | } |
| 66 | |
| 67 | QString VariableIntItem::valueAsString() const |
| 68 | { |
| 69 | return QString::number(value()); |
| 70 | } |
| 71 | |
| 72 | VariableEditor *VariableIntItem::createEditor(QWidget *parent) |
| 73 | { |
| 74 | return new VariableIntEditor(this, parent); |
| 75 | } |
| 76 | |
| 77 | void VariableIntItem::setRange(int minValue, int maxValue) |
| 78 | { |
| 79 | m_minValue = minValue; |
| 80 | m_maxValue = maxValue; |
| 81 | } |
| 82 | |
| 83 | int VariableIntItem::minValue() const |
| 84 | { |
| 85 | return m_minValue; |
| 86 | } |
| 87 | |
| 88 | int VariableIntItem::maxValue() const |
| 89 | { |
| 90 | return m_maxValue; |
| 91 | } |
| 92 | // END class VariableIntItem |
| 93 | |
| 94 | // BEGIN class VariableStringListItem |
| 95 | VariableStringListItem::VariableStringListItem(const QString &variable, const QStringList &slist, const QString &value) |
| 96 | : VariableItem(variable) |
| 97 | , m_list(slist) |
| 98 | , m_value(value) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | QStringList VariableStringListItem::stringList() const |
| 103 | { |
| 104 | return m_list; |
| 105 | } |
| 106 | |
| 107 | QString VariableStringListItem::value() const |
| 108 | { |
| 109 | return m_value; |
| 110 | } |
| 111 | |
| 112 | void VariableStringListItem::setValue(const QString &newValue) |
| 113 | { |
| 114 | m_value = newValue; |
| 115 | } |
| 116 | |
| 117 | void VariableStringListItem::setValueByString(const QString &value) |
| 118 | { |
| 119 | setValue(value); |
| 120 | } |
| 121 | |
| 122 | QString VariableStringListItem::valueAsString() const |
| 123 | { |
| 124 | return value(); |
| 125 | } |
| 126 | |
| 127 | VariableEditor *VariableStringListItem::createEditor(QWidget *parent) |
| 128 | { |
| 129 | return new VariableStringListEditor(this, parent); |
| 130 | } |
| 131 | // END class VariableStringListItem |
| 132 | |
| 133 | // BEGIN class VariableBoolItem |
| 134 | VariableBoolItem::VariableBoolItem(const QString &variable, bool value) |
| 135 | : VariableItem(variable) |
| 136 | , m_value(value) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | bool VariableBoolItem::value() const |
| 141 | { |
| 142 | return m_value; |
| 143 | } |
| 144 | |
| 145 | void VariableBoolItem::setValue(bool enabled) |
| 146 | { |
| 147 | m_value = enabled; |
| 148 | } |
| 149 | |
| 150 | void VariableBoolItem::setValueByString(const QString &value) |
| 151 | { |
| 152 | QString tmp = value.trimmed().toLower(); |
| 153 | bool enabled = (tmp == QLatin1String("on" )) || (tmp == QLatin1String("1" )) || (tmp == QLatin1String("true" )); |
| 154 | setValue(enabled); |
| 155 | } |
| 156 | |
| 157 | QString VariableBoolItem::valueAsString() const |
| 158 | { |
| 159 | return value() ? QStringLiteral("true" ) : QStringLiteral("false" ); |
| 160 | } |
| 161 | |
| 162 | VariableEditor *VariableBoolItem::createEditor(QWidget *parent) |
| 163 | { |
| 164 | return new VariableBoolEditor(this, parent); |
| 165 | } |
| 166 | // END class VariableBoolItem |
| 167 | |
| 168 | // BEGIN class VariableColorItem |
| 169 | VariableColorItem::VariableColorItem(const QString &variable, const QColor &value) |
| 170 | : VariableItem(variable) |
| 171 | , m_value(value) |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | QColor VariableColorItem::value() const |
| 176 | { |
| 177 | return m_value; |
| 178 | } |
| 179 | |
| 180 | void VariableColorItem::setValue(const QColor &value) |
| 181 | { |
| 182 | m_value = value; |
| 183 | } |
| 184 | |
| 185 | void VariableColorItem::setValueByString(const QString &value) |
| 186 | { |
| 187 | setValue(QColor(value)); |
| 188 | } |
| 189 | |
| 190 | QString VariableColorItem::valueAsString() const |
| 191 | { |
| 192 | return value().name(); |
| 193 | } |
| 194 | |
| 195 | VariableEditor *VariableColorItem::createEditor(QWidget *parent) |
| 196 | { |
| 197 | return new VariableColorEditor(this, parent); |
| 198 | } |
| 199 | // END class VariableColorItem |
| 200 | |
| 201 | // BEGIN class VariableFontItem |
| 202 | VariableFontItem::VariableFontItem(const QString &variable, const QFont &value) |
| 203 | : VariableItem(variable) |
| 204 | , m_value(value) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | QFont VariableFontItem::value() const |
| 209 | { |
| 210 | return m_value; |
| 211 | } |
| 212 | |
| 213 | void VariableFontItem::setValue(const QFont &value) |
| 214 | { |
| 215 | m_value = value; |
| 216 | } |
| 217 | |
| 218 | void VariableFontItem::setValueByString(const QString &value) |
| 219 | { |
| 220 | setValue(QFont(value)); |
| 221 | } |
| 222 | |
| 223 | QString VariableFontItem::valueAsString() const |
| 224 | { |
| 225 | return value().family(); |
| 226 | } |
| 227 | |
| 228 | VariableEditor *VariableFontItem::createEditor(QWidget *parent) |
| 229 | { |
| 230 | return new VariableFontEditor(this, parent); |
| 231 | } |
| 232 | // END class VariableFontItem |
| 233 | |
| 234 | // BEGIN class VariableStringItem |
| 235 | VariableStringItem::VariableStringItem(const QString &variable, const QString &value) |
| 236 | : VariableItem(variable) |
| 237 | , m_value(value) |
| 238 | { |
| 239 | } |
| 240 | |
| 241 | void VariableStringItem::setValue(const QString &value) |
| 242 | { |
| 243 | m_value = value; |
| 244 | } |
| 245 | |
| 246 | void VariableStringItem::setValueByString(const QString &value) |
| 247 | { |
| 248 | m_value = value; |
| 249 | } |
| 250 | |
| 251 | QString VariableStringItem::value() const |
| 252 | { |
| 253 | return m_value; |
| 254 | } |
| 255 | |
| 256 | QString VariableStringItem::valueAsString() const |
| 257 | { |
| 258 | return m_value; |
| 259 | } |
| 260 | |
| 261 | VariableEditor *VariableStringItem::createEditor(QWidget *parent) |
| 262 | { |
| 263 | return new VariableStringEditor(this, parent); |
| 264 | } |
| 265 | // END class VariableStringItem |
| 266 | |
| 267 | // BEGIN class VariableSpellCheckItem |
| 268 | VariableSpellCheckItem::VariableSpellCheckItem(const QString &variable, const QString &value) |
| 269 | : VariableItem(variable) |
| 270 | , m_value(value) |
| 271 | { |
| 272 | } |
| 273 | |
| 274 | QString VariableSpellCheckItem::value() const |
| 275 | { |
| 276 | return m_value; |
| 277 | } |
| 278 | |
| 279 | void VariableSpellCheckItem::setValue(const QString &value) |
| 280 | { |
| 281 | m_value = value; |
| 282 | } |
| 283 | |
| 284 | QString VariableSpellCheckItem::valueAsString() const |
| 285 | { |
| 286 | return m_value; |
| 287 | } |
| 288 | |
| 289 | void VariableSpellCheckItem::setValueByString(const QString &value) |
| 290 | { |
| 291 | m_value = value; |
| 292 | } |
| 293 | |
| 294 | VariableEditor *VariableSpellCheckItem::createEditor(QWidget *parent) |
| 295 | { |
| 296 | return new VariableSpellCheckEditor(this, parent); |
| 297 | } |
| 298 | // END class VariableSpellCheckItem |
| 299 | |
| 300 | // BEGIN class VariableRemoveSpacesItem |
| 301 | VariableRemoveSpacesItem::VariableRemoveSpacesItem(const QString &variable, int value) |
| 302 | : VariableItem(variable) |
| 303 | { |
| 304 | setValue(value); |
| 305 | } |
| 306 | |
| 307 | int VariableRemoveSpacesItem::value() const |
| 308 | { |
| 309 | return m_operation; |
| 310 | } |
| 311 | |
| 312 | void VariableRemoveSpacesItem::setValue(int value) |
| 313 | { |
| 314 | if (value >= RemoveOp::None && value <= RemoveOp::All) { |
| 315 | m_operation = static_cast<RemoveOp>(value); |
| 316 | } else { |
| 317 | m_operation = RemoveOp::None; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | QString VariableRemoveSpacesItem::valueAsString() const |
| 322 | { |
| 323 | if (m_operation == RemoveOp::All) { |
| 324 | return QStringLiteral("all" ); |
| 325 | } else if (m_operation == RemoveOp::Modified) { |
| 326 | return QStringLiteral("modified" ); |
| 327 | } else { |
| 328 | return QStringLiteral("none" ); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void VariableRemoveSpacesItem::setValueByString(const QString &value) |
| 333 | { |
| 334 | QString tmp = value.trimmed().toLower(); |
| 335 | |
| 336 | if (tmp == QLatin1String("1" ) || tmp == QLatin1String("modified" ) || tmp == QLatin1String("mod" ) || tmp == QLatin1String("+" )) { |
| 337 | m_operation = RemoveOp::Modified; |
| 338 | } else if (tmp == QLatin1String("2" ) || tmp == QLatin1String("all" ) || tmp == QLatin1String("*" )) { |
| 339 | m_operation = RemoveOp::All; |
| 340 | } else { |
| 341 | m_operation = RemoveOp::None; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | VariableEditor *VariableRemoveSpacesItem::createEditor(QWidget *parent) |
| 346 | { |
| 347 | return new VariableRemoveSpacesEditor(this, parent); |
| 348 | } |
| 349 | // END class VariableRemoveSpacesItem |
| 350 | |