src/SimulatorWindow.cpp
branchv_0
changeset 1 9cd86b92aabb
child 2 a27850958a67
equal deleted inserted replaced
0:bb36d1770a9e 1:9cd86b92aabb
       
     1 /**
       
     2  * Spacenav Simulator Qt
       
     3  * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, either version 3 of the License, or
       
     8  * (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17  */
       
    18 
       
    19 #include <QtWidgets/QFormLayout>
       
    20 #include <QtWidgets/QLabel>
       
    21 #include <QtWidgets/QGridLayout>
       
    22 #include <qt5/QtCore/qobject.h>
       
    23 
       
    24 #include "SimulatorWindow.h"
       
    25 
       
    26 SimulatorWindow::SimulatorWindow() {
       
    27 	resize(640, 480);
       
    28 	setWindowTitle("Spacenav Simulator");
       
    29 
       
    30 	QWidget* centralwidget = new QWidget(this);
       
    31 	QFormLayout* formLayout = new QFormLayout(centralwidget);
       
    32 
       
    33 	int f = 0;
       
    34 
       
    35 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Buttons:", centralwidget));
       
    36 	std::vector<QString> buttonLabels = {"0", "1"};
       
    37 
       
    38 	for (QString b : buttonLabels) {
       
    39 		QCheckBox* button = new QCheckBox(centralwidget);
       
    40 		buttons.push_back(button);
       
    41 		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(b, centralwidget));
       
    42 		formLayout->setWidget(f++, QFormLayout::FieldRole, button);
       
    43 	}
       
    44 
       
    45 	std::vector<QString> axisLabels = {"X", "Y", "Z"};
       
    46 
       
    47 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Motion:", centralwidget));
       
    48 	for (QString a : axisLabels) {
       
    49 		QSlider* slider = createSlider(centralwidget);
       
    50 		motions.push_back(slider);
       
    51 		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
       
    52 		formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
       
    53 	}
       
    54 
       
    55 
       
    56 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Rotation:", centralwidget));
       
    57 	for (QString a : axisLabels) {
       
    58 		QSlider* slider = createSlider(centralwidget);
       
    59 		rotations.push_back(slider);
       
    60 		formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
       
    61 		formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
       
    62 	}
       
    63 
       
    64 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Actions:", centralwidget));
       
    65 	centerButton = new QPushButton("Center all", centralwidget);
       
    66 	connect(centerButton, &QPushButton::clicked, this, &SimulatorWindow::centerAll);
       
    67 	formLayout->setWidget(f++, QFormLayout::FieldRole, centerButton);
       
    68 
       
    69 
       
    70 	setCentralWidget(centralwidget);
       
    71 }
       
    72 
       
    73 SimulatorWindow::SimulatorWindow(const SimulatorWindow& orig) {
       
    74 }
       
    75 
       
    76 SimulatorWindow::~SimulatorWindow() {
       
    77 }
       
    78 
       
    79 QSlider* SimulatorWindow::createSlider(QWidget* parent) {
       
    80 	QSlider* slider = new QSlider(Qt::Orientation::Horizontal, parent);
       
    81 	rotations.push_back(slider);
       
    82 	slider->setRange(-500, 500);
       
    83 	slider->setValue(0);
       
    84 	slider->setTickPosition(QSlider::TicksBelow);
       
    85 	slider->setTickInterval(100);
       
    86 	slider->setSingleStep(1);
       
    87 	return slider;
       
    88 }
       
    89 
       
    90 void SimulatorWindow::centerAll() {
       
    91 	for (QSlider* s : motions) s->setValue(0);
       
    92 	for (QSlider* s : rotations) s->setValue(0);
       
    93 }