# HG changeset patch # User František Kučera # Date 1552519414 -3600 # Node ID 9cd86b92aabbac9d3c012e742df8d814ab91c577 # Parent bb36d1770a9e3071969aa91bbe06b06a6ed361c2 GUI draft diff -r bb36d1770a9e -r 9cd86b92aabb nbproject/configurations.xml --- a/nbproject/configurations.xml Wed Mar 06 16:21:18 2019 +0100 +++ b/nbproject/configurations.xml Thu Mar 14 00:23:34 2019 +0100 @@ -58,6 +58,8 @@ + SimulatorWindow.cpp + SimulatorWindow.h spacenav-simulator-qt.cpp @@ -142,6 +144,10 @@ + + + + @@ -215,6 +221,10 @@ + + + + diff -r bb36d1770a9e -r 9cd86b92aabb src/CMakeLists.txt --- a/src/CMakeLists.txt Wed Mar 06 16:21:18 2019 +0100 +++ b/src/CMakeLists.txt Thu Mar 14 00:23:34 2019 +0100 @@ -32,6 +32,8 @@ add_executable( ${EXECUTABLE_FILE} # QObjects must be listed here (including them from other files is not enough) + SimulatorWindow.h + SimulatorWindow.cpp spacenav-simulator-qt.cpp ) diff -r bb36d1770a9e -r 9cd86b92aabb src/SimulatorWindow.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SimulatorWindow.cpp Thu Mar 14 00:23:34 2019 +0100 @@ -0,0 +1,93 @@ +/** + * 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 +#include +#include +#include + +#include "SimulatorWindow.h" + +SimulatorWindow::SimulatorWindow() { + resize(640, 480); + setWindowTitle("Spacenav Simulator"); + + QWidget* centralwidget = new QWidget(this); + QFormLayout* formLayout = new QFormLayout(centralwidget); + + int f = 0; + + formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Buttons:", centralwidget)); + std::vector buttonLabels = {"0", "1"}; + + for (QString b : buttonLabels) { + QCheckBox* button = new QCheckBox(centralwidget); + buttons.push_back(button); + formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(b, centralwidget)); + formLayout->setWidget(f++, QFormLayout::FieldRole, button); + } + + std::vector axisLabels = {"X", "Y", "Z"}; + + formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Motion:", centralwidget)); + for (QString a : axisLabels) { + QSlider* slider = createSlider(centralwidget); + motions.push_back(slider); + formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget)); + formLayout->setWidget(f++, QFormLayout::FieldRole, slider); + } + + + formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Rotation:", centralwidget)); + for (QString a : axisLabels) { + QSlider* slider = createSlider(centralwidget); + rotations.push_back(slider); + formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget)); + formLayout->setWidget(f++, QFormLayout::FieldRole, slider); + } + + formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Actions:", centralwidget)); + centerButton = new QPushButton("Center all", centralwidget); + connect(centerButton, &QPushButton::clicked, this, &SimulatorWindow::centerAll); + formLayout->setWidget(f++, QFormLayout::FieldRole, centerButton); + + + setCentralWidget(centralwidget); +} + +SimulatorWindow::SimulatorWindow(const SimulatorWindow& orig) { +} + +SimulatorWindow::~SimulatorWindow() { +} + +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); + slider->setTickInterval(100); + slider->setSingleStep(1); + return slider; +} + +void SimulatorWindow::centerAll() { + for (QSlider* s : motions) s->setValue(0); + for (QSlider* s : rotations) s->setValue(0); +} diff -r bb36d1770a9e -r 9cd86b92aabb src/SimulatorWindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SimulatorWindow.h Thu Mar 14 00:23:34 2019 +0100 @@ -0,0 +1,41 @@ +/** + * 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 + +#include +#include +#include +#include +#include + +class SimulatorWindow : public QMainWindow { + Q_OBJECT +public: + SimulatorWindow(); + SimulatorWindow(const SimulatorWindow& orig); + virtual ~SimulatorWindow(); +private: + std::vector buttons; + std::vector motions; + std::vector rotations; + QPushButton* centerButton; + QSlider* createSlider(QWidget* parent); + +private slots: + void centerAll(); +}; diff -r bb36d1770a9e -r 9cd86b92aabb src/spacenav-simulator-qt.cpp --- a/src/spacenav-simulator-qt.cpp Wed Mar 06 16:21:18 2019 +0100 +++ b/src/spacenav-simulator-qt.cpp Thu Mar 14 00:23:34 2019 +0100 @@ -20,14 +20,16 @@ #include #include -#include -#include -#include -#include +#include "SimulatorWindow.h" int main(int argc, char**argv) { setlocale(LC_ALL, ""); QApplication app(argc, argv); - return 0; + SimulatorWindow w; + w.show(); + + int qtResultCode = app.exec(); + + return qtResultCode; }