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

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