--- a/src/ButtonEvent.h Thu Mar 14 16:11:08 2019 +0100
+++ b/src/ButtonEvent.h Thu Mar 14 16:46:16 2019 +0100
@@ -22,6 +22,12 @@
int number;
bool pressed;
+ ButtonEvent() {
+ }
+
+ ButtonEvent(const ButtonEvent& other) : number(other.number), pressed(other.pressed) {
+ }
+
ButtonEvent(int number, bool pressed) :
number(number), pressed(pressed) {
}
--- a/src/CMakeLists.txt Thu Mar 14 16:11:08 2019 +0100
+++ b/src/CMakeLists.txt Thu Mar 14 16:46:16 2019 +0100
@@ -34,6 +34,7 @@
# QObjects must be listed here (including them from other files is not enough)
SimulatorWindow.h
SimulatorWindow.cpp
+ SimulatorSocketServer.cpp
spacenav-simulator-qt.cpp
)
--- a/src/SimulatorSocketServer.cpp Thu Mar 14 16:11:08 2019 +0100
+++ b/src/SimulatorSocketServer.cpp Thu Mar 14 16:46:16 2019 +0100
@@ -16,7 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <iostream>
+
#include "SimulatorSocketServer.h"
+#include "ButtonEvent.h"
+#include "MotionEvent.h"
SimulatorSocketServer::SimulatorSocketServer() {
}
@@ -27,3 +31,20 @@
SimulatorSocketServer::~SimulatorSocketServer() {
}
+void SimulatorSocketServer::publishButtonEvent(const ButtonEvent e) {
+ std::wcout << L"buttonEvent(" << e.number << L", " << (e.pressed ? L"pressed" : L"released") << L")" << std::endl;
+}
+
+void SimulatorSocketServer::publishMotionEvent(const MotionEvent e) {
+ std::wcout << L"motionEvent( m = ["
+ << e.x << L", "
+ << e.y << L", "
+ << e.z << L"], "
+ << L"r = ["
+ << e.rx << L", "
+ << e.ry << L", "
+ << e.rz << L"], "
+ << L"period = " << e.period
+ << L")" << std::endl;
+
+}
--- a/src/SimulatorSocketServer.h Thu Mar 14 16:11:08 2019 +0100
+++ b/src/SimulatorSocketServer.h Thu Mar 14 16:46:16 2019 +0100
@@ -17,11 +17,20 @@
*/
#pragma once
-class SimulatorSocketServer {
+#include <qt5/QtCore/QObject>
+
+#include "MotionEvent.h"
+#include "ButtonEvent.h"
+
+class SimulatorSocketServer : public QObject {
+ Q_OBJECT
public:
SimulatorSocketServer();
SimulatorSocketServer(const SimulatorSocketServer& orig);
virtual ~SimulatorSocketServer();
+public slots:
+ void publishMotionEvent(const MotionEvent e);
+ void publishButtonEvent(const ButtonEvent e);
private:
};
--- a/src/SimulatorWindow.cpp Thu Mar 14 16:11:08 2019 +0100
+++ b/src/SimulatorWindow.cpp Thu Mar 14 16:46:16 2019 +0100
@@ -23,6 +23,9 @@
#include "SimulatorWindow.h"
+Q_DECLARE_METATYPE(MotionEvent);
+Q_DECLARE_METATYPE(ButtonEvent);
+
SimulatorWindow::SimulatorWindow() {
resize(640, 480);
setWindowTitle("Spacenav Simulator");
@@ -83,7 +86,6 @@
QSlider* SimulatorWindow::createSlider(QWidget* parent) {
QSlider* slider = new QSlider(Qt::Orientation::Horizontal, parent);
- rotations.push_back(slider);
slider->setRange(-500, 500);
slider->setValue(0);
slider->setTickPosition(QSlider::TicksBelow);
--- a/src/SimulatorWindow.h Thu Mar 14 16:11:08 2019 +0100
+++ b/src/SimulatorWindow.h Thu Mar 14 16:46:16 2019 +0100
@@ -33,8 +33,8 @@
SimulatorWindow(const SimulatorWindow& orig);
virtual ~SimulatorWindow();
signals:
- void motionEvent(const MotionEvent e);
- void buttonEvent(const ButtonEvent e);
+ void motionEvent(MotionEvent e);
+ void buttonEvent(ButtonEvent e);
private:
std::vector<QCheckBox*> buttons;
std::vector<QSlider*> motions;
--- a/src/spacenav-simulator-qt.cpp Thu Mar 14 16:11:08 2019 +0100
+++ b/src/spacenav-simulator-qt.cpp Thu Mar 14 16:46:16 2019 +0100
@@ -21,6 +21,7 @@
#include <QThread>
#include "SimulatorWindow.h"
+#include "SimulatorSocketServer.h"
int main(int argc, char**argv) {
setlocale(LC_ALL, "");
@@ -28,6 +29,11 @@
SimulatorWindow w;
w.show();
+
+ SimulatorSocketServer socketServer;
+
+ QObject::connect(&w, &SimulatorWindow::motionEvent, &socketServer, &SimulatorSocketServer::publishMotionEvent);
+ QObject::connect(&w, &SimulatorWindow::buttonEvent, &socketServer, &SimulatorSocketServer::publishButtonEvent);
int qtResultCode = app.exec();