all repos — mgba @ 0980b67736c6f3235710840c9a9e7030b4fcc75d

mGBA Game Boy Advance Emulator

src/platform/qt/BattleChipView.cpp (view raw)

 1/* Copyright (c) 2013-2019 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "BattleChipView.h"
 7
 8#include "CoreController.h"
 9
10using namespace QGBA;
11
12BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, QWidget* parent)
13	: QDialog(parent)
14	, m_controller(controller)
15{
16	m_ui.setupUi(this);
17
18	connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.inserted, [this]() {
19		m_ui.inserted->setChecked(Qt::Checked);
20		insertChip(true);
21	});
22	connect(m_ui.inserted, &QAbstractButton::toggled, this, &BattleChipView::insertChip);
23	connect(controller.get(), &CoreController::stopping, this, &QWidget::close);
24}
25
26BattleChipView::~BattleChipView() {
27	m_controller->detachBattleChipGate();
28}
29
30void BattleChipView::insertChip(bool inserted) {
31	if (inserted) {
32		m_controller->setBattleChipId(m_ui.chipId->value());
33	} else {
34		m_controller->setBattleChipId(0);
35	}
36}