summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/TAS/TASSpinBox.cpp
blob: 33e3541d417b158f81ce31b95d46cc5b62fd4866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "DolphinQt/TAS/TASSpinBox.h"

#include "DolphinQt/QtUtils/QueueOnObject.h"

TASSpinBox::TASSpinBox(QWidget* parent) : QSpinBox(parent)
{
  connect(this, &TASSpinBox::valueChanged, this, &TASSpinBox::OnUIValueChanged);
}

int TASSpinBox::GetValue() const
{
  return m_state.GetValue();
}

void TASSpinBox::OnControllerValueChanged(int new_value)
{
  if (m_state.OnControllerValueChanged(new_value))
    QueueOnObject(this, &TASSpinBox::ApplyControllerValueChange);
}

void TASSpinBox::OnUIValueChanged(int new_value)
{
  m_state.OnUIValueChanged(new_value);
}

void TASSpinBox::ApplyControllerValueChange()
{
  setValue(m_state.ApplyControllerValueChange());
}

QValidator::State TASSpinBox::validate(QString& input, int& pos) const
{
  auto state = QSpinBox::validate(input, pos);
  if (state == QValidator::Invalid)
  {
    bool ok;
    input.toInt(&ok);
    if (ok)
      return QValidator::Intermediate;
  }
  return state;
}

void TASSpinBox::fixup(QString& input) const
{
  bool ok;
  int val = input.toInt(&ok);
  if (ok)
  {
    if (val > maximum())
      input = QString::number(maximum());
    else if (val < minimum())
      input = QString::number(minimum());
    return;
  }
  QSpinBox::fixup(input);
}