all repos — mgba @ 2c5d11539a2f7cd8672fc6272a63363cd36c9016

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2015 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 "SensorView.h"
 7
 8#include "GameController.h"
 9
10using namespace QGBA;
11
12SensorView::SensorView(GameController* controller, QWidget* parent)
13	: QWidget(parent)
14	, m_controller(controller)
15 {
16	m_ui.setupUi(this);
17
18	connect(m_ui.lightSpin, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
19	connect(m_ui.lightSlide, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
20
21	connect(m_ui.timeNoOverride, SIGNAL(clicked()), controller, SLOT(setRealTime()));
22	connect(m_ui.timeFixed, &QRadioButton::clicked, [controller, this] () {
23		controller->setFixedTime(m_ui.time->dateTime());
24	});
25	connect(m_ui.timeFakeEpoch, &QRadioButton::clicked, [controller, this] () {
26		controller->setFakeEpoch(m_ui.time->dateTime());
27	});
28	connect(m_ui.time, &QDateTimeEdit::dateTimeChanged, [controller, this] (const QDateTime&) {
29		m_ui.timeButtons->checkedButton()->clicked();
30	});
31	connect(m_ui.timeNow, &QPushButton::clicked, [controller, this] () {
32		m_ui.time->setDateTime(QDateTime::currentDateTime());
33	});
34 }
35
36void SensorView::setLuminanceValue(int value) {
37	bool oldState;
38	value = std::max(0, std::min(value, 255));
39
40	oldState = m_ui.lightSpin->blockSignals(true);
41	m_ui.lightSpin->setValue(value);
42	m_ui.lightSpin->blockSignals(oldState);
43
44	oldState = m_ui.lightSlide->blockSignals(true);
45	m_ui.lightSlide->setValue(value);
46	m_ui.lightSlide->blockSignals(oldState);
47
48	m_controller->setLuminanceValue(value);
49}