src/SpacenavWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Mar 2019 18:33:22 +0100
branchv_0
changeset 9 d3716f03efcd
parent 8 f351c261cbfd
child 11 aaa89fe98b63
permissions -rw-r--r--
display status – connection type (domain socket or X11)
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
	}
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    40
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    41
	widget.period->setMinimum(0);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    42
	widget.period->setMaximum(100);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    43
	widget.period->setValue(0);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    44
	widget.period->setFormat("%v ms");
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    45
	widget.period->setToolTip("duration in milliseconds from the last change");
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
}
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
SpacenavWindow::~SpacenavWindow() {
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
}
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    51
void SpacenavWindow::spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e) {
7
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    52
	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
    53
	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
    54
	widget.motionZ->setValue(e.z);
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    55
	
7
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    56
	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
    57
	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
    58
	widget.rotationZ->setValue(e.rz);
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    59
	
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    60
	widget.period->setValue(e.period);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    61
	// std::wcerr << L"period: " << e.period << std::endl;
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
}
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    63
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    64
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
    65
	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
    66
	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
    67
}
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    68
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    69
void SpacenavWindow::spacenavConnectionStatus(SpacenavWrapper::ConnectionStatus s) {
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    70
	if (s == SpacenavWrapper::ConnectionStatus::DOMAIN_SOCKET) widget.connection->setText("connected through: domain socket");
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    71
	if (s == SpacenavWrapper::ConnectionStatus::X11) widget.connection->setText("connected through: X11");
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    72
}
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    73