GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* The ManaPlus Client |
||
3 |
* Copyright (C) 2011-2019 The ManaPlus Developers |
||
4 |
* Copyright (C) 2019-2021 Andrei Karas |
||
5 |
* |
||
6 |
* This file is part of The ManaPlus Client. |
||
7 |
* |
||
8 |
* This program is free software; you can redistribute it and/or modify |
||
9 |
* it under the terms of the GNU General Public License as published by |
||
10 |
* the Free Software Foundation; either version 2 of the License, or |
||
11 |
* any later version. |
||
12 |
* |
||
13 |
* This program is distributed in the hope that it will be useful, |
||
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 |
* GNU General Public License for more details. |
||
17 |
* |
||
18 |
* You should have received a copy of the GNU General Public License |
||
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 |
*/ |
||
21 |
|||
22 |
#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" |
||
37 |
#include "gui/widgets/createwidget.h" |
||
38 |
#include "gui/widgets/dropdown.h" |
||
39 |
#include "gui/widgets/horizontcontainer.h" |
||
40 |
#include "gui/widgets/inttextfield.h" |
||
41 |
#include "gui/widgets/label.h" |
||
42 |
#include "gui/widgets/slider.h" |
||
43 |
#include "gui/widgets/sliderlist.h" |
||
44 |
#include "gui/widgets/vertcontainer.h" |
||
45 |
|||
46 |
#include "gui/widgets/tabs/setuptabscroll.h" |
||
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 |
406 |
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 |
406 |
const MainConfig mainConfig) : |
|
61 |
ActionListener(), |
||
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 |
4060 |
mUseDefault(false) |
|
75 |
{ |
||
76 |
406 |
} |
|
77 |
|||
78 |
80 |
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 |
80 |
const MainConfig mainConfig) : |
|
85 |
ActionListener(), |
||
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 |
800 |
mUseDefault(true) |
|
99 |
{ |
||
100 |
80 |
} |
|
101 |
|||
102 |
3888 |
SetupItem::~SetupItem() |
|
103 |
{ |
||
104 |
486 |
} |
|
105 |
|||
106 |
Configuration *SetupItem::getConfig() const |
||
107 |
{ |
||
108 |
✗✗✗✗ ✗✗✓✓ ✗✗ |
410 |
if (mMainConfig == MainConfig_true) |
109 |
return &config; |
||
110 |
return &serverConfig; |
||
111 |
} |
||
112 |
|||
113 |
410 |
void SetupItem::load() |
|
114 |
{ |
||
115 |
✓✗ | 820 |
if (mKeyName.empty()) |
116 |
return; |
||
117 |
|||
118 |
410 |
const Configuration *const cfg = getConfig(); |
|
119 |
✓✓ | 410 |
if (mUseDefault) |
120 |
{ |
||
121 |
12 |
mValue = cfg->getValue(mKeyName, mDefault); |
|
122 |
} |
||
123 |
else |
||
124 |
{ |
||
125 |
✓✓✗✗ |
404 |
switch (mValueType) |
126 |
{ |
||
127 |
case VBOOL: |
||
128 |
✓✓ | 268 |
if (cfg->getBoolValue(mKeyName)) |
129 |
156 |
mValue = "1"; |
|
130 |
else |
||
131 |
112 |
mValue = "0"; |
|
132 |
break; |
||
133 |
case VSTR: |
||
134 |
default: |
||
135 |
272 |
mValue = cfg->getStringValue(mKeyName); |
|
136 |
136 |
break; |
|
137 |
case VINT: |
||
138 |
mValue = toString(cfg->getIntValue(mKeyName)); |
||
139 |
break; |
||
140 |
case VNONE: |
||
141 |
break; |
||
142 |
} |
||
143 |
} |
||
144 |
} |
||
145 |
|||
146 |
void SetupItem::save() |
||
147 |
{ |
||
148 |
if (mKeyName.empty()) |
||
149 |
return; |
||
150 |
|||
151 |
Configuration *const cfg = getConfig(); |
||
152 |
cfg->setValue(mKeyName, mValue); |
||
153 |
} |
||
154 |
|||
155 |
486 |
std::string SetupItem::getActionEventId() const |
|
156 |
{ |
||
157 |
✗✓ | 486 |
if (mWidget == nullptr) |
158 |
return std::string(); |
||
159 |
|||
160 |
486 |
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 |
|||
172 |
void SetupItem::doAction() |
||
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 |
|||
198 |
26 |
void SetupItem::fixFirstItemSize(Widget *const widget) |
|
199 |
{ |
||
200 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
136 |
if (widget == nullptr) |
201 |
return; |
||
202 |
272 |
const int maxSize = mParent->getPreferredFirstItemSize(); |
|
203 |
✓✗✓✗ ✓✗✗✓ ✓✓✓✓ ✓✓✓✗ |
136 |
if (widget->getWidth() < maxSize) |
204 |
118 |
widget->setWidth(maxSize); |
|
205 |
} |
||
206 |
|||
207 |
void SetupItem::rereadValue() |
||
208 |
{ |
||
209 |
load(); |
||
210 |
toWidget(); |
||
211 |
} |
||
212 |
|||
213 |
268 |
SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text, |
|
214 |
const std::string &restrict description, |
||
215 |
const std::string &restrict keyName, |
||
216 |
SetupTabScroll *restrict const parent, |
||
217 |
const std::string &restrict eventName, |
||
218 |
268 |
const MainConfig mainConfig) : |
|
219 |
SetupItem(text, description, keyName, parent, eventName, mainConfig), |
||
220 |
268 |
mCheckBox(nullptr) |
|
221 |
{ |
||
222 |
✓✗ | 268 |
createControls(); |
223 |
268 |
} |
|
224 |
|||
225 |
6 |
SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text, |
|
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 |
6 |
const MainConfig mainConfig) : |
|
232 |
SetupItem(text, description, keyName, parent, eventName, def, mainConfig), |
||
233 |
6 |
mCheckBox(nullptr) |
|
234 |
{ |
||
235 |
✓✗ | 6 |
createControls(); |
236 |
6 |
} |
|
237 |
|||
238 |
548 |
SetupItemCheckBox::~SetupItemCheckBox() |
|
239 |
{ |
||
240 |
274 |
mWidget = nullptr; |
|
241 |
274 |
} |
|
242 |
|||
243 |
274 |
void SetupItemCheckBox::createControls() |
|
244 |
{ |
||
245 |
274 |
load(); |
|
246 |
✓✗✓✗ |
548 |
mCheckBox = new CheckBox(this, mText, mValue != "0", mParent, mEventName); |
247 |
548 |
mCheckBox->setToolTip(mDescription); |
|
248 |
274 |
mWidget = mCheckBox; |
|
249 |
548 |
mParent->getContainer()->add1(mWidget, -1); |
|
250 |
274 |
mParent->addControl(this); |
|
251 |
274 |
mParent->addActionListener(this); |
|
252 |
274 |
mWidget->addActionListener(this); |
|
253 |
274 |
} |
|
254 |
|||
255 |
void SetupItemCheckBox::fromWidget() |
||
256 |
{ |
||
257 |
if (mCheckBox == nullptr) |
||
258 |
return; |
||
259 |
|||
260 |
if (mCheckBox->isSelected()) |
||
261 |
mValue = "1"; |
||
262 |
else |
||
263 |
mValue = "0"; |
||
264 |
} |
||
265 |
|||
266 |
void SetupItemCheckBox::toWidget() |
||
267 |
{ |
||
268 |
if (mCheckBox == nullptr) |
||
269 |
return; |
||
270 |
|||
271 |
mCheckBox->setSelected(mValue != "0"); |
||
272 |
} |
||
273 |
|||
274 |
|||
275 |
16 |
SetupItemTextField::SetupItemTextField(const std::string &restrict text, |
|
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 |
16 |
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 |
16 |
mUseBase64(useBase64) |
|
289 |
{ |
||
290 |
16 |
mValueType = VSTR; |
|
291 |
✓✗ | 16 |
createControls(); |
292 |
16 |
} |
|
293 |
|||
294 |
SetupItemTextField::SetupItemTextField(const std::string &restrict text, |
||
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 |
|||
314 |
32 |
SetupItemTextField::~SetupItemTextField() |
|
315 |
{ |
||
316 |
16 |
mHorizont = nullptr; |
|
317 |
16 |
mWidget = nullptr; |
|
318 |
16 |
mTextField = nullptr; |
|
319 |
16 |
mLabel = nullptr; |
|
320 |
16 |
mButton = nullptr; |
|
321 |
16 |
} |
|
322 |
|||
323 |
void SetupItemTextField::save() |
||
324 |
{ |
||
325 |
if (mUseBase64 == UseBase64_true) |
||
326 |
{ |
||
327 |
std::string normalValue = mValue; |
||
328 |
mValue = encodeBase64String(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) |
||
342 |
mValue = decodeBase64String(mValue); |
||
343 |
toWidget(); |
||
344 |
} |
||
345 |
|||
346 |
void SetupItemTextField::externalUpdated(const std::string &eventName A_UNUSED) |
||
347 |
{ |
||
348 |
load(); |
||
349 |
if (mUseBase64 == UseBase64_true) |
||
350 |
mValue = decodeBase64String(mValue); |
||
351 |
toWidget(); |
||
352 |
} |
||
353 |
|||
354 |
void SetupItemTextField::rereadValue() |
||
355 |
{ |
||
356 |
load(); |
||
357 |
if (mUseBase64 == UseBase64_true) |
||
358 |
mValue = decodeBase64String(mValue); |
||
359 |
toWidget(); |
||
360 |
} |
||
361 |
|||
362 |
16 |
void SetupItemTextField::createControls() |
|
363 |
{ |
||
364 |
16 |
load(); |
|
365 |
✓✓ | 16 |
if (mUseBase64 == UseBase64_true) |
366 |
✓✗ | 8 |
mValue = decodeBase64String(mValue); |
367 |
✓✗ | 16 |
mHorizont = new HorizontContainer(this, 32, 2); |
368 |
|||
369 |
✓✗ | 16 |
mLabel = new Label(this, mText); |
370 |
32 |
mLabel->setToolTip(mDescription); |
|
371 |
16 |
mTextField = new TextField(this, |
|
372 |
mValue, |
||
373 |
LoseFocusOnTab_true, |
||
374 |
16 |
mParent, |
|
375 |
mEventName, |
||
376 |
✓✗✓✗ |
32 |
false); |
377 |
16 |
mButton = new Button(this, |
|
378 |
// TRANSLATORS: setup item button |
||
379 |
16 |
_("Edit"), |
|
380 |
✓✗ | 32 |
mEventName + "_EDIT", |
381 |
BUTTON_SKIN, |
||
382 |
✓✗✓✗ ✓✗ |
80 |
mParent); |
383 |
16 |
mWidget = mTextField; |
|
384 |
16 |
mTextField->setWidth(200); |
|
385 |
32 |
fixFirstItemSize(mLabel); |
|
386 |
16 |
mHorizont->add(mLabel); |
|
387 |
16 |
mHorizont->add(mTextField); |
|
388 |
16 |
mHorizont->add(mButton); |
|
389 |
|||
390 |
32 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
391 |
16 |
mParent->addControl(this); |
|
392 |
✓✗ | 32 |
mParent->addControl(this, mEventName + "_EDIT"); |
393 |
✓✗ | 32 |
mParent->addControl(this, mEventName + "_EDIT_OK"); |
394 |
16 |
mParent->addActionListener(this); |
|
395 |
16 |
mWidget->addActionListener(this); |
|
396 |
16 |
mButton->addActionListener(this); |
|
397 |
16 |
} |
|
398 |
|||
399 |
void SetupItemTextField::fromWidget() |
||
400 |
{ |
||
401 |
if (mTextField == nullptr) |
||
402 |
return; |
||
403 |
|||
404 |
mValue = mTextField->getText(); |
||
405 |
} |
||
406 |
|||
407 |
void SetupItemTextField::toWidget() |
||
408 |
{ |
||
409 |
if (mTextField == nullptr) |
||
410 |
return; |
||
411 |
|||
412 |
mTextField->setText(mValue); |
||
413 |
} |
||
414 |
|||
415 |
void SetupItemTextField::action(const ActionEvent &event) |
||
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 |
{ |
||
427 |
mEditDialog = CREATEWIDGETR(EditDialog, |
||
428 |
mText, |
||
429 |
mTextField->getText(), |
||
430 |
mEventName + "_EDIT_OK", |
||
431 |
300, |
||
432 |
nullptr, |
||
433 |
Modal_true); |
||
434 |
mEditDialog->addActionListener(this); |
||
435 |
} |
||
436 |
else if (eventId == mEventName + "_EDIT_OK") |
||
437 |
{ |
||
438 |
mTextField->setText(mEditDialog->getMsg()); |
||
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 |
|||
452 |
24 |
SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text, |
|
453 |
const std::string &restrict |
||
454 |
description, |
||
455 |
const std::string &restrict |
||
456 |
keyName, |
||
457 |
SetupTabScroll *restrict |
||
458 |
const parent, |
||
459 |
const std::string &restrict |
||
460 |
eventName, |
||
461 |
const int min, const int max, |
||
462 |
24 |
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 |
24 |
mMax(max) |
|
471 |
{ |
||
472 |
24 |
mValueType = VSTR; |
|
473 |
✓✗ | 24 |
createControls(); |
474 |
24 |
} |
|
475 |
|||
476 |
SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text, |
||
477 |
const std::string &restrict |
||
478 |
description, |
||
479 |
const std::string &restrict |
||
480 |
keyName, |
||
481 |
SetupTabScroll *restrict |
||
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 |
|||
501 |
48 |
SetupItemIntTextField::~SetupItemIntTextField() |
|
502 |
{ |
||
503 |
24 |
mHorizont = nullptr; |
|
504 |
24 |
mWidget = nullptr; |
|
505 |
24 |
mTextField = nullptr; |
|
506 |
24 |
mLabel = nullptr; |
|
507 |
24 |
mButton = nullptr; |
|
508 |
24 |
} |
|
509 |
|||
510 |
24 |
void SetupItemIntTextField::createControls() |
|
511 |
{ |
||
512 |
24 |
load(); |
|
513 |
✓✗ | 24 |
mHorizont = new HorizontContainer(this, 32, 2); |
514 |
|||
515 |
✓✗ | 24 |
mLabel = new Label(this, mText); |
516 |
48 |
mLabel->setToolTip(mDescription); |
|
517 |
96 |
mTextField = new IntTextField(this, atoi(mValue.c_str()), |
|
518 |
✓✗ | 24 |
mMin, mMax, Enable_true, 30); |
519 |
48 |
mTextField->setActionEventId(mEventName); |
|
520 |
✓✗ | 24 |
mTextField->addActionListener(mParent); |
521 |
|||
522 |
24 |
mButton = new Button(this, |
|
523 |
// TRANSLATORS: setup item button |
||
524 |
24 |
_("Edit"), |
|
525 |
✓✗ | 48 |
mEventName + "_EDIT", |
526 |
BUTTON_SKIN, |
||
527 |
✓✗✓✗ ✓✗ |
120 |
mParent); |
528 |
24 |
mWidget = mTextField; |
|
529 |
24 |
mTextField->setWidth(50); |
|
530 |
48 |
fixFirstItemSize(mLabel); |
|
531 |
24 |
mHorizont->add(mLabel); |
|
532 |
24 |
mHorizont->add(mTextField); |
|
533 |
24 |
mHorizont->add(mButton); |
|
534 |
|||
535 |
48 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
536 |
24 |
mParent->addControl(this); |
|
537 |
✓✗ | 48 |
mParent->addControl(this, mEventName + "_EDIT"); |
538 |
✓✗ | 48 |
mParent->addControl(this, mEventName + "_EDIT_OK"); |
539 |
24 |
mParent->addActionListener(this); |
|
540 |
24 |
mWidget->addActionListener(this); |
|
541 |
24 |
mButton->addActionListener(this); |
|
542 |
24 |
} |
|
543 |
|||
544 |
void SetupItemIntTextField::fromWidget() |
||
545 |
{ |
||
546 |
if (mTextField == nullptr) |
||
547 |
return; |
||
548 |
|||
549 |
mValue = mTextField->getText(); |
||
550 |
} |
||
551 |
|||
552 |
void SetupItemIntTextField::toWidget() |
||
553 |
{ |
||
554 |
if (mTextField == nullptr) |
||
555 |
return; |
||
556 |
|||
557 |
mTextField->setText(mValue); |
||
558 |
} |
||
559 |
|||
560 |
void SetupItemIntTextField::action(const ActionEvent &event) |
||
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 |
{ |
||
572 |
mEditDialog = CREATEWIDGETR(EditDialog, |
||
573 |
mText, |
||
574 |
mTextField->getText(), |
||
575 |
mEventName + "_EDIT_OK", |
||
576 |
300, |
||
577 |
nullptr, |
||
578 |
Modal_true); |
||
579 |
mEditDialog->addActionListener(this); |
||
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 |
74 |
SetupItemLabel::SetupItemLabel(const std::string &restrict text, |
|
599 |
const std::string &restrict description, |
||
600 |
SetupTabScroll *restrict const parent, |
||
601 |
74 |
const Separator separator) : |
|
602 |
SetupItem(text, description, "", parent, "", "", MainConfig_true), |
||
603 |
mLabel(nullptr), |
||
604 |
✓✗✓✗ ✓✗ |
740 |
mIsSeparator(separator) |
605 |
{ |
||
606 |
74 |
mValueType = VNONE; |
|
607 |
✓✗ | 74 |
createControls(); |
608 |
74 |
} |
|
609 |
|||
610 |
148 |
SetupItemLabel::~SetupItemLabel() |
|
611 |
{ |
||
612 |
74 |
mWidget = nullptr; |
|
613 |
74 |
mLabel = nullptr; |
|
614 |
74 |
} |
|
615 |
|||
616 |
74 |
void SetupItemLabel::createControls() |
|
617 |
{ |
||
618 |
✓✗ | 74 |
if (mIsSeparator == Separator_true) |
619 |
{ |
||
620 |
const std::string str(" \342\200\225\342\200\225\342\200\225" |
||
621 |
296 |
"\342\200\225\342\200\225 "); |
|
622 |
✓✗✓✗ |
370 |
mLabel = new Label(this, std::string(str).append(mText).append(str)); |
623 |
} |
||
624 |
else |
||
625 |
{ |
||
626 |
mLabel = new Label(this, mText); |
||
627 |
} |
||
628 |
148 |
mLabel->setToolTip(mDescription); |
|
629 |
|||
630 |
74 |
mWidget = mLabel; |
|
631 |
148 |
mParent->getContainer()->add1(mWidget, -1); |
|
632 |
74 |
mParent->addControl(this); |
|
633 |
74 |
mParent->addActionListener(this); |
|
634 |
74 |
mWidget->addActionListener(this); |
|
635 |
74 |
} |
|
636 |
|||
637 |
void SetupItemLabel::fromWidget() |
||
638 |
{ |
||
639 |
} |
||
640 |
|||
641 |
void SetupItemLabel::toWidget() |
||
642 |
{ |
||
643 |
} |
||
644 |
|||
645 |
void SetupItemLabel::action(const ActionEvent &event A_UNUSED) |
||
646 |
{ |
||
647 |
} |
||
648 |
|||
649 |
void SetupItemLabel::apply(const std::string &eventName A_UNUSED) |
||
650 |
{ |
||
651 |
} |
||
652 |
|||
653 |
|||
654 |
30 |
SetupItemDropDown::SetupItemDropDown(const std::string &restrict text, |
|
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 |
30 |
const MainConfig mainConfig) : |
|
662 |
SetupItem(text, description, keyName, parent, eventName, mainConfig), |
||
663 |
mHorizont(nullptr), |
||
664 |
mLabel(nullptr), |
||
665 |
mModel(model), |
||
666 |
mDropDown(nullptr), |
||
667 |
30 |
mWidth(width) |
|
668 |
{ |
||
669 |
30 |
mValueType = VSTR; |
|
670 |
✓✗ | 30 |
createControls(); |
671 |
30 |
} |
|
672 |
|||
673 |
SetupItemDropDown::SetupItemDropDown(const std::string &restrict text, |
||
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 |
|||
693 |
60 |
SetupItemDropDown::~SetupItemDropDown() |
|
694 |
{ |
||
695 |
30 |
mHorizont = nullptr; |
|
696 |
30 |
mWidget = nullptr; |
|
697 |
30 |
mModel = nullptr; |
|
698 |
30 |
mDropDown = nullptr; |
|
699 |
30 |
mLabel = nullptr; |
|
700 |
30 |
} |
|
701 |
|||
702 |
30 |
void SetupItemDropDown::createControls() |
|
703 |
{ |
||
704 |
30 |
load(); |
|
705 |
✓✗ | 30 |
mHorizont = new HorizontContainer(this, 32, 2); |
706 |
|||
707 |
✓✗ | 30 |
mLabel = new Label(this, mText); |
708 |
60 |
mLabel->setToolTip(mDescription); |
|
709 |
30 |
mDropDown = new DropDown(this, |
|
710 |
mModel, |
||
711 |
false, |
||
712 |
Modal_false, |
||
713 |
nullptr, |
||
714 |
✓✗✓✗ |
60 |
std::string()); |
715 |
60 |
mDropDown->setActionEventId(mEventName); |
|
716 |
✓✗ | 30 |
mDropDown->addActionListener(mParent); |
717 |
30 |
mDropDown->setWidth(mWidth); |
|
718 |
30 |
mDropDown->setSelected(selectionByValue()); |
|
719 |
|||
720 |
✓✗ | 30 |
mWidget = mDropDown; |
721 |
✓✗ | 60 |
if (!mText.empty()) |
722 |
30 |
fixFirstItemSize(mLabel); |
|
723 |
30 |
mHorizont->add(mLabel); |
|
724 |
✓✗ | 30 |
mHorizont->add(mDropDown); |
725 |
|||
726 |
60 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
727 |
30 |
mParent->addControl(this); |
|
728 |
30 |
mParent->addActionListener(this); |
|
729 |
30 |
mWidget->addActionListener(this); |
|
730 |
30 |
} |
|
731 |
|||
732 |
int SetupItemDropDown::selectionByValue() |
||
733 |
{ |
||
734 |
90 |
return atoi(mValue.c_str()); |
|
735 |
} |
||
736 |
|||
737 |
void SetupItemDropDown::fromWidget() |
||
738 |
{ |
||
739 |
if (mDropDown == nullptr) |
||
740 |
return; |
||
741 |
|||
742 |
mValue = toString(mDropDown->getSelected()); |
||
743 |
} |
||
744 |
|||
745 |
void SetupItemDropDown::toWidget() |
||
746 |
{ |
||
747 |
if (mDropDown == nullptr) |
||
748 |
return; |
||
749 |
|||
750 |
mDropDown->setSelected(selectionByValue()); |
||
751 |
} |
||
752 |
|||
753 |
|||
754 |
2 |
SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text, |
|
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 |
2 |
const MainConfig mainConfig) : |
|
765 |
SetupItem(text, description, keyName, parent, eventName, mainConfig), |
||
766 |
mHorizont(nullptr), |
||
767 |
mLabel(nullptr), |
||
768 |
mModel(model), |
||
769 |
mDropDown(nullptr), |
||
770 |
2 |
mWidth(width) |
|
771 |
{ |
||
772 |
2 |
mValueType = VSTR; |
|
773 |
✓✗ | 2 |
createControls(); |
774 |
2 |
} |
|
775 |
|||
776 |
SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text, |
||
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 |
|||
799 |
4 |
SetupItemDropDownStr::~SetupItemDropDownStr() |
|
800 |
{ |
||
801 |
2 |
mHorizont = nullptr; |
|
802 |
2 |
mWidget = nullptr; |
|
803 |
2 |
mModel = nullptr; |
|
804 |
2 |
mDropDown = nullptr; |
|
805 |
2 |
mLabel = nullptr; |
|
806 |
2 |
} |
|
807 |
|||
808 |
2 |
void SetupItemDropDownStr::createControls() |
|
809 |
{ |
||
810 |
2 |
load(); |
|
811 |
✓✗ | 2 |
mHorizont = new HorizontContainer(this, 32, 2); |
812 |
|||
813 |
✓✗ | 2 |
mLabel = new Label(this, mText); |
814 |
4 |
mLabel->setToolTip(mDescription); |
|
815 |
2 |
mDropDown = new DropDown(this, |
|
816 |
mModel, |
||
817 |
false, |
||
818 |
Modal_false, |
||
819 |
nullptr, |
||
820 |
✓✗✓✗ |
4 |
std::string()); |
821 |
4 |
mDropDown->setActionEventId(mEventName); |
|
822 |
✓✗ | 2 |
mDropDown->addActionListener(mParent); |
823 |
2 |
mDropDown->setWidth(mWidth); |
|
824 |
2 |
mDropDown->setSelected(selectionByValue()); |
|
825 |
|||
826 |
✓✗ | 2 |
mWidget = mDropDown; |
827 |
✓✗ | 4 |
if (!mText.empty()) |
828 |
2 |
fixFirstItemSize(mLabel); |
|
829 |
2 |
mHorizont->add(mLabel); |
|
830 |
✓✗ | 2 |
mHorizont->add(mDropDown); |
831 |
|||
832 |
4 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
833 |
2 |
mParent->addControl(this); |
|
834 |
2 |
mParent->addActionListener(this); |
|
835 |
2 |
mWidget->addActionListener(this); |
|
836 |
2 |
} |
|
837 |
|||
838 |
2 |
int SetupItemDropDownStr::selectionByValue() |
|
839 |
{ |
||
840 |
2 |
const int sz = mModel->getNumberOfElements(); |
|
841 |
✓✓ | 10 |
for (int f = 0; f < sz; f ++) |
842 |
{ |
||
843 |
✓✗ | 16 |
if (mModel->getElementAt(f) == mValue) |
844 |
{ |
||
845 |
return f; |
||
846 |
} |
||
847 |
} |
||
848 |
return 0; |
||
849 |
} |
||
850 |
|||
851 |
void SetupItemDropDownStr::fromWidget() |
||
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 |
|||
864 |
void SetupItemDropDownStr::toWidget() |
||
865 |
{ |
||
866 |
if (mDropDown == nullptr) |
||
867 |
return; |
||
868 |
|||
869 |
mDropDown->setSelected(selectionByValue()); |
||
870 |
} |
||
871 |
|||
872 |
|||
873 |
8 |
SetupItemSlider::SetupItemSlider(const std::string &restrict text, |
|
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 |
8 |
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 |
8 |
mOnTheFly(onTheFly) |
|
893 |
{ |
||
894 |
8 |
mValueType = VSTR; |
|
895 |
✓✗ | 8 |
createControls(); |
896 |
8 |
} |
|
897 |
|||
898 |
SetupItemSlider::SetupItemSlider(const std::string &restrict text, |
||
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 |
|||
924 |
16 |
SetupItemSlider::~SetupItemSlider() |
|
925 |
{ |
||
926 |
8 |
mHorizont = nullptr; |
|
927 |
8 |
mWidget = nullptr; |
|
928 |
8 |
mSlider = nullptr; |
|
929 |
8 |
mLabel = nullptr; |
|
930 |
8 |
} |
|
931 |
|||
932 |
8 |
void SetupItemSlider::createControls() |
|
933 |
{ |
||
934 |
8 |
load(); |
|
935 |
✓✗ | 8 |
mHorizont = new HorizontContainer(this, 32, 2); |
936 |
|||
937 |
✓✗ | 8 |
mLabel = new Label(this, mText); |
938 |
16 |
mLabel->setToolTip(mDescription); |
|
939 |
✓✗ | 8 |
mSlider = new Slider(this, mMin, mMax, mStep); |
940 |
16 |
mSlider->setActionEventId(mEventName); |
|
941 |
✓✗ | 8 |
mSlider->addActionListener(mParent); |
942 |
24 |
mSlider->setValue(atof(mValue.c_str())); |
|
943 |
8 |
mSlider->setHeight(30); |
|
944 |
|||
945 |
8 |
mWidget = mSlider; |
|
946 |
8 |
mSlider->setWidth(mWidth); |
|
947 |
8 |
mSlider->setHeight(40); |
|
948 |
16 |
fixFirstItemSize(mLabel); |
|
949 |
8 |
mHorizont->add(mLabel); |
|
950 |
8 |
mHorizont->add(mSlider, -10); |
|
951 |
|||
952 |
16 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
953 |
8 |
mParent->addControl(this); |
|
954 |
8 |
mParent->addActionListener(this); |
|
955 |
8 |
mWidget->addActionListener(this); |
|
956 |
8 |
} |
|
957 |
|||
958 |
void SetupItemSlider::fromWidget() |
||
959 |
{ |
||
960 |
if (mSlider == nullptr) |
||
961 |
return; |
||
962 |
|||
963 |
mValue = toString(mSlider->getValue()); |
||
964 |
} |
||
965 |
|||
966 |
void SetupItemSlider::toWidget() |
||
967 |
{ |
||
968 |
if (mSlider == nullptr) |
||
969 |
return; |
||
970 |
|||
971 |
mSlider->setValue(atof(mValue.c_str())); |
||
972 |
} |
||
973 |
|||
974 |
void SetupItemSlider::action(const ActionEvent &event A_UNUSED) |
||
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 |
|||
991 |
4 |
SetupItemSlider2::SetupItemSlider2(const std::string &restrict text, |
|
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, |
||
999 |
SetupItemNames *restrict const values, |
||
1000 |
const OnTheFly onTheFly, |
||
1001 |
const MainConfig mainConfig, |
||
1002 |
4 |
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 |
4 |
mDoNotAlign(doNotAlign) |
|
1016 |
{ |
||
1017 |
4 |
mValueType = VSTR; |
|
1018 |
✓✗ | 4 |
createControls(); |
1019 |
4 |
} |
|
1020 |
|||
1021 |
SetupItemSlider2::SetupItemSlider2(const std::string &restrict text, |
||
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, |
||
1029 |
SetupItemNames *restrict const values, |
||
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 |
|||
1052 |
8 |
SetupItemSlider2::~SetupItemSlider2() |
|
1053 |
{ |
||
1054 |
4 |
mHorizont = nullptr; |
|
1055 |
4 |
mWidget = nullptr; |
|
1056 |
4 |
mSlider = nullptr; |
|
1057 |
4 |
mLabel = nullptr; |
|
1058 |
4 |
} |
|
1059 |
|||
1060 |
4 |
void SetupItemSlider2::createControls() |
|
1061 |
{ |
||
1062 |
4 |
load(); |
|
1063 |
✓✗ | 4 |
mHorizont = new HorizontContainer(this, 32, 2); |
1064 |
|||
1065 |
4 |
const int width = getMaxWidth(); |
|
1066 |
|||
1067 |
✓✗ | 4 |
mLabel = new Label(this, mText); |
1068 |
8 |
mLabel->setToolTip(mDescription); |
|
1069 |
✓✗✓✗ |
16 |
mLabel2 = new Label(this, ""); |
1070 |
4 |
mLabel2->setWidth(width); |
|
1071 |
✓✗ | 4 |
mSlider = new Slider(this, mMin, mMax, mStep); |
1072 |
8 |
mSlider->setActionEventId(mEventName); |
|
1073 |
✓✗ | 4 |
mSlider->addActionListener(mParent); |
1074 |
12 |
mSlider->setValue(atof(mValue.c_str())); |
|
1075 |
4 |
mSlider->setHeight(30); |
|
1076 |
|||
1077 |
4 |
mWidget = mSlider; |
|
1078 |
4 |
mSlider->setWidth(150); |
|
1079 |
4 |
mSlider->setHeight(40); |
|
1080 |
✓✗ | 4 |
if (mDoNotAlign == DoNotAlign_false) |
1081 |
4 |
fixFirstItemSize(mLabel); |
|
1082 |
4 |
mHorizont->add(mLabel); |
|
1083 |
4 |
mHorizont->add(mSlider, -10); |
|
1084 |
4 |
mHorizont->add(mLabel2); |
|
1085 |
|||
1086 |
8 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
1087 |
4 |
mParent->addControl(this); |
|
1088 |
4 |
mParent->addActionListener(this); |
|
1089 |
4 |
mWidget->addActionListener(this); |
|
1090 |
4 |
updateLabel(); |
|
1091 |
4 |
} |
|
1092 |
|||
1093 |
4 |
int SetupItemSlider2::getMaxWidth() |
|
1094 |
{ |
||
1095 |
✓✗✓✗ |
4 |
if ((mValues == nullptr) || (gui == nullptr)) |
1096 |
return 1; |
||
1097 |
|||
1098 |
4 |
int maxWidth = 0; |
|
1099 |
12 |
SetupItemNamesConstIter it = mValues->begin(); |
|
1100 |
12 |
const SetupItemNamesConstIter it_end = mValues->end(); |
|
1101 |
8 |
const Font *const font = gui->getFont(); |
|
1102 |
|||
1103 |
✓✓ | 20 |
while (it != it_end) |
1104 |
{ |
||
1105 |
16 |
const int w = font->getWidth(*it); |
|
1106 |
✓✓ | 16 |
if (w > maxWidth) |
1107 |
12 |
maxWidth = w; |
|
1108 |
|||
1109 |
++ it; |
||
1110 |
} |
||
1111 |
return maxWidth; |
||
1112 |
} |
||
1113 |
|||
1114 |
void SetupItemSlider2::fromWidget() |
||
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 |
|||
1125 |
2 |
void SetupItemSlider2::toWidget() |
|
1126 |
{ |
||
1127 |
✓✗ | 2 |
if (mSlider == nullptr) |
1128 |
return; |
||
1129 |
|||
1130 |
8 |
int val = roundDouble(atof(mValue.c_str())); |
|
1131 |
✓✗ | 2 |
if (mInvert) |
1132 |
2 |
val = mInvertValue - val; |
|
1133 |
2 |
mSlider->setValue(val); |
|
1134 |
2 |
updateLabel(); |
|
1135 |
} |
||
1136 |
|||
1137 |
void SetupItemSlider2::action(const ActionEvent &event A_UNUSED) |
||
1138 |
{ |
||
1139 |
fromWidget(); |
||
1140 |
updateLabel(); |
||
1141 |
if (mOnTheFly == OnTheFly_true) |
||
1142 |
save(); |
||
1143 |
} |
||
1144 |
|||
1145 |
6 |
void SetupItemSlider2::updateLabel() |
|
1146 |
{ |
||
1147 |
6 |
int val = CAST_S32(mSlider->getValue()) - mMin; |
|
1148 |
✓✗ | 6 |
if (val < 0) |
1149 |
{ |
||
1150 |
val = 0; |
||
1151 |
} |
||
1152 |
else |
||
1153 |
{ |
||
1154 |
12 |
const int sz = CAST_S32(mValues->size()); |
|
1155 |
✗✓ | 6 |
if (val >= sz) |
1156 |
val = sz - 1; |
||
1157 |
} |
||
1158 |
24 |
std::string str = mValues->at(val); |
|
1159 |
✓✗ | 6 |
mLabel2->setCaption(str); |
1160 |
6 |
} |
|
1161 |
|||
1162 |
void SetupItemSlider2::apply(const std::string &eventName) |
||
1163 |
{ |
||
1164 |
if (eventName != mEventName) |
||
1165 |
return; |
||
1166 |
|||
1167 |
fromWidget(); |
||
1168 |
save(); |
||
1169 |
} |
||
1170 |
|||
1171 |
2 |
void SetupItemSlider2::setInvertValue(const int v) |
|
1172 |
{ |
||
1173 |
2 |
mInvert = true; |
|
1174 |
2 |
mInvertValue = v; |
|
1175 |
2 |
toWidget(); |
|
1176 |
2 |
} |
|
1177 |
|||
1178 |
|||
1179 |
SetupItemSliderList::SetupItemSliderList(const std::string &restrict text, |
||
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 |
26 |
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 |
26 |
mOnTheFly(onTheFly) |
|
1196 |
{ |
||
1197 |
26 |
mValueType = VSTR; |
|
1198 |
} |
||
1199 |
|||
1200 |
SetupItemSliderList::SetupItemSliderList(const std::string &restrict text, |
||
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 |
|||
1222 |
52 |
SetupItemSliderList::~SetupItemSliderList() |
|
1223 |
{ |
||
1224 |
26 |
mHorizont = nullptr; |
|
1225 |
26 |
mWidget = nullptr; |
|
1226 |
26 |
mSlider = nullptr; |
|
1227 |
26 |
mLabel = nullptr; |
|
1228 |
} |
||
1229 |
|||
1230 |
26 |
void SetupItemSliderList::createControls() |
|
1231 |
{ |
||
1232 |
26 |
load(); |
|
1233 |
✓✗ | 26 |
mHorizont = new HorizontContainer(this, 32, 2); |
1234 |
|||
1235 |
✓✗ | 26 |
mLabel = new Label(this, mText); |
1236 |
52 |
mLabel->setToolTip(mDescription); |
|
1237 |
✓✗ | 26 |
mSlider = new SliderList(this, mModel); |
1238 |
✓✗ | 26 |
mSlider->postInit2(mParent, mEventName); |
1239 |
26 |
mSlider->setSelectedString(mValue); |
|
1240 |
26 |
mSlider->adjustSize(); |
|
1241 |
|||
1242 |
26 |
mWidget = mSlider; |
|
1243 |
52 |
fixFirstItemSize(mLabel); |
|
1244 |
26 |
mHorizont->add(mLabel, 5); |
|
1245 |
26 |
mHorizont->add(mSlider); |
|
1246 |
|||
1247 |
26 |
addMoreControls(); |
|
1248 |
|||
1249 |
52 |
mParent->getContainer()->add2(mHorizont, true, 4); |
|
1250 |
26 |
mParent->addControl(this); |
|
1251 |
26 |
mParent->addActionListener(this); |
|
1252 |
26 |
mWidget->addActionListener(this); |
|
1253 |
26 |
} |
|
1254 |
|||
1255 |
void SetupItemSliderList::fromWidget() |
||
1256 |
{ |
||
1257 |
if (mSlider == nullptr) |
||
1258 |
return; |
||
1259 |
|||
1260 |
mValue = mSlider->getSelectedString(); |
||
1261 |
} |
||
1262 |
|||
1263 |
void SetupItemSliderList::toWidget() |
||
1264 |
{ |
||
1265 |
if (mSlider == nullptr) |
||
1266 |
return; |
||
1267 |
|||
1268 |
mSlider->setSelectedString(mValue); |
||
1269 |
} |
||
1270 |
|||
1271 |
void SetupItemSliderList::action(const ActionEvent &event A_UNUSED) |
||
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 |
|||
1287 |
24 |
SetupItemSound::SetupItemSound(const std::string &restrict text, |
|
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 |
24 |
const MainConfig mainConfig) : |
|
1296 |
SetupItemSliderList(text, description, keyName, parent, eventName, |
||
1297 |
model, width, onTheFly, mainConfig), |
||
1298 |
48 |
mButton(nullptr) |
|
1299 |
{ |
||
1300 |
✓✗ | 24 |
createControls(); |
1301 |
24 |
} |
|
1302 |
|||
1303 |
24 |
void SetupItemSound::addMoreControls() |
|
1304 |
{ |
||
1305 |
24 |
mButton = new Button(this, |
|
1306 |
BUTTON_PLAY, |
||
1307 |
16, 16, |
||
1308 |
48 |
mEventName + "_PLAY", |
|
1309 |
BUTTON_SKIN, |
||
1310 |
✓✗✓✗ |
24 |
this); |
1311 |
✓✗ | 24 |
if (mHorizont != nullptr) |
1312 |
24 |
mHorizont->add(mButton); |
|
1313 |
24 |
} |
|
1314 |
|||
1315 |
void SetupItemSound::action(const ActionEvent &event) |
||
1316 |
{ |
||
1317 |
if (event.getId() == mEventName + "_PLAY") |
||
1318 |
{ |
||
1319 |
if ((mSlider != nullptr) && (mSlider->getSelected() != 0)) |
||
1320 |
{ |
||
1321 |
soundManager.playGuiSfx(pathJoin(branding.getStringValue( |
||
1322 |
"systemsounds"), |
||
1323 |
mSlider->getSelectedString()).append(".ogg")); |
||
1324 |
} |
||
1325 |
} |
||
1326 |
else |
||
1327 |
{ |
||
1328 |
SetupItemSliderList::action(event); |
||
1329 |
} |
||
1330 |
} |
||
1331 |
|||
1332 |
2 |
SetupItemSliderInt::SetupItemSliderInt(const std::string &restrict text, |
|
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 |
2 |
const MainConfig mainConfig) : |
|
1342 |
SetupItemSliderList(text, description, keyName, parent, eventName, |
||
1343 |
model, width, onTheFly, mainConfig), |
||
1344 |
4 |
mMin(min) |
|
1345 |
{ |
||
1346 |
✓✗ | 2 |
createControls(); |
1347 |
2 |
} |
|
1348 |
|||
1349 |
2 |
void SetupItemSliderInt::addMoreControls() |
|
1350 |
{ |
||
1351 |
2 |
toWidget(); |
|
1352 |
2 |
} |
|
1353 |
|||
1354 |
void SetupItemSliderInt::fromWidget() |
||
1355 |
{ |
||
1356 |
if (mSlider == nullptr) |
||
1357 |
return; |
||
1358 |
|||
1359 |
mValue = toString(mSlider->getSelected() + mMin); |
||
1360 |
} |
||
1361 |
|||
1362 |
2 |
void SetupItemSliderInt::toWidget() |
|
1363 |
{ |
||
1364 |
✓✗ | 2 |
if (mSlider == nullptr) |
1365 |
return; |
||
1366 |
|||
1367 |
6 |
mSlider->setSelected(atoi(mValue.c_str()) - mMin); |
|
1368 |
✓✗✓✗ |
3 |
} |
Generated by: GCOVR (Version 3.3) |