src/SpacenavWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:49:24 +0200
branchv_0
changeset 11 aaa89fe98b63
parent 9 d3716f03efcd
permissions -rw-r--r--
fix license version: GNU GPLv3
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
11
aaa89fe98b63 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 */
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
#include "SpacenavWindow.h"
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
SpacenavWindow::SpacenavWindow() {
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	widget.setupUi(this);
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    22
	resize(640, 480);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    23
	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
    24
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    25
	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
    26
	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
    27
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    28
	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
    29
		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
    30
		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
    31
	};
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
	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
    34
		m->setMinimum(-500);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    35
		m->setMaximum(500);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    36
		m->setValue(0);
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    37
		m->setFormat("%v");
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    38
	}
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    39
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    40
	widget.period->setMinimum(0);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    41
	widget.period->setMaximum(100);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    42
	widget.period->setValue(0);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    43
	widget.period->setFormat("%v ms");
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    44
	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
    45
}
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
SpacenavWindow::~SpacenavWindow() {
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
}
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    50
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
    51
	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
    52
	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
    53
	widget.motionZ->setValue(e.z);
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    54
	
7
b6c0e1574a8b display buttons, motions and rotations of all axes
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    55
	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
    56
	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
    57
	widget.rotationZ->setValue(e.rz);
8
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    58
	
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    59
	widget.period->setValue(e.period);
f351c261cbfd display period
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    60
	// std::wcerr << L"period: " << e.period << std::endl;
5
6ba51911d539 Qt designer UI
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
}
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    62
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    63
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
    64
	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
    65
	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
    66
}
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    67
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    68
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
    69
	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
    70
	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
    71
}
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    72