ManaPlus
setupitem.cpp
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 #include "gui/widgets/setupitem.h"
23 
24 #include "configuration.h"
25 #include "soundmanager.h"
26 
27 #include "gui/gui.h"
28 
29 #include "gui/fonts/font.h"
30 
31 #include "gui/models/listmodel.h"
32 
33 #include "gui/windows/editdialog.h"
34 
35 #include "gui/widgets/button.h"
36 #include "gui/widgets/checkbox.h"
38 #include "gui/widgets/dropdown.h"
41 #include "gui/widgets/label.h"
42 #include "gui/widgets/slider.h"
43 #include "gui/widgets/sliderlist.h"
45 
47 
48 #include "utils/base64.h"
49 #include "utils/gettext.h"
50 #include "utils/stdmove.h"
51 #include "utils/mathutils.h"
52 
53 #include "debug.h"
54 
55 SetupItem::SetupItem(const std::string &restrict text,
56  const std::string &restrict description,
57  const std::string &restrict keyName,
58  SetupTabScroll *restrict const parent,
59  const std::string &restrict eventName,
60  const MainConfig mainConfig) :
62  Widget2(parent),
63  mText(text),
64  mDescription(description),
65  mKeyName(keyName),
66  mParent(parent),
67  mEventName(eventName),
68  mValue(),
69  mDefault(),
70  mWidget(nullptr),
71  mTempWidgets(),
72  mValueType(VBOOL),
73  mMainConfig(mainConfig),
74  mUseDefault(false)
75 {
76 }
77 
78 SetupItem::SetupItem(const std::string &restrict text,
79  const std::string &restrict description,
80  const std::string &restrict keyName,
81  SetupTabScroll *restrict const parent,
82  const std::string &restrict eventName,
83  const std::string &restrict def,
84  const MainConfig mainConfig) :
86  Widget2(parent),
87  mText(text),
88  mDescription(description),
89  mKeyName(keyName),
90  mParent(parent),
91  mEventName(eventName),
92  mValue(),
93  mDefault(def),
94  mWidget(nullptr),
95  mTempWidgets(),
96  mValueType(VBOOL),
97  mMainConfig(mainConfig),
98  mUseDefault(true)
99 {
100 }
101 
103 {
104 }
105 
107 {
109  return &config;
110  return &serverConfig;
111 }
112 
114 {
115  if (mKeyName.empty())
116  return;
117 
118  const Configuration *const cfg = getConfig();
119  if (mUseDefault)
120  {
121  mValue = cfg->getValue(mKeyName, mDefault);
122  }
123  else
124  {
125  switch (mValueType)
126  {
127  case VBOOL:
128  if (cfg->getBoolValue(mKeyName))
129  mValue = "1";
130  else
131  mValue = "0";
132  break;
133  case VSTR:
134  default:
136  break;
137  case VINT:
139  break;
140  case VNONE:
141  break;
142  }
143  }
144 }
145 
147 {
148  if (mKeyName.empty())
149  return;
150 
151  Configuration *const cfg = getConfig();
152  cfg->setValue(mKeyName, mValue);
153 }
154 
155 std::string SetupItem::getActionEventId() const
156 {
157  if (mWidget == nullptr)
158  return std::string();
159 
160  return mWidget->getActionEventId();
161 }
162 
163 void SetupItem::action(const ActionEvent &event)
164 {
165  if (mWidget == nullptr)
166  return;
167 
168  if (event.getId() == mWidget->getActionEventId())
169  doAction();
170 }
171 
173 {
174  fromWidget();
175 }
176 
177 void SetupItem::apply(const std::string &eventName A_UNUSED)
178 {
179  save();
180 }
181 
182 void SetupItem::cancel(const std::string &eventName A_UNUSED)
183 {
184  load();
185  toWidget();
186 }
187 
188 void SetupItem::externalUpdated(const std::string &eventName A_UNUSED)
189 {
190  load();
191  toWidget();
192 }
193 
194 void SetupItem::externalUnloaded(const std::string &eventName A_UNUSED)
195 {
196 }
197 
199 {
200  if (widget == nullptr)
201  return;
202  const int maxSize = mParent->getPreferredFirstItemSize();
203  if (widget->getWidth() < maxSize)
204  widget->setWidth(maxSize);
205 }
206 
208 {
209  load();
210  toWidget();
211 }
212 
214  const std::string &restrict description,
215  const std::string &restrict keyName,
216  SetupTabScroll *restrict const parent,
217  const std::string &restrict eventName,
218  const MainConfig mainConfig) :
219  SetupItem(text, description, keyName, parent, eventName, mainConfig),
220  mCheckBox(nullptr)
221 {
222  createControls();
223 }
224 
226  const std::string &restrict description,
227  const std::string &restrict keyName,
228  SetupTabScroll *restrict const parent,
229  const std::string &restrict eventName,
230  const std::string &restrict def,
231  const MainConfig mainConfig) :
232  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
233  mCheckBox(nullptr)
234 {
235  createControls();
236 }
237 
239 {
240  mWidget = nullptr;
241 }
242 
244 {
245  load();
246  mCheckBox = new CheckBox(this, mText, mValue != "0", mParent, mEventName);
248  mWidget = mCheckBox;
249  mParent->getContainer()->add1(mWidget, -1);
250  mParent->addControl(this);
251  mParent->addActionListener(this);
252  mWidget->addActionListener(this);
253 }
254 
256 {
257  if (mCheckBox == nullptr)
258  return;
259 
260  if (mCheckBox->isSelected())
261  mValue = "1";
262  else
263  mValue = "0";
264 }
265 
267 {
268  if (mCheckBox == nullptr)
269  return;
270 
271  mCheckBox->setSelected(mValue != "0");
272 }
273 
274 
276  const std::string &restrict description,
277  const std::string &restrict keyName,
278  SetupTabScroll *restrict const parent,
279  const std::string &restrict eventName,
280  const MainConfig mainConfig,
281  const UseBase64 useBase64) :
282  SetupItem(text, description, keyName, parent, eventName, mainConfig),
283  mHorizont(nullptr),
284  mLabel(nullptr),
285  mTextField(nullptr),
286  mButton(nullptr),
287  mEditDialog(nullptr),
288  mUseBase64(useBase64)
289 {
290  mValueType = VSTR;
291  createControls();
292 }
293 
295  const std::string &restrict description,
296  const std::string &restrict keyName,
297  SetupTabScroll *restrict const parent,
298  const std::string &restrict eventName,
299  const std::string &restrict def,
300  const MainConfig mainConfig,
301  const UseBase64 useBase64) :
302  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
303  mHorizont(nullptr),
304  mLabel(nullptr),
305  mTextField(nullptr),
306  mButton(nullptr),
307  mEditDialog(nullptr),
308  mUseBase64(useBase64)
309 {
310  mValueType = VSTR;
311  createControls();
312 }
313 
315 {
316  mHorizont = nullptr;
317  mWidget = nullptr;
318  mTextField = nullptr;
319  mLabel = nullptr;
320  mButton = nullptr;
321 }
322 
324 {
325  if (mUseBase64 == UseBase64_true)
326  {
327  std::string normalValue = mValue;
329  SetupItem::save();
330  mValue = STD_MOVE(normalValue);
331  }
332  else
333  {
334  SetupItem::save();
335  }
336 }
337 
338 void SetupItemTextField::cancel(const std::string &eventName A_UNUSED)
339 {
340  load();
341  if (mUseBase64 == UseBase64_true)
343  toWidget();
344 }
345 
346 void SetupItemTextField::externalUpdated(const std::string &eventName A_UNUSED)
347 {
348  load();
349  if (mUseBase64 == UseBase64_true)
351  toWidget();
352 }
353 
355 {
356  load();
357  if (mUseBase64 == UseBase64_true)
359  toWidget();
360 }
361 
363 {
364  load();
365  if (mUseBase64 == UseBase64_true)
367  mHorizont = new HorizontContainer(this, 32, 2);
368 
369  mLabel = new Label(this, mText);
371  mTextField = new TextField(this,
372  mValue,
374  mParent,
375  mEventName,
376  false);
377  mButton = new Button(this,
378  // TRANSLATORS: setup item button
379  _("Edit"),
380  mEventName + "_EDIT",
381  BUTTON_SKIN,
382  mParent);
384  mTextField->setWidth(200);
386  mHorizont->add(mLabel);
389 
390  mParent->getContainer()->add2(mHorizont, true, 4);
391  mParent->addControl(this);
392  mParent->addControl(this, mEventName + "_EDIT");
393  mParent->addControl(this, mEventName + "_EDIT_OK");
394  mParent->addActionListener(this);
395  mWidget->addActionListener(this);
396  mButton->addActionListener(this);
397 }
398 
400 {
401  if (mTextField == nullptr)
402  return;
403 
405 }
406 
408 {
409  if (mTextField == nullptr)
410  return;
411 
413 }
414 
416 {
417  if (mTextField == nullptr)
418  return;
419 
420  const std::string &eventId = event.getId();
421  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
422  {
423  fromWidget();
424  }
425  else if (eventId == mEventName + "_EDIT")
426  {
428  mText,
429  mTextField->getText(),
430  mEventName + "_EDIT_OK",
431  300,
432  nullptr,
433  Modal_true);
435  }
436  else if (eventId == mEventName + "_EDIT_OK")
437  {
439  mEditDialog = nullptr;
440  }
441 }
442 
443 void SetupItemTextField::apply(const std::string &eventName)
444 {
445  if (eventName != mEventName)
446  return;
447 
448  fromWidget();
449  save();
450 }
451 
453  const std::string &restrict
454  description,
455  const std::string &restrict
456  keyName,
458  const parent,
459  const std::string &restrict
460  eventName,
461  const int min, const int max,
462  const MainConfig mainConfig) :
463  SetupItem(text, description, keyName, parent, eventName, mainConfig),
464  mHorizont(nullptr),
465  mLabel(nullptr),
466  mTextField(nullptr),
467  mButton(nullptr),
468  mEditDialog(nullptr),
469  mMin(min),
470  mMax(max)
471 {
472  mValueType = VSTR;
473  createControls();
474 }
475 
477  const std::string &restrict
478  description,
479  const std::string &restrict
480  keyName,
482  const parent,
483  const std::string &restrict
484  eventName,
485  const int min, const int max,
486  const std::string &restrict def,
487  const MainConfig mainConfig) :
488  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
489  mHorizont(nullptr),
490  mLabel(nullptr),
491  mTextField(nullptr),
492  mButton(nullptr),
493  mEditDialog(nullptr),
494  mMin(min),
495  mMax(max)
496 {
497  mValueType = VSTR;
498  createControls();
499 }
500 
502 {
503  mHorizont = nullptr;
504  mWidget = nullptr;
505  mTextField = nullptr;
506  mLabel = nullptr;
507  mButton = nullptr;
508 }
509 
511 {
512  load();
513  mHorizont = new HorizontContainer(this, 32, 2);
514 
515  mLabel = new Label(this, mText);
517  mTextField = new IntTextField(this, atoi(mValue.c_str()),
518  mMin, mMax, Enable_true, 30);
521 
522  mButton = new Button(this,
523  // TRANSLATORS: setup item button
524  _("Edit"),
525  mEventName + "_EDIT",
526  BUTTON_SKIN,
527  mParent);
529  mTextField->setWidth(50);
531  mHorizont->add(mLabel);
534 
535  mParent->getContainer()->add2(mHorizont, true, 4);
536  mParent->addControl(this);
537  mParent->addControl(this, mEventName + "_EDIT");
538  mParent->addControl(this, mEventName + "_EDIT_OK");
539  mParent->addActionListener(this);
540  mWidget->addActionListener(this);
541  mButton->addActionListener(this);
542 }
543 
545 {
546  if (mTextField == nullptr)
547  return;
548 
550 }
551 
553 {
554  if (mTextField == nullptr)
555  return;
556 
558 }
559 
561 {
562  if (mTextField == nullptr)
563  return;
564 
565  const std::string &eventId = event.getId();
566  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
567  {
568  fromWidget();
569  }
570  else if (eventId == mEventName + "_EDIT")
571  {
573  mText,
574  mTextField->getText(),
575  mEventName + "_EDIT_OK",
576  300,
577  nullptr,
578  Modal_true);
580  }
581  else if (eventId == mEventName + "_EDIT_OK")
582  {
583  mTextField->setValue(atoi(mEditDialog->getMsg().c_str()));
584  mEditDialog = nullptr;
585  }
586 }
587 
588 void SetupItemIntTextField::apply(const std::string &eventName)
589 {
590  if (eventName != mEventName)
591  return;
592 
593  fromWidget();
594  save();
595 }
596 
597 
598 SetupItemLabel::SetupItemLabel(const std::string &restrict text,
599  const std::string &restrict description,
600  SetupTabScroll *restrict const parent,
601  const Separator separator) :
602  SetupItem(text, description, "", parent, "", "", MainConfig_true),
603  mLabel(nullptr),
604  mIsSeparator(separator)
605 {
606  mValueType = VNONE;
607  createControls();
608 }
609 
611 {
612  mWidget = nullptr;
613  mLabel = nullptr;
614 }
615 
617 {
619  {
620  const std::string str(" \342\200\225\342\200\225\342\200\225"
621  "\342\200\225\342\200\225 ");
622  mLabel = new Label(this, std::string(str).append(mText).append(str));
623  }
624  else
625  {
626  mLabel = new Label(this, mText);
627  }
629 
630  mWidget = mLabel;
631  mParent->getContainer()->add1(mWidget, -1);
632  mParent->addControl(this);
633  mParent->addActionListener(this);
634  mWidget->addActionListener(this);
635 }
636 
638 {
639 }
640 
642 {
643 }
644 
646 {
647 }
648 
649 void SetupItemLabel::apply(const std::string &eventName A_UNUSED)
650 {
651 }
652 
653 
655  const std::string &restrict description,
656  const std::string &restrict keyName,
657  SetupTabScroll *restrict const parent,
658  const std::string &restrict eventName,
659  ListModel *restrict const model,
660  const int width,
661  const MainConfig mainConfig) :
662  SetupItem(text, description, keyName, parent, eventName, mainConfig),
663  mHorizont(nullptr),
664  mLabel(nullptr),
665  mModel(model),
666  mDropDown(nullptr),
667  mWidth(width)
668 {
669  mValueType = VSTR;
670  createControls();
671 }
672 
674  const std::string &restrict description,
675  const std::string &restrict keyName,
676  SetupTabScroll *restrict const parent,
677  const std::string &restrict eventName,
678  ListModel *restrict const model,
679  const int width,
680  const std::string &restrict def,
681  const MainConfig mainConfig) :
682  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
683  mHorizont(nullptr),
684  mLabel(nullptr),
685  mModel(model),
686  mDropDown(nullptr),
687  mWidth(width)
688 {
689  mValueType = VSTR;
690  createControls();
691 }
692 
694 {
695  mHorizont = nullptr;
696  mWidget = nullptr;
697  mModel = nullptr;
698  mDropDown = nullptr;
699  mLabel = nullptr;
700 }
701 
703 {
704  load();
705  mHorizont = new HorizontContainer(this, 32, 2);
706 
707  mLabel = new Label(this, mText);
709  mDropDown = new DropDown(this,
710  mModel,
711  false,
712  Modal_false,
713  nullptr,
714  std::string());
719 
720  mWidget = mDropDown;
721  if (!mText.empty())
723  mHorizont->add(mLabel);
725 
726  mParent->getContainer()->add2(mHorizont, true, 4);
727  mParent->addControl(this);
728  mParent->addActionListener(this);
729  mWidget->addActionListener(this);
730 }
731 
733 {
734  return atoi(mValue.c_str());
735 }
736 
738 {
739  if (mDropDown == nullptr)
740  return;
741 
743 }
744 
746 {
747  if (mDropDown == nullptr)
748  return;
749 
751 }
752 
753 
755  const std::string &restrict
756  description,
757  const std::string &restrict keyName,
758  SetupTabScroll *restrict const
759  parent,
760  const std::string &restrict
761  eventName,
762  ListModel *restrict const model,
763  const int width,
764  const MainConfig mainConfig) :
765  SetupItem(text, description, keyName, parent, eventName, mainConfig),
766  mHorizont(nullptr),
767  mLabel(nullptr),
768  mModel(model),
769  mDropDown(nullptr),
770  mWidth(width)
771 {
772  mValueType = VSTR;
773  createControls();
774 }
775 
777  const std::string &restrict
778  description,
779  const std::string &restrict keyName,
780  SetupTabScroll *restrict const
781  parent,
782  const std::string &restrict
783  eventName,
784  ListModel *restrict const model,
785  const int width,
786  const std::string &restrict def,
787  const MainConfig mainConfig) :
788  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
789  mHorizont(nullptr),
790  mLabel(nullptr),
791  mModel(model),
792  mDropDown(nullptr),
793  mWidth(width)
794 {
795  mValueType = VSTR;
796  createControls();
797 }
798 
800 {
801  mHorizont = nullptr;
802  mWidget = nullptr;
803  mModel = nullptr;
804  mDropDown = nullptr;
805  mLabel = nullptr;
806 }
807 
809 {
810  load();
811  mHorizont = new HorizontContainer(this, 32, 2);
812 
813  mLabel = new Label(this, mText);
815  mDropDown = new DropDown(this,
816  mModel,
817  false,
818  Modal_false,
819  nullptr,
820  std::string());
825 
826  mWidget = mDropDown;
827  if (!mText.empty())
829  mHorizont->add(mLabel);
831 
832  mParent->getContainer()->add2(mHorizont, true, 4);
833  mParent->addControl(this);
834  mParent->addActionListener(this);
835  mWidget->addActionListener(this);
836 }
837 
839 {
840  const int sz = mModel->getNumberOfElements();
841  for (int f = 0; f < sz; f ++)
842  {
843  if (mModel->getElementAt(f) == mValue)
844  {
845  return f;
846  }
847  }
848  return 0;
849 }
850 
852 {
853  if (mDropDown == nullptr)
854  return;
855 
856  const int sel = mDropDown->getSelected();
857  // use first element in model as empty string
858  if (sel == 0 || sel >= mModel->getNumberOfElements())
859  mValue.clear();
860  else
861  mValue = mModel->getElementAt(sel);
862 }
863 
865 {
866  if (mDropDown == nullptr)
867  return;
868 
870 }
871 
872 
874  const std::string &restrict description,
875  const std::string &restrict keyName,
876  SetupTabScroll *restrict const parent,
877  const std::string &restrict eventName,
878  const double min,
879  const double max,
880  const double step,
881  const int width,
882  const OnTheFly onTheFly,
883  const MainConfig mainConfig) :
884  SetupItem(text, description, keyName, parent, eventName, mainConfig),
885  mHorizont(nullptr),
886  mLabel(nullptr),
887  mSlider(nullptr),
888  mMin(min),
889  mMax(max),
890  mStep(step),
891  mWidth(width),
892  mOnTheFly(onTheFly)
893 {
894  mValueType = VSTR;
895  createControls();
896 }
897 
899  const std::string &restrict description,
900  const std::string &restrict keyName,
901  SetupTabScroll *restrict const parent,
902  const std::string &restrict eventName,
903  const double min,
904  const double max,
905  const double step,
906  const std::string &restrict def,
907  const int width,
908  const OnTheFly onTheFly,
909  const MainConfig mainConfig) :
910  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
911  mHorizont(nullptr),
912  mLabel(nullptr),
913  mSlider(nullptr),
914  mMin(min),
915  mMax(max),
916  mStep(step),
917  mWidth(width),
918  mOnTheFly(onTheFly)
919 {
920  mValueType = VSTR;
921  createControls();
922 }
923 
925 {
926  mHorizont = nullptr;
927  mWidget = nullptr;
928  mSlider = nullptr;
929  mLabel = nullptr;
930 }
931 
933 {
934  load();
935  mHorizont = new HorizontContainer(this, 32, 2);
936 
937  mLabel = new Label(this, mText);
939  mSlider = new Slider(this, mMin, mMax, mStep);
942  mSlider->setValue(atof(mValue.c_str()));
943  mSlider->setHeight(30);
944 
945  mWidget = mSlider;
947  mSlider->setHeight(40);
949  mHorizont->add(mLabel);
950  mHorizont->add(mSlider, -10);
951 
952  mParent->getContainer()->add2(mHorizont, true, 4);
953  mParent->addControl(this);
954  mParent->addActionListener(this);
955  mWidget->addActionListener(this);
956 }
957 
959 {
960  if (mSlider == nullptr)
961  return;
962 
964 }
965 
967 {
968  if (mSlider == nullptr)
969  return;
970 
971  mSlider->setValue(atof(mValue.c_str()));
972 }
973 
975 {
976  fromWidget();
977  if (mOnTheFly == OnTheFly_true)
978  save();
979 }
980 
981 void SetupItemSlider::apply(const std::string &eventName)
982 {
983  if (eventName != mEventName)
984  return;
985 
986  fromWidget();
987  save();
988 }
989 
990 
992  const std::string &restrict description,
993  const std::string &restrict keyName,
994  SetupTabScroll *restrict const parent,
995  const std::string &restrict eventName,
996  const int min,
997  const int max,
998  const int step,
1000  const OnTheFly onTheFly,
1001  const MainConfig mainConfig,
1002  const DoNotAlign doNotAlign) :
1003  SetupItem(text, description, keyName, parent, eventName, mainConfig),
1004  mHorizont(nullptr),
1005  mLabel(nullptr),
1006  mLabel2(nullptr),
1007  mSlider(nullptr),
1008  mValues(values),
1009  mMin(min),
1010  mMax(max),
1011  mStep(step),
1012  mInvertValue(0),
1013  mInvert(false),
1014  mOnTheFly(onTheFly),
1015  mDoNotAlign(doNotAlign)
1016 {
1017  mValueType = VSTR;
1018  createControls();
1019 }
1020 
1022  const std::string &restrict description,
1023  const std::string &restrict keyName,
1024  SetupTabScroll *restrict const parent,
1025  const std::string &restrict eventName,
1026  const int min,
1027  const int max,
1028  const int step,
1030  const std::string &restrict def,
1031  const OnTheFly onTheFly,
1032  const MainConfig mainConfig,
1033  const DoNotAlign doNotAlign) :
1034  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1035  mHorizont(nullptr),
1036  mLabel(nullptr),
1037  mLabel2(nullptr),
1038  mSlider(nullptr),
1039  mValues(values),
1040  mMin(min),
1041  mMax(max),
1042  mStep(step),
1043  mInvertValue(0),
1044  mInvert(false),
1045  mOnTheFly(onTheFly),
1046  mDoNotAlign(doNotAlign)
1047 {
1048  mValueType = VSTR;
1049  createControls();
1050 }
1051 
1053 {
1054  mHorizont = nullptr;
1055  mWidget = nullptr;
1056  mSlider = nullptr;
1057  mLabel = nullptr;
1058 }
1059 
1061 {
1062  load();
1063  mHorizont = new HorizontContainer(this, 32, 2);
1064 
1065  const int width = getMaxWidth();
1066 
1067  mLabel = new Label(this, mText);
1069  mLabel2 = new Label(this, "");
1070  mLabel2->setWidth(width);
1071  mSlider = new Slider(this, mMin, mMax, mStep);
1074  mSlider->setValue(atof(mValue.c_str()));
1075  mSlider->setHeight(30);
1076 
1077  mWidget = mSlider;
1078  mSlider->setWidth(150);
1079  mSlider->setHeight(40);
1082  mHorizont->add(mLabel);
1083  mHorizont->add(mSlider, -10);
1084  mHorizont->add(mLabel2);
1085 
1086  mParent->getContainer()->add2(mHorizont, true, 4);
1087  mParent->addControl(this);
1088  mParent->addActionListener(this);
1089  mWidget->addActionListener(this);
1090  updateLabel();
1091 }
1092 
1094 {
1095  if ((mValues == nullptr) || (gui == nullptr))
1096  return 1;
1097 
1098  int maxWidth = 0;
1099  SetupItemNamesConstIter it = mValues->begin();
1100  const SetupItemNamesConstIter it_end = mValues->end();
1101  const Font *const font = gui->getFont();
1102 
1103  while (it != it_end)
1104  {
1105  const int w = font->getWidth(*it);
1106  if (w > maxWidth)
1107  maxWidth = w;
1108 
1109  ++ it;
1110  }
1111  return maxWidth;
1112 }
1113 
1115 {
1116  if (mSlider == nullptr)
1117  return;
1118 
1119  int val = roundDouble(mSlider->getValue());
1120  if (mInvert)
1121  val = mInvertValue - val;
1122  mValue = toString(val);
1123 }
1124 
1126 {
1127  if (mSlider == nullptr)
1128  return;
1129 
1130  int val = roundDouble(atof(mValue.c_str()));
1131  if (mInvert)
1132  val = mInvertValue - val;
1133  mSlider->setValue(val);
1134  updateLabel();
1135 }
1136 
1138 {
1139  fromWidget();
1140  updateLabel();
1141  if (mOnTheFly == OnTheFly_true)
1142  save();
1143 }
1144 
1146 {
1147  int val = CAST_S32(mSlider->getValue()) - mMin;
1148  if (val < 0)
1149  {
1150  val = 0;
1151  }
1152  else
1153  {
1154  const int sz = CAST_S32(mValues->size());
1155  if (val >= sz)
1156  val = sz - 1;
1157  }
1158  std::string str = mValues->at(val);
1159  mLabel2->setCaption(str);
1160 }
1161 
1162 void SetupItemSlider2::apply(const std::string &eventName)
1163 {
1164  if (eventName != mEventName)
1165  return;
1166 
1167  fromWidget();
1168  save();
1169 }
1170 
1172 {
1173  mInvert = true;
1174  mInvertValue = v;
1175  toWidget();
1176 }
1177 
1178 
1180  const std::string &restrict
1181  description,
1182  const std::string &restrict keyName,
1183  SetupTabScroll *restrict const parent,
1184  const std::string &restrict eventName,
1185  ListModel *restrict const model,
1186  const int width,
1187  const OnTheFly onTheFly,
1188  const MainConfig mainConfig) :
1189  SetupItem(text, description, keyName, parent, eventName, mainConfig),
1190  mHorizont(nullptr),
1191  mLabel(nullptr),
1192  mSlider(nullptr),
1193  mModel(model),
1194  mWidth(width),
1195  mOnTheFly(onTheFly)
1196 {
1197  mValueType = VSTR;
1198 }
1199 
1201  const std::string &restrict
1202  description,
1203  const std::string &restrict keyName,
1204  SetupTabScroll *restrict const parent,
1205  const std::string &restrict eventName,
1206  ListModel *restrict const model,
1207  const std::string &restrict def,
1208  const int width,
1209  const OnTheFly onTheFly,
1210  const MainConfig mainConfig) :
1211  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1212  mHorizont(nullptr),
1213  mLabel(nullptr),
1214  mSlider(nullptr),
1215  mModel(model),
1216  mWidth(width),
1217  mOnTheFly(onTheFly)
1218 {
1219  mValueType = VSTR;
1220 }
1221 
1223 {
1224  mHorizont = nullptr;
1225  mWidget = nullptr;
1226  mSlider = nullptr;
1227  mLabel = nullptr;
1228 }
1229 
1231 {
1232  load();
1233  mHorizont = new HorizontContainer(this, 32, 2);
1234 
1235  mLabel = new Label(this, mText);
1237  mSlider = new SliderList(this, mModel);
1240  mSlider->adjustSize();
1241 
1242  mWidget = mSlider;
1244  mHorizont->add(mLabel, 5);
1245  mHorizont->add(mSlider);
1246 
1247  addMoreControls();
1248 
1249  mParent->getContainer()->add2(mHorizont, true, 4);
1250  mParent->addControl(this);
1251  mParent->addActionListener(this);
1252  mWidget->addActionListener(this);
1253 }
1254 
1256 {
1257  if (mSlider == nullptr)
1258  return;
1259 
1261 }
1262 
1264 {
1265  if (mSlider == nullptr)
1266  return;
1267 
1269 }
1270 
1272 {
1273  fromWidget();
1274  if (mOnTheFly == OnTheFly_true)
1275  save();
1276 }
1277 
1278 void SetupItemSliderList::apply(const std::string &eventName)
1279 {
1280  if (eventName != mEventName)
1281  return;
1282 
1283  fromWidget();
1284  save();
1285 }
1286 
1288  const std::string &restrict description,
1289  const std::string &restrict keyName,
1290  SetupTabScroll *restrict const parent,
1291  const std::string &restrict eventName,
1292  ListModel *restrict const model,
1293  const int width,
1294  const OnTheFly onTheFly,
1295  const MainConfig mainConfig) :
1296  SetupItemSliderList(text, description, keyName, parent, eventName,
1297  model, width, onTheFly, mainConfig),
1298  mButton(nullptr)
1299 {
1300  createControls();
1301 }
1302 
1304 {
1305  mButton = new Button(this,
1306  BUTTON_PLAY,
1307  16, 16,
1308  mEventName + "_PLAY",
1309  BUTTON_SKIN,
1310  this);
1311  if (mHorizont != nullptr)
1312  mHorizont->add(mButton);
1313 }
1314 
1316 {
1317  if (event.getId() == mEventName + "_PLAY")
1318  {
1319  if ((mSlider != nullptr) && (mSlider->getSelected() != 0))
1320  {
1322  "systemsounds"),
1323  mSlider->getSelectedString()).append(".ogg"));
1324  }
1325  }
1326  else
1327  {
1329  }
1330 }
1331 
1333  const std::string &restrict description,
1334  const std::string &restrict keyName,
1335  SetupTabScroll *restrict const parent,
1336  const std::string &restrict eventName,
1337  ListModel *restrict const model,
1338  const int min,
1339  const int width,
1340  const OnTheFly onTheFly,
1341  const MainConfig mainConfig) :
1342  SetupItemSliderList(text, description, keyName, parent, eventName,
1343  model, width, onTheFly, mainConfig),
1344  mMin(min)
1345 {
1346  createControls();
1347 }
1348 
1350 {
1351  toWidget();
1352 }
1353 
1355 {
1356  if (mSlider == nullptr)
1357  return;
1358 
1360 }
1361 
1363 {
1364  if (mSlider == nullptr)
1365  return;
1366 
1367  mSlider->setSelected(atoi(mValue.c_str()) - mMin);
1368 }
std::string decodeBase64String(std::string value)
Definition: base64.cpp:203
std::string encodeBase64String(std::string value)
Definition: base64.cpp:188
const std::string BUTTON_SKIN
Definition: button.h:89
const std::string BUTTON_PLAY
Definition: button.h:88
#define CAST_S32
Definition: cast.h:30
const std::string & getId() const
Definition: actionevent.h:122
Definition: button.h:102
void setSelected(const bool selected)
Definition: checkbox.h:156
bool isSelected() const
Definition: checkbox.h:147
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
void setValue(const std::string &key, const std::string &value)
int getIntValue(const std::string &key) const
int getSelected() const
Definition: dropdown.cpp:509
void setSelected(int selected)
Definition: dropdown.cpp:514
std::string getMsg() const
Definition: editdialog.h:65
Definition: font.h:90
int getWidth(const std::string &text) const
Definition: font.cpp:334
Font * getFont() const
Definition: gui.h:160
void add(Widget *const widget)
void setValue(const int value)
Definition: label.h:91
void setCaption(const std::string &caption)
Definition: label.cpp:264
virtual std::string getElementAt(int i)=0
virtual int getNumberOfElements()=0
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 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
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
virtual void apply(const std::string &eventName)
Definition: setupitem.cpp:177
virtual void doAction()
Definition: setupitem.cpp:172
SetupTabScroll * mParent
Definition: setupitem.h:135
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 mKeyName
Definition: setupitem.h:133
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
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
int getPreferredFirstItemSize() const
void addControl(SetupItem *const widget)
VertContainer * getContainer() const
void setSelectedString(const std::string &str)
Definition: sliderlist.cpp:190
int getSelected() const
Definition: sliderlist.h:73
void setSelected(const int idx)
Definition: sliderlist.cpp:213
void adjustSize()
Definition: sliderlist.cpp:227
std::string getSelectedString() const
Definition: sliderlist.cpp:205
void postInit2(ActionListener *const listener, const std::string &eventId)
Definition: sliderlist.cpp:56
Definition: slider.h:89
double getValue() const
Definition: slider.h:204
void setValue(const double value)
Definition: slider.cpp:474
void playGuiSfx(const std::string &path)
const std::string & getText() const
Definition: textfield.h:224
void setText(const std::string &text)
Definition: textfield.cpp:803
void setToolTip(const std::string &str)
void add2(Widget *const widget, const bool resizable, const int spacing)
void add1(Widget *const widget, const int spacing)
Definition: widget.h:99
void setWidth(const int width)
Definition: widget.cpp:133
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
const std::string & getActionEventId() const
Definition: widget.h:605
int getWidth() const
Definition: widget.h:221
Configuration config
Configuration serverConfig
Configuration branding
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
bool DoNotAlign
Definition: donotalign.h:30
const bool DoNotAlign_false
Definition: donotalign.h:30
const bool Enable_true
Definition: enable.h:30
#define _(s)
Definition: gettext.h:35
Gui * gui
Definition: gui.cpp:111
#define restrict
Definition: localconsts.h:165
#define nullptr
Definition: localconsts.h:45
#define A_UNUSED
Definition: localconsts.h:160
const bool LoseFocusOnTab_true
const bool MainConfig_true
Definition: mainconfig.h:30
bool MainConfig
Definition: mainconfig.h:30
int roundDouble(const double v)
Definition: mathutils.h:232
const bool Modal_false
Definition: modal.h:30
const bool Modal_true
Definition: modal.h:30
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
const bool OnTheFly_true
Definition: onthefly.h:30
bool OnTheFly
Definition: onthefly.h:30
bool Separator
Definition: separator.h:30
const bool Separator_true
Definition: separator.h:30
SetupItemNames::const_iterator SetupItemNamesConstIter
Definition: setupitem.h:453
std::vector< std::string > SetupItemNames
Definition: setupitem.h:451
SoundManager soundManager
#define STD_MOVE(var)
Definition: stdmove.h:28
std::string pathJoin(std::string str1, const std::string &str2)
bool UseBase64
Definition: usebase64.h:30
const bool UseBase64_true
Definition: usebase64.h:30