Debian Codegraph @

Source/Core/DolphinQt/TAS/TASSpinBox.cpp

raw symbols SCIP
1 // Copyright 2019 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/TAS/TASSpinBox.h"
5
6 #include "DolphinQt/QtUtils/QueueOnObject.h"
7
8 TASSpinBox::TASSpinBox(QWidget* parent) : QSpinBox(parent)
9 {
10 connect(this, &TASSpinBox::valueChanged, this, &TASSpinBox::OnUIValueChanged);
11 }
12
13 int TASSpinBox::GetValue() const
14 {
15 return m_state.GetValue();
16 }
17
18 void TASSpinBox::OnControllerValueChanged(int new_value)
19 {
20 if (m_state.OnControllerValueChanged(new_value))
21 QueueOnObject(this, &TASSpinBox::ApplyControllerValueChange);
22 }
23
24 void TASSpinBox::OnUIValueChanged(int new_value)
25 {
26 m_state.OnUIValueChanged(new_value);
27 }
28
29 void TASSpinBox::ApplyControllerValueChange()
30 {
31 setValue(m_state.ApplyControllerValueChange());
32 }
33
34 QValidator::State TASSpinBox::validate(QString& input, int& pos) const
35 {
36 auto state = QSpinBox::validate(input, pos);
37 if (state == QValidator::Invalid)
38 {
39 bool ok;
40 input.toInt(&ok);
41 if (ok)
42 return QValidator::Intermediate;
43 }
44 return state;
45 }
46
47 void TASSpinBox::fixup(QString& input) const
48 {
49 bool ok;
50 int val = input.toInt(&ok);
51 if (ok)
52 {
53 if (val > maximum())
54 input = QString::number(maximum());
55 else if (val < minimum())
56 input = QString::number(minimum());
57 return;
58 }
59 QSpinBox::fixup(input);
60 }