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