Debian Codegraph @

Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/Config/Mapping/MappingNumeric.h"
5
6 #include <limits>
7
8 #include "DolphinQt/Config/Mapping/MappingWidget.h"
9
10 MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
11 : QDoubleSpinBox(parent), m_setting(*setting)
12 {
13 setDecimals(2);
14
15 if (const auto ui_description = m_setting.GetUIDescription())
16 setToolTip(tr(ui_description));
17
18 connect(this, &QDoubleSpinBox::valueChanged, this, [this, parent](double value) {
19 m_setting.SetValue(value);
20 ConfigChanged();
21 parent->SaveSettings();
22 });
23
24 connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
25 connect(parent, &MappingWidget::Update, this, &MappingDouble::Update);
26 }
27
28 // Overriding QDoubleSpinBox's fixup to set the default value when input is cleared.
29 void MappingDouble::fixup(QString& input) const
30 {
31 input = QString::number(m_setting.GetDefaultValue());
32 }
33
34 void MappingDouble::ConfigChanged()
35 {
36 const QSignalBlocker blocker(this);
37
38 QString suffix;
39
40 if (const auto ui_suffix = m_setting.GetUISuffix())
41 suffix += QLatin1Char{' '} + tr(ui_suffix);
42
43 if (m_setting.IsSimpleValue())
44 {
45 setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
46 setButtonSymbols(ButtonSymbols::UpDownArrows);
47 }
48 else
49 {
50 constexpr auto inf = std::numeric_limits<double>::infinity();
51 setRange(-inf, inf);
52 setButtonSymbols(ButtonSymbols::NoButtons);
53 suffix += QString::fromUtf8(" 🎮");
54 }
55
56 setSuffix(suffix);
57
58 setValue(m_setting.GetValue());
59 }
60
61 void MappingDouble::Update()
62 {
63 if (m_setting.IsSimpleValue() || hasFocus())
64 return;
65
66 const QSignalBlocker blocker(this);
67 setValue(m_setting.GetValue());
68 }
69
70 MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bool>* setting)
71 : QCheckBox(parent), m_setting(*setting)
72 {
73 if (const auto ui_description = m_setting.GetUIDescription())
74 setToolTip(tr(ui_description));
75
76 #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
77 connect(this, &QCheckBox::checkStateChanged, this, [this, parent](Qt::CheckState value) {
78 #else
79 connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
80 #endif
81 m_setting.SetValue(value != 0);
82 ConfigChanged();
83 parent->SaveSettings();
84 });
85
86 connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
87 connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
88
89 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
90 }
91
92 void MappingBool::ConfigChanged()
93 {
94 const QSignalBlocker blocker(this);
95
96 if (m_setting.IsSimpleValue())
97 setText({});
98 else
99 setText(QString::fromUtf8("🎮"));
100
101 setChecked(m_setting.GetValue());
102 }
103
104 void MappingBool::Update()
105 {
106 if (m_setting.IsSimpleValue())
107 return;
108
109 const QSignalBlocker blocker(this);
110 setChecked(m_setting.GetValue());
111 }