ManaPlus
setupitem.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef GUI_WIDGETS_SETUPITEM_H
23 #define GUI_WIDGETS_SETUPITEM_H
24 
30 
31 #include "gui/widgets/widget2.h"
32 
34 
35 #include <list>
36 
37 class Button;
38 class CheckBox;
39 class Configuration;
40 class DropDown;
41 class EditDialog;
42 class HorizontContainer;
43 class IntTextField;
44 class Label;
45 class ListModel;
46 class SetupTabScroll;
47 class Slider;
48 class SliderList;
49 class TextField;
50 
52  public Widget2
53 {
54  public:
55  enum
56  {
57  VBOOL = 0,
60  VNONE
61  };
62 
64 
65  ~SetupItem() override;
66 
67  void load();
68 
69  virtual void save();
70 
71  virtual void fromWidget() = 0;
72 
73  virtual void toWidget() = 0;
74 
75  void setWidget(Widget *widget)
76  { mWidget = widget; }
77 
79  { return mWidget; }
80 
82 
83  virtual std::string getActionEventId() const A_WARN_UNUSED;
84 
85  void action(const ActionEvent &event) override;
86 
87  virtual void doAction();
88 
89  virtual void apply(const std::string &eventName);
90 
91  virtual void cancel(const std::string &eventName);
92 
93  virtual void externalUpdated(const std::string &eventName);
94 
95  virtual void externalUnloaded(const std::string &eventName);
96 
98  { return mMainConfig; }
99 
100  void fixFirstItemSize(Widget *const widget);
101 
102  virtual void rereadValue();
103 
104  void setValue(const std::string &str) noexcept2
105  { mValue = str; }
106 
107  std::string getValue() const noexcept2
108  { return mValue; }
109 
110  std::string getEventName() const noexcept2
111  { return mEventName; }
112 
113  protected:
114  SetupItem(const std::string &restrict text,
115  const std::string &restrict description,
116  const std::string &restrict keyName,
117  SetupTabScroll *restrict const parent,
118  const std::string &restrict eventName,
119  const MainConfig mainConfig);
120 
121  SetupItem(const std::string &restrict text,
122  const std::string &restrict description,
123  const std::string &restrict keyName,
124  SetupTabScroll *restrict const parent,
125  const std::string &restrict eventName,
126  const std::string &def,
127  const MainConfig mainConfig);
128 
129  std::string mText;
130 
131  std::string mDescription;
132 
133  std::string mKeyName;
134 
136 
137  std::string mEventName;
138 
139  std::string mValue;
140 
141  std::string mDefault;
142 
144 
145  std::list<Widget*> mTempWidgets;
146 
148 
150 
152 };
153 
155 {
156  public:
157  SetupItemCheckBox(const std::string &restrict text,
158  const std::string &restrict description,
159  const std::string &restrict keyName,
160  SetupTabScroll *restrict const parent,
161  const std::string &restrict eventName,
162  const MainConfig mainConfig);
163 
164  SetupItemCheckBox(const std::string &restrict text,
165  const std::string &restrict description,
166  const std::string &restrict keyName,
167  SetupTabScroll *restrict const parent,
168  const std::string &restrict eventName,
169  const std::string &restrict def,
170  const MainConfig mainConfig);
171 
173 
174  ~SetupItemCheckBox() override final;
175 
176  void createControls();
177 
178  void fromWidget() override final;
179 
180  void toWidget() override final;
181 
182  protected:
184 };
185 
187 {
188  public:
189  SetupItemTextField(const std::string &restrict text,
190  const std::string &restrict description,
191  const std::string &restrict keyName,
192  SetupTabScroll *restrict const parent,
193  const std::string &restrict eventName,
194  const MainConfig mainConfig,
195  const UseBase64 useBase64);
196 
197  SetupItemTextField(const std::string &restrict text,
198  const std::string &restrict description,
199  const std::string &restrict keyName,
200  SetupTabScroll *restrict const parent,
201  const std::string &restrict eventName,
202  const std::string &restrict def,
203  const MainConfig mainConfig,
204  const UseBase64 useBase64);
205 
207 
208  ~SetupItemTextField() override final;
209 
210  void createControls();
211 
212  void fromWidget() override final;
213 
214  void toWidget() override final;
215 
216  void action(const ActionEvent &event) override final;
217 
218  void apply(const std::string &eventName) override final;
219 
220  void cancel(const std::string &eventName A_UNUSED) override final;
221 
222  void externalUpdated(const std::string &eventName A_UNUSED)
223  override final;
224 
225  void rereadValue() override final;
226 
227  void save() override final;
228 
229  void setUseBase64(const UseBase64 b)
230  { mUseBase64 = b; }
231 
232  protected:
239 };
240 
242 {
243  public:
244  SetupItemIntTextField(const std::string &restrict text,
245  const std::string &restrict description,
246  const std::string &restrict keyName,
247  SetupTabScroll *restrict const parent,
248  const std::string &restrict eventName,
249  const int min, const int max,
250  const MainConfig mainConfig);
251 
252  SetupItemIntTextField(const std::string &restrict text,
253  const std::string &restrict description,
254  const std::string &restrict keyName,
255  SetupTabScroll *restrict const parent,
256  const std::string &restrict eventName,
257  const int min, const int max,
258  const std::string &restrict def,
259  const MainConfig mainConfig);
260 
262 
263  ~SetupItemIntTextField() override final;
264 
265  void createControls();
266 
267  void fromWidget() override final;
268 
269  void toWidget() override final;
270 
271  void action(const ActionEvent &event) override final;
272 
273  void apply(const std::string &eventName) override final;
274 
275  protected:
281  int mMin;
282  int mMax;
283 };
284 
286 {
287  public:
288  SetupItemLabel(const std::string &restrict text,
289  const std::string &restrict description,
290  SetupTabScroll *restrict const parent,
291  const Separator separator);
292 
294 
295  ~SetupItemLabel() override final;
296 
297  void createControls();
298 
299  void fromWidget() override final;
300 
301  void toWidget() override final;
302 
303  void action(const ActionEvent &event) override final;
304 
305  void apply(const std::string &eventName) override final;
306 
307  protected:
310 };
311 
313 {
314  public:
315  SetupItemDropDown(const std::string &restrict text,
316  const std::string &restrict description,
317  const std::string &restrict keyName,
318  SetupTabScroll *restrict const parent,
319  const std::string &restrict eventName,
320  ListModel *restrict const model,
321  const int width,
322  const MainConfig mainConfig);
323 
324  SetupItemDropDown(const std::string &restrict text,
325  const std::string &restrict description,
326  const std::string &restrict keyName,
327  SetupTabScroll *restrict const parent,
328  const std::string &restrict eventName,
329  ListModel *restrict const model,
330  const int width,
331  const std::string &restrict def,
332  const MainConfig mainConfig);
333 
335 
336  ~SetupItemDropDown() override final;
337 
338  void createControls();
339 
340  void fromWidget() override final;
341 
342  void toWidget() override final;
343 
344  int selectionByValue();
345 
346  protected:
351  int mWidth;
352 };
353 
355 {
356  public:
357  SetupItemDropDownStr(const std::string &restrict text,
358  const std::string &restrict description,
359  const std::string &restrict keyName,
360  SetupTabScroll *restrict const parent,
361  const std::string &restrict eventName,
362  ListModel *restrict const model,
363  const int width,
364  const MainConfig mainConfig);
365 
366  SetupItemDropDownStr(const std::string &restrict text,
367  const std::string &restrict description,
368  const std::string &restrict keyName,
369  SetupTabScroll *restrict const parent,
370  const std::string &restrict eventName,
371  ListModel *restrict const model,
372  const int width,
373  const std::string &restrict def,
374  const MainConfig mainConfig);
375 
377 
378  ~SetupItemDropDownStr() override final;
379 
380  void createControls();
381 
382  void fromWidget() override final;
383 
384  void toWidget() override final;
385 
386  int selectionByValue();
387 
388  protected:
393  int mWidth;
394 };
395 
397 {
398  public:
399  SetupItemSlider(const std::string &restrict text,
400  const std::string &restrict description,
401  const std::string &restrict keyName,
402  SetupTabScroll *restrict const parent,
403  const std::string &restrict eventName,
404  const double min,
405  const double max,
406  const double step,
407  const int width,
408  const OnTheFly onTheFly,
409  const MainConfig mainConfig);
410 
411  SetupItemSlider(const std::string &restrict text,
412  const std::string &restrict description,
413  const std::string &restrict keyName,
414  SetupTabScroll *restrict const parent,
415  const std::string &restrict eventName,
416  const double min,
417  const double max,
418  const double step,
419  const std::string &restrict def,
420  const int width,
421  const OnTheFly onTheFly,
422  const MainConfig mainConfig);
423 
425 
426  ~SetupItemSlider() override final;
427 
428  void createControls();
429 
430  void fromWidget() override final;
431 
432  void toWidget() override final;
433 
434  void action(const ActionEvent &event) override final;
435 
436  void apply(const std::string &eventName) override final;
437 
438  void updateLabel();
439 
440  protected:
444  double mMin;
445  double mMax;
446  double mStep;
447  int mWidth;
449 };
450 
451 typedef STD_VECTOR<std::string> SetupItemNames;
452 typedef SetupItemNames::iterator SetupItemNamesIter;
453 typedef SetupItemNames::const_iterator SetupItemNamesConstIter;
454 
456 {
457  public:
458  SetupItemSlider2(const std::string &restrict text,
459  const std::string &restrict description,
460  const std::string &restrict keyName,
461  SetupTabScroll *restrict const parent,
462  const std::string &restrict eventName,
463  const int min, const int max, const int step,
465  const OnTheFly onTheFly,
466  const MainConfig mainConfig,
467  const DoNotAlign doNotAlign);
468 
469  SetupItemSlider2(const std::string &restrict text,
470  const std::string &restrict description,
471  const std::string &restrict keyName,
472  SetupTabScroll *restrict const parent,
473  const std::string &restrict eventName,
474  const int min, const int max, const int step,
476  const std::string &restrict def,
477  const OnTheFly onTheFly,
478  const MainConfig mainConfig,
479  const DoNotAlign doNotAlign);
480 
482 
483  ~SetupItemSlider2() override final;
484 
485  void createControls();
486 
487  void fromWidget() override final;
488 
489  void toWidget() override final;
490 
491  void action(const ActionEvent &event) override final;
492 
493  void apply(const std::string &eventName) override final;
494 
495  void setInvertValue(const int v);
496 
497  protected:
498  void updateLabel();
499 
500  int getMaxWidth();
501 
507  int mMin;
508  int mMax;
509  int mStep;
511  bool mInvert;
514 };
515 
517 {
518  public:
520 
521  ~SetupItemSliderList() override;
522 
523  void createControls();
524 
525  void fromWidget() override;
526 
527  void toWidget() override;
528 
529  void action(const ActionEvent &event) override;
530 
531  void apply(const std::string &eventName) override final;
532 
533  virtual void addMoreControls() = 0;
534 
535  protected:
536  SetupItemSliderList(const std::string &restrict text,
537  const std::string &restrict description,
538  const std::string &restrict keyName,
539  SetupTabScroll *restrict const parent,
540  const std::string &restrict eventName,
541  ListModel *restrict const model,
542  const int width,
543  const OnTheFly onTheFly,
544  const MainConfig mainConfig);
545 
546  SetupItemSliderList(const std::string &restrict text,
547  const std::string &restrict description,
548  const std::string &restrict keyName,
549  SetupTabScroll *restrict const parent,
550  const std::string &restrict eventName,
551  ListModel *restrict const model,
552  const std::string &restrict def,
553  const int width,
554  const OnTheFly onTheFly,
555  const MainConfig mainConfig);
556 
561  int mWidth;
563 };
564 
566 {
567  public:
568  SetupItemSound(const std::string &restrict text,
569  const std::string &restrict description,
570  const std::string &restrict keyName,
571  SetupTabScroll *restrict const parent,
572  const std::string &restrict eventName,
573  ListModel *restrict const model,
574  const int width,
575  const OnTheFly onTheFly,
576  const MainConfig mainConfig);
577 
579 
580  void action(const ActionEvent &event) override final;
581 
582  void addMoreControls() override final;
583 
584  protected:
586 };
587 
589 {
590  public:
591  SetupItemSliderInt(const std::string &restrict text,
592  const std::string &restrict description,
593  const std::string &restrict keyName,
594  SetupTabScroll *restrict const parent,
595  const std::string &restrict eventName,
596  ListModel *restrict const model,
597  const int min,
598  const int width,
599  const OnTheFly onTheFly,
600  const MainConfig mainConfig);
601 
603 
604  void addMoreControls() override final;
605 
606  void fromWidget() override final;
607 
608  void toWidget() override final;
609 
610  protected:
611  int mMin;
612 };
613 
614 #endif // GUI_WIDGETS_SETUPITEM_H
Definition: button.h:102
Definition: label.h:91
CheckBox * mCheckBox
Definition: setupitem.h:183
SetupItemCheckBox(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
Definition: setupitem.cpp:213
SetupItemDropDownStr(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, ListModel *const model, const int width, const MainConfig mainConfig)
Definition: setupitem.cpp:754
HorizontContainer * mHorizont
Definition: setupitem.h:389
DropDown * mDropDown
Definition: setupitem.h:392
ListModel * mModel
Definition: setupitem.h:391
HorizontContainer * mHorizont
Definition: setupitem.h:347
SetupItemDropDown(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, ListModel *const model, const int width, const MainConfig mainConfig)
Definition: setupitem.cpp:654
ListModel * mModel
Definition: setupitem.h:349
DropDown * mDropDown
Definition: setupitem.h:350
SetupItemIntTextField(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const int min, const int max, const MainConfig mainConfig)
Definition: setupitem.cpp:452
void action(const ActionEvent &event)
Definition: setupitem.cpp:560
void apply(const std::string &eventName)
Definition: setupitem.cpp:588
EditDialog * mEditDialog
Definition: setupitem.h:280
IntTextField * mTextField
Definition: setupitem.h:278
HorizontContainer * mHorizont
Definition: setupitem.h:276
SetupItemLabel(const std::string &text, const std::string &description, SetupTabScroll *const parent, const Separator separator)
Definition: setupitem.cpp:598
Separator mIsSeparator
Definition: setupitem.h:309
void fromWidget()
Definition: setupitem.cpp:637
void createControls()
Definition: setupitem.cpp:616
Label * mLabel
Definition: setupitem.h:308
void action(const ActionEvent &event)
Definition: setupitem.cpp:645
void apply(const std::string &eventName)
Definition: setupitem.cpp:649
void apply(const std::string &eventName)
Definition: setupitem.cpp:1162
Label * mLabel
Definition: setupitem.h:503
OnTheFly mOnTheFly
Definition: setupitem.h:512
SetupItemSlider2(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const int min, const int max, const int step, SetupItemNames *const values, const OnTheFly onTheFly, const MainConfig mainConfig, const DoNotAlign doNotAlign)
Definition: setupitem.cpp:991
SetupItemNames * mValues
Definition: setupitem.h:506
Slider * mSlider
Definition: setupitem.h:505
void setInvertValue(const int v)
Definition: setupitem.cpp:1171
Label * mLabel2
Definition: setupitem.h:504
HorizontContainer * mHorizont
Definition: setupitem.h:502
void action(const ActionEvent &event)
Definition: setupitem.cpp:1137
DoNotAlign mDoNotAlign
Definition: setupitem.h:513
SetupItemSliderInt(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, ListModel *const model, const int min, const int width, const OnTheFly onTheFly, const MainConfig mainConfig)
Definition: setupitem.cpp:1332
void action(const ActionEvent &event)
Definition: setupitem.cpp:1271
ListModel * mModel
Definition: setupitem.h:560
virtual void addMoreControls()=0
SetupItemSliderList(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, ListModel *const model, const int width, const OnTheFly onTheFly, const MainConfig mainConfig)
Definition: setupitem.cpp:1179
void apply(const std::string &eventName)
Definition: setupitem.cpp:1278
SliderList * mSlider
Definition: setupitem.h:559
OnTheFly mOnTheFly
Definition: setupitem.h:562
HorizontContainer * mHorizont
Definition: setupitem.h:557
HorizontContainer * mHorizont
Definition: setupitem.h:441
void action(const ActionEvent &event)
Definition: setupitem.cpp:974
Label * mLabel
Definition: setupitem.h:442
SetupItemSlider(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const double min, const double max, const double step, const int width, const OnTheFly onTheFly, const MainConfig mainConfig)
Definition: setupitem.cpp:873
void createControls()
Definition: setupitem.cpp:932
Slider * mSlider
Definition: setupitem.h:443
void apply(const std::string &eventName)
Definition: setupitem.cpp:981
OnTheFly mOnTheFly
Definition: setupitem.h:448
void addMoreControls()
Definition: setupitem.cpp:1303
void action(const ActionEvent &event)
Definition: setupitem.cpp:1315
SetupItemSound(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, ListModel *const model, const int width, const OnTheFly onTheFly, const MainConfig mainConfig)
Definition: setupitem.cpp:1287
Button * mButton
Definition: setupitem.h:585
void action(const ActionEvent &event)
Definition: setupitem.cpp:415
EditDialog * mEditDialog
Definition: setupitem.h:237
void cancel(const std::string &eventName)
Definition: setupitem.cpp:338
void setUseBase64(const UseBase64 b)
Definition: setupitem.h:229
void apply(const std::string &eventName)
Definition: setupitem.cpp:443
void externalUpdated(const std::string &eventName)
Definition: setupitem.cpp:346
UseBase64 mUseBase64
Definition: setupitem.h:238
Button * mButton
Definition: setupitem.h:236
TextField * mTextField
Definition: setupitem.h:235
SetupItemTextField(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig, const UseBase64 useBase64)
Definition: setupitem.cpp:275
HorizontContainer * mHorizont
Definition: setupitem.h:233
MainConfig isMainConfig() const
Definition: setupitem.h:97
virtual std::string getActionEventId() const
Definition: setupitem.cpp:155
bool mUseDefault
Definition: setupitem.h:151
Widget * mWidget
Definition: setupitem.h:143
SetupItem(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
Definition: setupitem.cpp:55
virtual void fromWidget()=0
Configuration * getConfig() const
Definition: setupitem.cpp:106
void setWidget(Widget *widget)
Definition: setupitem.h:75
virtual void apply(const std::string &eventName)
Definition: setupitem.cpp:177
virtual void doAction()
Definition: setupitem.cpp:172
SetupTabScroll * mParent
Definition: setupitem.h:135
Widget * getWidget() const
Definition: setupitem.h:78
void setValue(const std::string &str)
Definition: setupitem.h:104
std::string mDescription
Definition: setupitem.h:131
std::string mValue
Definition: setupitem.h:139
std::string mDefault
Definition: setupitem.h:141
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:198
std::string mText
Definition: setupitem.h:129
void load()
Definition: setupitem.cpp:113
int mValueType
Definition: setupitem.h:147
std::string getValue() const
Definition: setupitem.h:107
std::string mKeyName
Definition: setupitem.h:133
std::string getEventName() const
Definition: setupitem.h:110
virtual void externalUpdated(const std::string &eventName)
Definition: setupitem.cpp:188
std::string mEventName
Definition: setupitem.h:137
virtual void toWidget()=0
virtual void cancel(const std::string &eventName)
Definition: setupitem.cpp:182
MainConfig mMainConfig
Definition: setupitem.h:149
void action(const ActionEvent &event)
Definition: setupitem.cpp:163
std::list< Widget * > mTempWidgets
Definition: setupitem.h:145
virtual void save()
Definition: setupitem.cpp:146
virtual void externalUnloaded(const std::string &eventName)
Definition: setupitem.cpp:194
virtual void rereadValue()
Definition: setupitem.cpp:207
Definition: slider.h:89
Definition: widget.h:99
bool DoNotAlign
Definition: donotalign.h:30
#define restrict
Definition: localconsts.h:165
#define override
Definition: localconsts.h:47
#define RETURNS_NONNULL
Definition: localconsts.h:167
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define A_UNUSED
Definition: localconsts.h:160
bool MainConfig
Definition: mainconfig.h:30
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472
bool OnTheFly
Definition: onthefly.h:30
bool Separator
Definition: separator.h:30
SetupItemNames::const_iterator SetupItemNamesConstIter
Definition: setupitem.h:453
std::vector< std::string > SetupItemNames
Definition: setupitem.h:451
SetupItemNames::iterator SetupItemNamesIter
Definition: setupitem.h:452
bool UseBase64
Definition: usebase64.h:30