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 connect(m_controller, SIGNAL(luminanceValueChanged(int)), this, SLOT(luminanceValueChanged(int)));
36 }
37
38void SensorView::setLuminanceValue(int value) {
39 value = std::max(0, std::min(value, 255));
40 m_controller->setLuminanceValue(value);
41}
42
43void SensorView::luminanceValueChanged(int value) {
44 bool oldState;
45 oldState = m_ui.lightSpin->blockSignals(true);
46 m_ui.lightSpin->setValue(value);
47 m_ui.lightSpin->blockSignals(oldState);
48
49 oldState = m_ui.lightSlide->blockSignals(true);
50 m_ui.lightSlide->setValue(value);
51 m_ui.lightSlide->blockSignals(oldState);
52}