src/SimulatorWindow.cpp
branchv_0
changeset 2 a27850958a67
parent 1 9cd86b92aabb
child 3 42d64bd73232
--- a/src/SimulatorWindow.cpp	Thu Mar 14 00:23:34 2019 +0100
+++ b/src/SimulatorWindow.cpp	Thu Mar 14 16:11:08 2019 +0100
@@ -35,11 +35,14 @@
 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Buttons:", centralwidget));
 	std::vector<QString> buttonLabels = {"0", "1"};
 
-	for (QString b : buttonLabels) {
+	for (int i = 0; i < buttonLabels.size(); i++) {
 		QCheckBox* button = new QCheckBox(centralwidget);
 		buttons.push_back(button);
-		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(b, centralwidget));
+		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(buttonLabels[i], centralwidget));
 		formLayout->setWidget(f++, QFormLayout::FieldRole, button);
+		connect(button, &QCheckBox::stateChanged, [ i, this ](int state) {
+			emit buttonEvent({i, state == Qt::CheckState::Checked});
+		});
 	}
 
 	std::vector<QString> axisLabels = {"X", "Y", "Z"};
@@ -50,6 +53,7 @@
 		motions.push_back(slider);
 		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
 		formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
+		connect(slider, &QSlider::valueChanged, this, &SimulatorWindow::sendMotionEvent);
 	}
 
 
@@ -59,6 +63,7 @@
 		rotations.push_back(slider);
 		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
 		formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
+		connect(slider, &QSlider::valueChanged, this, &SimulatorWindow::sendMotionEvent);
 	}
 
 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Actions:", centralwidget));
@@ -91,3 +96,19 @@
 	for (QSlider* s : motions) s->setValue(0);
 	for (QSlider* s : rotations) s->setValue(0);
 }
+
+void SimulatorWindow::sendMotionEvent() {
+	MotionEvent event;
+
+	event.x = motions[0]->value();
+	event.y = motions[1]->value();
+	event.z = motions[2]->value();
+
+	event.rx = rotations[0]->value();
+	event.ry = rotations[1]->value();
+	event.rz = rotations[2]->value();
+
+	event.period = 0; // TODO: period?
+
+	emit motionEvent(event);
+}