dolphin/Source/Core/DolphinQt/TAS/TASCheckBox.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.8 KiB
C++
Raw Normal View History

2019-03-31 04:49:57 +02:00
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2019-03-31 04:49:57 +02:00
#include "DolphinQt/TAS/TASCheckBox.h"
#include <QMouseEvent>
#include "Core/Movie.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/TAS/TASInputWindow.h"
2019-03-31 04:49:57 +02:00
TASCheckBox::TASCheckBox(const QString& text, TASInputWindow* parent)
: QCheckBox(text, parent), m_parent(parent)
2019-03-31 04:49:57 +02:00
{
setTristate(true);
connect(this, &TASCheckBox::stateChanged, this, &TASCheckBox::OnUIValueChanged);
2019-03-31 04:49:57 +02:00
}
bool TASCheckBox::GetValue() const
2019-03-31 04:49:57 +02:00
{
Qt::CheckState check_state = static_cast<Qt::CheckState>(m_state.GetValue());
if (check_state == Qt::PartiallyChecked)
{
const u64 frames_elapsed = Movie::GetCurrentFrame() - m_frame_turbo_started;
2020-11-21 01:05:01 +01:00
return static_cast<int>(frames_elapsed % m_turbo_total_frames) < m_turbo_press_frames;
}
2019-03-31 04:49:57 +02:00
return check_state != Qt::Unchecked;
}
void TASCheckBox::OnControllerValueChanged(bool new_value)
{
if (m_state.OnControllerValueChanged(new_value ? Qt::Checked : Qt::Unchecked))
QueueOnObject(this, &TASCheckBox::ApplyControllerValueChange);
2019-03-31 04:49:57 +02:00
}
void TASCheckBox::mousePressEvent(QMouseEvent* event)
{
if (event->button() != Qt::RightButton)
{
setChecked(!isChecked());
return;
}
if (checkState() == Qt::PartiallyChecked)
{
setCheckState(Qt::Unchecked);
return;
}
m_frame_turbo_started = Movie::GetCurrentFrame();
m_turbo_press_frames = m_parent->GetTurboPressFrames();
m_turbo_total_frames = m_turbo_press_frames + m_parent->GetTurboReleaseFrames();
2019-03-31 04:49:57 +02:00
setCheckState(Qt::PartiallyChecked);
}
void TASCheckBox::OnUIValueChanged(int new_value)
{
m_state.OnUIValueChanged(new_value);
}
void TASCheckBox::ApplyControllerValueChange()
{
const QSignalBlocker blocker(this);
setCheckState(static_cast<Qt::CheckState>(m_state.ApplyControllerValueChange()));
}