# HG changeset patch # User František Kučera # Date 1552576268 -3600 # Node ID a27850958a67740306b4de278f3681524086ae34 # Parent 9cd86b92aabbac9d3c012e742df8d814ab91c577 emit button and motion events diff -r 9cd86b92aabb -r a27850958a67 nbproject/configurations.xml --- a/nbproject/configurations.xml Thu Mar 14 00:23:34 2019 +0100 +++ b/nbproject/configurations.xml Thu Mar 14 16:11:08 2019 +0100 @@ -58,6 +58,8 @@ + SimulatorSocketServer.cpp + SimulatorSocketServer.h SimulatorWindow.cpp SimulatorWindow.h spacenav-simulator-qt.cpp @@ -144,6 +146,10 @@ + + + + @@ -221,6 +227,10 @@ + + + + diff -r 9cd86b92aabb -r a27850958a67 src/ButtonEvent.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ButtonEvent.h Thu Mar 14 16:11:08 2019 +0100 @@ -0,0 +1,29 @@ +/** + * Spacenav Demo Qt + * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +class ButtonEvent { +public: + int number; + bool pressed; + + ButtonEvent(int number, bool pressed) : + number(number), pressed(pressed) { + } + +}; diff -r 9cd86b92aabb -r a27850958a67 src/MotionEvent.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MotionEvent.h Thu Mar 14 16:11:08 2019 +0100 @@ -0,0 +1,30 @@ +/** + * Spacenav Demo Qt + * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +class MotionEvent { +public: + int x; + int y; + int z; + int rx; + int ry; + int rz; + int type; + unsigned int period; +}; diff -r 9cd86b92aabb -r a27850958a67 src/SimulatorSocketServer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SimulatorSocketServer.cpp Thu Mar 14 16:11:08 2019 +0100 @@ -0,0 +1,29 @@ +/** + * Spacenav Simulator Qt + * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "SimulatorSocketServer.h" + +SimulatorSocketServer::SimulatorSocketServer() { +} + +SimulatorSocketServer::SimulatorSocketServer(const SimulatorSocketServer& orig) { +} + +SimulatorSocketServer::~SimulatorSocketServer() { +} + diff -r 9cd86b92aabb -r a27850958a67 src/SimulatorSocketServer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SimulatorSocketServer.h Thu Mar 14 16:11:08 2019 +0100 @@ -0,0 +1,27 @@ +/** + * Spacenav Simulator Qt + * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +class SimulatorSocketServer { +public: + SimulatorSocketServer(); + SimulatorSocketServer(const SimulatorSocketServer& orig); + virtual ~SimulatorSocketServer(); +private: + +}; diff -r 9cd86b92aabb -r a27850958a67 src/SimulatorWindow.cpp --- 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 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 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); +} diff -r 9cd86b92aabb -r a27850958a67 src/SimulatorWindow.h --- a/src/SimulatorWindow.h Thu Mar 14 00:23:34 2019 +0100 +++ b/src/SimulatorWindow.h Thu Mar 14 16:11:08 2019 +0100 @@ -23,12 +23,18 @@ #include #include +#include "MotionEvent.h" +#include "ButtonEvent.h" + class SimulatorWindow : public QMainWindow { Q_OBJECT public: SimulatorWindow(); SimulatorWindow(const SimulatorWindow& orig); virtual ~SimulatorWindow(); +signals: + void motionEvent(const MotionEvent e); + void buttonEvent(const ButtonEvent e); private: std::vector buttons; std::vector motions; @@ -38,4 +44,5 @@ private slots: void centerAll(); + void sendMotionEvent(); };