src/SpacenavWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Mar 2019 17:03:43 +0100
branchv_0
changeset 7 b6c0e1574a8b
parent 6 49560660d230
child 8 f351c261cbfd
permissions -rw-r--r--
display buttons, motions and rotations of all axes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Spacenav Demo Qt
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include "SpacenavWindow.h"
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
SpacenavWindow::SpacenavWindow() {
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	widget.setupUi(this);
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    23
	resize(640, 480);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    24
	setWindowTitle("Spacenav Demo");
7
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    25
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    26
	std::vector<QCheckBox*> buttons{ widget.button0, widget.button1};
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    27
	for (QCheckBox* b : buttons) b->setEnabled(false);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    28
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    29
	std::vector<QProgressBar*> motions{
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    30
		widget.motionX, widget.motionY, widget.motionZ,
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    31
		widget.rotationX, widget.rotationY, widget.rotationZ
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    32
	};
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    33
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    34
	for (QProgressBar* m : motions) {
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    35
		m->setMinimum(-500);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    36
		m->setMaximum(500);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    37
		m->setValue(0);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    38
		m->setFormat("%v");
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    39
	}
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
}
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
SpacenavWindow::~SpacenavWindow() {
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
}
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    45
void SpacenavWindow::spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e) {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    46
	setWindowTitle("m event!");
7
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    47
	widget.motionX->setValue(e.x);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    48
	widget.motionY->setValue(e.y);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    49
	widget.motionZ->setValue(e.z);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    50
	widget.rotationX->setValue(e.rx);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    51
	widget.rotationY->setValue(e.ry);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    52
	widget.rotationZ->setValue(e.rz);
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
}
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    54
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    55
void SpacenavWindow::spacenavButtonEvent(SpacenavWrapper::Event::ButtonEvent e) {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    56
	if (e.number == 0) widget.button0->setChecked(e.pressed);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    57
	if (e.number == 1) widget.button1->setChecked(e.pressed);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    58
}