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  // TRANSLATORS: setup item button
377  mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
379  mTextField->setWidth(200);
381  mHorizont->add(mLabel);
384 
385  mParent->getContainer()->add2(mHorizont, true, 4);
386  mParent->addControl(this);
387  mParent->addControl(this, mEventName + "_EDIT");
388  mParent->addControl(this, mEventName + "_EDIT_OK");
389  mParent->addActionListener(this);
390  mWidget->addActionListener(this);
391  mButton->addActionListener(this);
392 }
393 
395 {
396  if (mTextField == nullptr)
397  return;
398 
400 }
401 
403 {
404  if (mTextField == nullptr)
405  return;
406 
408 }
409 
411 {
412  if (mTextField == nullptr)
413  return;
414 
415  const std::string &eventId = event.getId();
416  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
417  {
418  fromWidget();
419  }
420  else if (eventId == mEventName + "_EDIT")
421  {
423  mText,
424  mTextField->getText(),
425  mEventName + "_EDIT_OK",
426  300,
427  nullptr,
428  Modal_true);
430  }
431  else if (eventId == mEventName + "_EDIT_OK")
432  {
434  mEditDialog = nullptr;
435  }
436 }
437 
438 void SetupItemTextField::apply(const std::string &eventName)
439 {
440  if (eventName != mEventName)
441  return;
442 
443  fromWidget();
444  save();
445 }
446 
448  const std::string &restrict
449  description,
450  const std::string &restrict
451  keyName,
453  const parent,
454  const std::string &restrict
455  eventName,
456  const int min, const int max,
457  const MainConfig mainConfig) :
458  SetupItem(text, description, keyName, parent, eventName, mainConfig),
460  mLabel(nullptr),
462  mButton(nullptr),
464  mMin(min),
465  mMax(max)
466 {
467  mValueType = VSTR;
468  createControls();
469 }
470 
472  const std::string &restrict
473  description,
474  const std::string &restrict
475  keyName,
477  const parent,
478  const std::string &restrict
479  eventName,
480  const int min, const int max,
481  const std::string &restrict def,
482  const MainConfig mainConfig) :
483  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
485  mLabel(nullptr),
487  mButton(nullptr),
489  mMin(min),
490  mMax(max)
491 {
492  mValueType = VSTR;
493  createControls();
494 }
495 
497 {
498  mHorizont = nullptr;
499  mWidget = nullptr;
500  mTextField = nullptr;
501  mLabel = nullptr;
502  mButton = nullptr;
503 }
504 
506 {
507  load();
508  mHorizont = new HorizontContainer(this, 32, 2);
509 
510  mLabel = new Label(this, mText);
512  mTextField = new IntTextField(this, atoi(mValue.c_str()),
513  mMin, mMax, Enable_true, 30);
516 
517  // TRANSLATORS: setup item button
518  mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
520  mTextField->setWidth(50);
522  mHorizont->add(mLabel);
525 
526  mParent->getContainer()->add2(mHorizont, true, 4);
527  mParent->addControl(this);
528  mParent->addControl(this, mEventName + "_EDIT");
529  mParent->addControl(this, mEventName + "_EDIT_OK");
530  mParent->addActionListener(this);
531  mWidget->addActionListener(this);
532  mButton->addActionListener(this);
533 }
534 
536 {
537  if (mTextField == nullptr)
538  return;
539 
541 }
542 
544 {
545  if (mTextField == nullptr)
546  return;
547 
549 }
550 
552 {
553  if (mTextField == nullptr)
554  return;
555 
556  const std::string &eventId = event.getId();
557  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
558  {
559  fromWidget();
560  }
561  else if (eventId == mEventName + "_EDIT")
562  {
564  mText,
565  mTextField->getText(),
566  mEventName + "_EDIT_OK",
567  300,
568  nullptr,
569  Modal_true);
571  }
572  else if (eventId == mEventName + "_EDIT_OK")
573  {
574  mTextField->setValue(atoi(mEditDialog->getMsg().c_str()));
575  mEditDialog = nullptr;
576  }
577 }
578 
579 void SetupItemIntTextField::apply(const std::string &eventName)
580 {
581  if (eventName != mEventName)
582  return;
583 
584  fromWidget();
585  save();
586 }
587 
588 
589 SetupItemLabel::SetupItemLabel(const std::string &restrict text,
590  const std::string &restrict description,
591  SetupTabScroll *restrict const parent,
592  const Separator separator) :
593  SetupItem(text, description, "", parent, "", "", MainConfig_true),
594  mLabel(nullptr),
595  mIsSeparator(separator)
596 {
597  mValueType = VNONE;
598  createControls();
599 }
600 
602 {
603  mWidget = nullptr;
604  mLabel = nullptr;
605 }
606 
608 {
610  {
611  const std::string str(" \342\200\225\342\200\225\342\200\225"
612  "\342\200\225\342\200\225 ");
613  mLabel = new Label(this, std::string(str).append(mText).append(str));
614  }
615  else
616  {
617  mLabel = new Label(this, mText);
618  }
620 
621  mWidget = mLabel;
622  mParent->getContainer()->add1(mWidget, -1);
623  mParent->addControl(this);
624  mParent->addActionListener(this);
625  mWidget->addActionListener(this);
626 }
627 
629 {
630 }
631 
633 {
634 }
635 
637 {
638 }
639 
640 void SetupItemLabel::apply(const std::string &eventName A_UNUSED)
641 {
642 }
643 
644 
646  const std::string &restrict description,
647  const std::string &restrict keyName,
648  SetupTabScroll *restrict const parent,
649  const std::string &restrict eventName,
650  ListModel *restrict const model,
651  const int width,
652  const MainConfig mainConfig) :
653  SetupItem(text, description, keyName, parent, eventName, mainConfig),
654  mHorizont(nullptr),
655  mLabel(nullptr),
656  mModel(model),
657  mDropDown(nullptr),
658  mWidth(width)
659 {
660  mValueType = VSTR;
661  createControls();
662 }
663 
665  const std::string &restrict description,
666  const std::string &restrict keyName,
667  SetupTabScroll *restrict const parent,
668  const std::string &restrict eventName,
669  ListModel *restrict const model,
670  const int width,
671  const std::string &restrict def,
672  const MainConfig mainConfig) :
673  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
675  mLabel(nullptr),
676  mModel(model),
678  mWidth(width)
679 {
680  mValueType = VSTR;
681  createControls();
682 }
683 
685 {
686  mHorizont = nullptr;
687  mWidget = nullptr;
688  mModel = nullptr;
689  mDropDown = nullptr;
690  mLabel = nullptr;
691 }
692 
694 {
695  load();
696  mHorizont = new HorizontContainer(this, 32, 2);
697 
698  mLabel = new Label(this, mText);
700  mDropDown = new DropDown(this,
701  mModel,
702  false,
703  Modal_false,
704  nullptr,
705  std::string());
710 
711  mWidget = mDropDown;
712  if (!mText.empty())
714  mHorizont->add(mLabel);
716 
717  mParent->getContainer()->add2(mHorizont, true, 4);
718  mParent->addControl(this);
719  mParent->addActionListener(this);
720  mWidget->addActionListener(this);
721 }
722 
724 {
725  return atoi(mValue.c_str());
726 }
727 
729 {
730  if (mDropDown == nullptr)
731  return;
732 
734 }
735 
737 {
738  if (mDropDown == nullptr)
739  return;
740 
742 }
743 
744 
746  const std::string &restrict
747  description,
748  const std::string &restrict keyName,
749  SetupTabScroll *restrict const
750  parent,
751  const std::string &restrict
752  eventName,
753  ListModel *restrict const model,
754  const int width,
755  const MainConfig mainConfig) :
756  SetupItem(text, description, keyName, parent, eventName, mainConfig),
758  mLabel(nullptr),
759  mModel(model),
761  mWidth(width)
762 {
763  mValueType = VSTR;
764  createControls();
765 }
766 
768  const std::string &restrict
769  description,
770  const std::string &restrict keyName,
771  SetupTabScroll *restrict const
772  parent,
773  const std::string &restrict
774  eventName,
775  ListModel *restrict const model,
776  const int width,
777  const std::string &restrict def,
778  const MainConfig mainConfig) :
779  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
781  mLabel(nullptr),
782  mModel(model),
784  mWidth(width)
785 {
786  mValueType = VSTR;
787  createControls();
788 }
789 
791 {
792  mHorizont = nullptr;
793  mWidget = nullptr;
794  mModel = nullptr;
795  mDropDown = nullptr;
796  mLabel = nullptr;
797 }
798 
800 {
801  load();
802  mHorizont = new HorizontContainer(this, 32, 2);
803 
804  mLabel = new Label(this, mText);
806  mDropDown = new DropDown(this,
807  mModel,
808  false,
809  Modal_false,
810  nullptr,
811  std::string());
816 
817  mWidget = mDropDown;
818  if (!mText.empty())
820  mHorizont->add(mLabel);
822 
823  mParent->getContainer()->add2(mHorizont, true, 4);
824  mParent->addControl(this);
825  mParent->addActionListener(this);
826  mWidget->addActionListener(this);
827 }
828 
830 {
831  const int sz = mModel->getNumberOfElements();
832  for (int f = 0; f < sz; f ++)
833  {
834  if (mModel->getElementAt(f) == mValue)
835  {
836  return f;
837  }
838  }
839  return 0;
840 }
841 
843 {
844  if (mDropDown == nullptr)
845  return;
846 
847  const int sel = mDropDown->getSelected();
848  // use first element in model as empty string
849  if (sel == 0 || sel >= mModel->getNumberOfElements())
850  mValue.clear();
851  else
852  mValue = mModel->getElementAt(sel);
853 }
854 
856 {
857  if (mDropDown == nullptr)
858  return;
859 
861 }
862 
863 
865  const std::string &restrict description,
866  const std::string &restrict keyName,
867  SetupTabScroll *restrict const parent,
868  const std::string &restrict eventName,
869  const double min,
870  const double max,
871  const double step,
872  const int width,
873  const OnTheFly onTheFly,
874  const MainConfig mainConfig) :
875  SetupItem(text, description, keyName, parent, eventName, mainConfig),
877  mLabel(nullptr),
878  mSlider(nullptr),
879  mMin(min),
880  mMax(max),
881  mStep(step),
882  mWidth(width),
883  mOnTheFly(onTheFly)
884 {
885  mValueType = VSTR;
886  createControls();
887 }
888 
890  const std::string &restrict description,
891  const std::string &restrict keyName,
892  SetupTabScroll *restrict const parent,
893  const std::string &restrict eventName,
894  const double min,
895  const double max,
896  const double step,
897  const std::string &restrict def,
898  const int width,
899  const OnTheFly onTheFly,
900  const MainConfig mainConfig) :
901  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
903  mLabel(nullptr),
904  mSlider(nullptr),
905  mMin(min),
906  mMax(max),
907  mStep(step),
908  mWidth(width),
909  mOnTheFly(onTheFly)
910 {
911  mValueType = VSTR;
912  createControls();
913 }
914 
916 {
917  mHorizont = nullptr;
918  mWidget = nullptr;
919  mSlider = nullptr;
920  mLabel = nullptr;
921 }
922 
924 {
925  load();
926  mHorizont = new HorizontContainer(this, 32, 2);
927 
928  mLabel = new Label(this, mText);
930  mSlider = new Slider(this, mMin, mMax, mStep);
933  mSlider->setValue(atof(mValue.c_str()));
934  mSlider->setHeight(30);
935 
936  mWidget = mSlider;
938  mSlider->setHeight(40);
940  mHorizont->add(mLabel);
941  mHorizont->add(mSlider, -10);
942 
943  mParent->getContainer()->add2(mHorizont, true, 4);
944  mParent->addControl(this);
945  mParent->addActionListener(this);
946  mWidget->addActionListener(this);
947 }
948 
950 {
951  if (mSlider == nullptr)
952  return;
953 
955 }
956 
958 {
959  if (mSlider == nullptr)
960  return;
961 
962  mSlider->setValue(atof(mValue.c_str()));
963 }
964 
966 {
967  fromWidget();
968  if (mOnTheFly == OnTheFly_true)
969  save();
970 }
971 
972 void SetupItemSlider::apply(const std::string &eventName)
973 {
974  if (eventName != mEventName)
975  return;
976 
977  fromWidget();
978  save();
979 }
980 
981 
983  const std::string &restrict description,
984  const std::string &restrict keyName,
985  SetupTabScroll *restrict const parent,
986  const std::string &restrict eventName,
987  const int min,
988  const int max,
989  const int step,
991  const OnTheFly onTheFly,
992  const MainConfig mainConfig,
993  const DoNotAlign doNotAlign) :
994  SetupItem(text, description, keyName, parent, eventName, mainConfig),
996  mLabel(nullptr),
997  mLabel2(nullptr),
998  mSlider(nullptr),
999  mValues(values),
1000  mMin(min),
1001  mMax(max),
1002  mStep(step),
1003  mInvertValue(0),
1004  mInvert(false),
1005  mOnTheFly(onTheFly),
1006  mDoNotAlign(doNotAlign)
1007 {
1008  mValueType = VSTR;
1009  createControls();
1010 }
1011 
1013  const std::string &restrict description,
1014  const std::string &restrict keyName,
1015  SetupTabScroll *restrict const parent,
1016  const std::string &restrict eventName,
1017  const int min,
1018  const int max,
1019  const int step,
1021  const std::string &restrict def,
1022  const OnTheFly onTheFly,
1023  const MainConfig mainConfig,
1024  const DoNotAlign doNotAlign) :
1025  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1026  mHorizont(nullptr),
1027  mLabel(nullptr),
1028  mLabel2(nullptr),
1029  mSlider(nullptr),
1030  mValues(values),
1031  mMin(min),
1032  mMax(max),
1033  mStep(step),
1034  mInvertValue(0),
1035  mInvert(false),
1036  mOnTheFly(onTheFly),
1037  mDoNotAlign(doNotAlign)
1038 {
1039  mValueType = VSTR;
1040  createControls();
1041 }
1042 
1044 {
1045  mHorizont = nullptr;
1046  mWidget = nullptr;
1047  mSlider = nullptr;
1048  mLabel = nullptr;
1049 }
1050 
1052 {
1053  load();
1054  mHorizont = new HorizontContainer(this, 32, 2);
1055 
1056  const int width = getMaxWidth();
1057 
1058  mLabel = new Label(this, mText);
1060  mLabel2 = new Label(this, "");
1061  mLabel2->setWidth(width);
1062  mSlider = new Slider(this, mMin, mMax, mStep);
1065  mSlider->setValue(atof(mValue.c_str()));
1066  mSlider->setHeight(30);
1067 
1068  mWidget = mSlider;
1069  mSlider->setWidth(150);
1070  mSlider->setHeight(40);
1073  mHorizont->add(mLabel);
1074  mHorizont->add(mSlider, -10);
1075  mHorizont->add(mLabel2);
1076 
1077  mParent->getContainer()->add2(mHorizont, true, 4);
1078  mParent->addControl(this);
1079  mParent->addActionListener(this);
1080  mWidget->addActionListener(this);
1081  updateLabel();
1082 }
1083 
1085 {
1086  if ((mValues == nullptr) || (gui == nullptr))
1087  return 1;
1088 
1089  int maxWidth = 0;
1090  SetupItemNamesConstIter it = mValues->begin();
1091  const SetupItemNamesConstIter it_end = mValues->end();
1092  const Font *const font = gui->getFont();
1093 
1094  while (it != it_end)
1095  {
1096  const int w = font->getWidth(*it);
1097  if (w > maxWidth)
1098  maxWidth = w;
1099 
1100  ++ it;
1101  }
1102  return maxWidth;
1103 }
1104 
1106 {
1107  if (mSlider == nullptr)
1108  return;
1109 
1110  int val = roundDouble(mSlider->getValue());
1111  if (mInvert)
1112  val = mInvertValue - val;
1113  mValue = toString(val);
1114 }
1115 
1117 {
1118  if (mSlider == nullptr)
1119  return;
1120 
1121  int val = roundDouble(atof(mValue.c_str()));
1122  if (mInvert)
1123  val = mInvertValue - val;
1124  mSlider->setValue(val);
1125  updateLabel();
1126 }
1127 
1129 {
1130  fromWidget();
1131  updateLabel();
1132  if (mOnTheFly == OnTheFly_true)
1133  save();
1134 }
1135 
1137 {
1138  int val = CAST_S32(mSlider->getValue()) - mMin;
1139  if (val < 0)
1140  {
1141  val = 0;
1142  }
1143  else
1144  {
1145  const int sz = CAST_S32(mValues->size());
1146  if (val >= sz)
1147  val = sz - 1;
1148  }
1149  std::string str = mValues->at(val);
1150  mLabel2->setCaption(str);
1151 }
1152 
1153 void SetupItemSlider2::apply(const std::string &eventName)
1154 {
1155  if (eventName != mEventName)
1156  return;
1157 
1158  fromWidget();
1159  save();
1160 }
1161 
1163 {
1164  mInvert = true;
1165  mInvertValue = v;
1166  toWidget();
1167 }
1168 
1169 
1171  const std::string &restrict
1172  description,
1173  const std::string &restrict keyName,
1174  SetupTabScroll *restrict const parent,
1175  const std::string &restrict eventName,
1176  ListModel *restrict const model,
1177  const int width,
1178  const OnTheFly onTheFly,
1179  const MainConfig mainConfig) :
1180  SetupItem(text, description, keyName, parent, eventName, mainConfig),
1181  mHorizont(nullptr),
1182  mLabel(nullptr),
1183  mSlider(nullptr),
1184  mModel(model),
1185  mWidth(width),
1186  mOnTheFly(onTheFly)
1187 {
1188  mValueType = VSTR;
1189 }
1190 
1192  const std::string &restrict
1193  description,
1194  const std::string &restrict keyName,
1195  SetupTabScroll *restrict const parent,
1196  const std::string &restrict eventName,
1197  ListModel *restrict const model,
1198  const std::string &restrict def,
1199  const int width,
1200  const OnTheFly onTheFly,
1201  const MainConfig mainConfig) :
1202  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1203  mHorizont(nullptr),
1204  mLabel(nullptr),
1205  mSlider(nullptr),
1206  mModel(model),
1207  mWidth(width),
1208  mOnTheFly(onTheFly)
1209 {
1210  mValueType = VSTR;
1211 }
1212 
1214 {
1215  mHorizont = nullptr;
1216  mWidget = nullptr;
1217  mSlider = nullptr;
1218  mLabel = nullptr;
1219 }
1220 
1222 {
1223  load();
1224  mHorizont = new HorizontContainer(this, 32, 2);
1225 
1226  mLabel = new Label(this, mText);
1228  mSlider = new SliderList(this, mModel);
1231  mSlider->adjustSize();
1232 
1233  mWidget = mSlider;
1235  mHorizont->add(mLabel, 5);
1236  mHorizont->add(mSlider);
1237 
1238  addMoreControls();
1239 
1240  mParent->getContainer()->add2(mHorizont, true, 4);
1241  mParent->addControl(this);
1242  mParent->addActionListener(this);
1243  mWidget->addActionListener(this);
1244 }
1245 
1247 {
1248  if (mSlider == nullptr)
1249  return;
1250 
1252 }
1253 
1255 {
1256  if (mSlider == nullptr)
1257  return;
1258 
1260 }
1261 
1263 {
1264  fromWidget();
1265  if (mOnTheFly == OnTheFly_true)
1266  save();
1267 }
1268 
1269 void SetupItemSliderList::apply(const std::string &eventName)
1270 {
1271  if (eventName != mEventName)
1272  return;
1273 
1274  fromWidget();
1275  save();
1276 }
1277 
1279  const std::string &restrict description,
1280  const std::string &restrict keyName,
1281  SetupTabScroll *restrict const parent,
1282  const std::string &restrict eventName,
1283  ListModel *restrict const model,
1284  const int width,
1285  const OnTheFly onTheFly,
1286  const MainConfig mainConfig) :
1287  SetupItemSliderList(text, description, keyName, parent, eventName,
1288  model, width, onTheFly, mainConfig),
1289  mButton(nullptr)
1290 {
1291  createControls();
1292 }
1293 
1295 {
1296  mButton = new Button(this, BUTTON_PLAY, 16, 16,
1297  mEventName + "_PLAY", this);
1298  if (mHorizont != nullptr)
1299  mHorizont->add(mButton);
1300 }
1301 
1303 {
1304  if (event.getId() == mEventName + "_PLAY")
1305  {
1306  if ((mSlider != nullptr) && (mSlider->getSelected() != 0))
1307  {
1309  "systemsounds"),
1310  mSlider->getSelectedString()).append(".ogg"));
1311  }
1312  }
1313  else
1314  {
1316  }
1317 }
1318 
1320  const std::string &restrict description,
1321  const std::string &restrict keyName,
1322  SetupTabScroll *restrict const parent,
1323  const std::string &restrict eventName,
1324  ListModel *restrict const model,
1325  const int min,
1326  const int width,
1327  const OnTheFly onTheFly,
1328  const MainConfig mainConfig) :
1329  SetupItemSliderList(text, description, keyName, parent, eventName,
1330  model, width, onTheFly, mainConfig),
1331  mMin(min)
1332 {
1333  createControls();
1334 }
1335 
1337 {
1338  toWidget();
1339 }
1340 
1342 {
1343  if (mSlider == nullptr)
1344  return;
1345 
1347 }
1348 
1350 {
1351  if (mSlider == nullptr)
1352  return;
1353 
1354  mSlider->setSelected(atoi(mValue.c_str()) - mMin);
1355 }
HorizontContainer * mHorizont
Definition: setupitem.h:388
Configuration branding
void load()
Definition: setupitem.cpp:112
void action(const ActionEvent &event)
Definition: setupitem.cpp:1302
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:864
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:1294
void setValue(const int value)
int getWidth() const
Definition: widget.h:220
void addControl(SetupItem *const widget)
void adjustSize()
Definition: sliderlist.cpp:217
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:636
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:200
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:1269
void action(const ActionEvent &event)
Definition: setupitem.cpp:551
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:203
Definition: button.h:94
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:447
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:972
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:1278
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:640
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
void add2(Widget *const widget, const bool resizable, const int spacing)
void setSelectedString(const std::string &str)
Definition: sliderlist.cpp:180
void setCaption(const std::string &caption)
Definition: label.cpp:261
virtual std::string getActionEventId() const
Definition: setupitem.cpp:154
void createControls()
Definition: setupitem.cpp:923
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:1128
void action(const ActionEvent &event)
Definition: setupitem.cpp:1262
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:1170
const std::string & getId() const
Definition: actionevent.h:121
void action(const ActionEvent &event)
Definition: setupitem.cpp:410
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:645
#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:1162
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:438
Label * mLabel
Definition: setupitem.h:307
void createControls()
Definition: setupitem.cpp:607
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:171
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:745
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:185
int getWidth(const std::string &text) const
Definition: font.cpp:333
void apply(const std::string &eventName)
Definition: setupitem.cpp:1153
SetupItemLabel(const std::string &text, const std::string &description, SetupTabScroll *const parent, const Separator separator)
Definition: setupitem.cpp:589
SliderList * mSlider
Definition: setupitem.h:558
Slider * mSlider
Definition: setupitem.h:504
#define restrict
Definition: localconsts.h:176
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:1319
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:195
Label * mLabel2
Definition: setupitem.h:503
void action(const ActionEvent &event)
Definition: setupitem.cpp:965
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:579
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:982
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:628
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