GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/setupitem.h Lines: 2 6 33.3 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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
25
#include "enums/simpletypes/donotalign.h"
26
#include "enums/simpletypes/mainconfig.h"
27
#include "enums/simpletypes/onthefly.h"
28
#include "enums/simpletypes/usebase64.h"
29
#include "enums/simpletypes/separator.h"
30
31
#include "gui/widgets/widget2.h"
32
33
#include "listeners/actionlistener.h"
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
51
class SetupItem notfinal : public ActionListener,
52
                           public Widget2
53
{
54
    public:
55
        enum
56
        {
57
            VBOOL = 0,
58
            VSTR,
59
            VINT,
60
            VNONE
61
        };
62
63
        A_DELETE_COPY(SetupItem)
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
78
        Widget *getWidget() const noexcept2 A_WARN_UNUSED
79
        { return mWidget; }
80
81
        Configuration *getConfig() const RETURNS_NONNULL A_WARN_UNUSED;
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
97
        MainConfig isMainConfig() const noexcept2 A_WARN_UNUSED
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
135
        SetupTabScroll *mParent;
136
137
        std::string mEventName;
138
139
        std::string mValue;
140
141
        std::string mDefault;
142
143
        Widget *mWidget;
144
145
        std::list<Widget*> mTempWidgets;
146
147
        int mValueType;
148
149
        MainConfig mMainConfig;
150
151
        bool mUseDefault;
152
};
153
154
class SetupItemCheckBox final : public SetupItem
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
172
        A_DELETE_COPY(SetupItemCheckBox)
173
174
        ~SetupItemCheckBox() override final;
175
176
        void createControls();
177
178
        void fromWidget() override final;
179
180
        void toWidget() override final;
181
182
    protected:
183
        CheckBox *mCheckBox;
184
};
185
186
class SetupItemTextField final : public SetupItem
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
206
        A_DELETE_COPY(SetupItemTextField)
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:
233
        HorizontContainer *mHorizont;
234
        Label *mLabel;
235
        TextField *mTextField;
236
        Button *mButton;
237
        EditDialog *mEditDialog;
238
        UseBase64 mUseBase64;
239
};
240
241
class SetupItemIntTextField final : public SetupItem
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
261
        A_DELETE_COPY(SetupItemIntTextField)
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:
276
        HorizontContainer *mHorizont;
277
        Label *mLabel;
278
        IntTextField *mTextField;
279
        Button *mButton;
280
        EditDialog *mEditDialog;
281
        int mMin;
282
        int mMax;
283
};
284
285
class SetupItemLabel final : public SetupItem
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
293
        A_DELETE_COPY(SetupItemLabel)
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:
308
        Label *mLabel;
309
        Separator mIsSeparator;
310
};
311
312
class SetupItemDropDown final : public SetupItem
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
334
        A_DELETE_COPY(SetupItemDropDown)
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:
347
        HorizontContainer *mHorizont;
348
        Label *mLabel;
349
        ListModel *mModel;
350
        DropDown *mDropDown;
351
        int mWidth;
352
};
353
354
class SetupItemDropDownStr final : public SetupItem
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
376
        A_DELETE_COPY(SetupItemDropDownStr)
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:
389
        HorizontContainer *mHorizont;
390
        Label *mLabel;
391
        ListModel *mModel;
392
        DropDown *mDropDown;
393
        int mWidth;
394
};
395
396
class SetupItemSlider final : public SetupItem
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
424
        A_DELETE_COPY(SetupItemSlider)
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:
441
        HorizontContainer *mHorizont;
442
        Label *mLabel;
443
        Slider *mSlider;
444
        double mMin;
445
        double mMax;
446
        double mStep;
447
        int mWidth;
448
        OnTheFly mOnTheFly;
449
};
450
451
typedef STD_VECTOR<std::string> SetupItemNames;
452
typedef SetupItemNames::iterator SetupItemNamesIter;
453
typedef SetupItemNames::const_iterator SetupItemNamesConstIter;
454
455
class SetupItemSlider2 final : public SetupItem
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,
464
                         SetupItemNames *restrict const values,
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,
475
                         SetupItemNames *restrict const values,
476
                         const std::string &restrict def,
477
                         const OnTheFly onTheFly,
478
                         const MainConfig mainConfig,
479
                         const DoNotAlign doNotAlign);
480
481
        A_DELETE_COPY(SetupItemSlider2)
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
502
        HorizontContainer *mHorizont;
503
        Label *mLabel;
504
        Label *mLabel2;
505
        Slider *mSlider;
506
        SetupItemNames *mValues;
507
        int mMin;
508
        int mMax;
509
        int mStep;
510
        int mInvertValue;
511
        bool mInvert;
512
        OnTheFly mOnTheFly;
513
        DoNotAlign mDoNotAlign;
514
};
515
516
class SetupItemSliderList notfinal : public SetupItem
517
{
518
    public:
519
        A_DELETE_COPY(SetupItemSliderList)
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
557
        HorizontContainer *mHorizont;
558
        Label *mLabel;
559
        SliderList *mSlider;
560
        ListModel *mModel;
561
        int mWidth;
562
        OnTheFly mOnTheFly;
563
};
564
565
48
class SetupItemSound final : public SetupItemSliderList
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
578
        A_DELETE_COPY(SetupItemSound)
579
580
        void action(const ActionEvent &event) override final;
581
582
        void addMoreControls() override final;
583
584
    protected:
585
        Button *mButton;
586
};
587
588
4
class SetupItemSliderInt final : public SetupItemSliderList
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
602
        A_DELETE_COPY(SetupItemSliderInt)
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