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

source code of ktexteditor/src/variableeditor/variableitem.cpp