1 /*
2     SPDX-FileCopyrightText: 2011-2018 Dominik Haumann <dhaumann@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef VARIABLE_ITEM_H
8 #define VARIABLE_ITEM_H
9 
10 #include <QColor>
11 #include <QFont>
12 #include <QString>
13 #include <QStringList>
14 
15 class VariableEditor;
16 
17 // BEGIN class VariableItem
18 class VariableItem
19 {
20 public:
21     explicit VariableItem(const QString &variable);
22     virtual ~VariableItem() = default;
23 
24     QString variable() const;
25     QString helpText() const;
26     void setHelpText(const QString &text);
27 
28     bool isActive() const;
29     void setActive(bool active);
30 
31     virtual void setValueByString(const QString &value) = 0;
32     virtual QString valueAsString() const = 0;
33 
34     virtual VariableEditor *createEditor(QWidget *parent) = 0;
35 
36 private:
37     // not implemented: copy constructor and operator=
38     VariableItem(const VariableItem &copy);
39     VariableItem &operator=(const VariableItem &other);
40 
41     QString m_variable;
42     QString m_helpText;
43     bool m_active;
44 };
45 // END class VariableItem
46 
47 //
48 // DERIVE A CLASS FOR EACH TYPE
49 //
50 
51 // BEGIN class VariableIntItem
52 class VariableIntItem : public VariableItem
53 {
54 public:
55     explicit VariableIntItem(const QString &variable, int value);
56 
57     int value() const;
58     void setValue(int newValue);
59     void setRange(int minValue, int maxValue);
60     int minValue() const;
61     int maxValue() const;
62 
63 public:
64     void setValueByString(const QString &value) override;
65     QString valueAsString() const override;
66     VariableEditor *createEditor(QWidget *parent) override;
67 
68 private:
69     int m_value;
70     int m_minValue;
71     int m_maxValue;
72 };
73 // END class VariableIntItem
74 
75 // BEGIN class VariableStringListItem
76 class VariableStringListItem : public VariableItem
77 {
78 public:
79     explicit VariableStringListItem(const QString &variable, const QStringList &slist, const QString &value);
80 
81     QStringList stringList() const;
82 
83     QString value() const;
84     void setValue(const QString &newValue);
85 
86 public:
87     void setValueByString(const QString &value) override;
88     QString valueAsString() const override;
89     VariableEditor *createEditor(QWidget *parent) override;
90 
91 private:
92     QStringList m_list;
93     QString m_value;
94 };
95 // END class VariableStringListItem
96 
97 // BEGIN class VariableBoolItem
98 class VariableBoolItem : public VariableItem
99 {
100 public:
101     explicit VariableBoolItem(const QString &variable, bool value);
102 
103     bool value() const;
104     void setValue(bool enabled);
105 
106 public:
107     void setValueByString(const QString &value) override;
108     QString valueAsString() const override;
109     VariableEditor *createEditor(QWidget *parent) override;
110 
111 private:
112     bool m_value;
113 };
114 // END class VariableBoolItem
115 
116 // BEGIN class VariableColorItem
117 class VariableColorItem : public VariableItem
118 {
119 public:
120     explicit VariableColorItem(const QString &variable, const QColor &value);
121 
122     QColor value() const;
123     void setValue(const QColor &color);
124 
125 public:
126     void setValueByString(const QString &value) override;
127     QString valueAsString() const override;
128     VariableEditor *createEditor(QWidget *parent) override;
129 
130 private:
131     QColor m_value;
132 };
133 // END class VariableColorItem
134 
135 // BEGIN class VariableFontItem
136 class VariableFontItem : public VariableItem
137 {
138 public:
139     explicit VariableFontItem(const QString &variable, const QFont &value);
140 
141     QFont value() const;
142     void setValue(const QFont &value);
143 
144 public:
145     void setValueByString(const QString &value) override;
146     QString valueAsString() const override;
147     VariableEditor *createEditor(QWidget *parent) override;
148 
149 private:
150     QFont m_value;
151 };
152 // END class VariableFontItem
153 
154 // BEGIN class VariableStringItem
155 class VariableStringItem : public VariableItem
156 {
157 public:
158     explicit VariableStringItem(const QString &variable, const QString &value);
159 
160     QString value() const;
161     void setValue(const QString &value);
162 
163 public:
164     void setValueByString(const QString &value) override; // Same as setValue() in this case, implemented for uniformity
165     QString valueAsString() const override; // Same as value() in this case, implemented for uniformity
166     VariableEditor *createEditor(QWidget *parent) override;
167 
168 private:
169     QString m_value;
170 };
171 
172 // END class VariableStringItem
173 
174 // BEGIN class VariableSpellCheckItem
175 class VariableSpellCheckItem : public VariableItem
176 {
177 public:
178     explicit VariableSpellCheckItem(const QString &variable, const QString &value);
179 
180     QString value() const;
181     void setValue(const QString &value);
182 
183 public:
184     void setValueByString(const QString &value) override; // Same as setValue() in this case, implemented for uniformity
185     QString valueAsString() const override; // Same as value() in this case, implemented for uniformity
186     VariableEditor *createEditor(QWidget *parent) override;
187 
188 private:
189     QString m_value;
190 };
191 // END class VariableSpellCheckItem
192 
193 // BEGIN class VariableRemoveSpacesItem
194 class VariableRemoveSpacesItem : public VariableItem
195 {
196 public:
197     explicit VariableRemoveSpacesItem(const QString &variable, int value);
198 
199     int value() const;
200     void setValue(int value);
201 
202 public:
203     void setValueByString(const QString &value) override; // Same as setValue() in this case, implemented for uniformity
204     QString valueAsString() const override; // Same as value() in this case, implemented for uniformity
205     VariableEditor *createEditor(QWidget *parent) override;
206 
207 private:
208     int m_value;
209 };
210 // END class VariableRemoveSpacesItem
211 
212 #endif
213