src/spacenav-demo-qt.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:
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Spacenav Demo Qt
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
37aa134ae57b empty QT project linked to spnav library
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.
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <stdio.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <QApplication>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <QThread>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    22
#include "SpacenavReceiver.h"
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    23
#include "SpacenavWindow.h"
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    24
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
int main(int argc, char**argv) {
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	setlocale(LC_ALL, "");
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	QApplication app(argc, argv);
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    29
	SpacenavReceiver t;
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    30
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    31
	SpacenavWindow w;
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    32
	w.show();
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    33
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    34
	QObject::connect(&t, &SpacenavReceiver::spacenavMotionEvent, &w, &SpacenavWindow::spacenavMotionEvent, Qt::ConnectionType::QueuedConnection);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    35
	QObject::connect(&t, &SpacenavReceiver::spacenavButtonEvent, &w, &SpacenavWindow::spacenavButtonEvent, Qt::ConnectionType::QueuedConnection);
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    36
	QObject::connect(&t, &SpacenavReceiver::spacenavConnectionStatus, &w, &SpacenavWindow::spacenavConnectionStatus, Qt::ConnectionType::QueuedConnection);
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    37
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    38
	t.start();
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    39
	int qtResultCode = app.exec();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    40
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    41
	if (t.isRunning()) {
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    42
		std::wcerr << L"Background RelationalReader thread is still running → terminate()" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    43
		t.terminate();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    44
		std::wcerr << L"Background RelationalReader thread was terminated → wait()" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    45
		t.wait();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    46
		std::wcerr << L"Background RelationalReader thread wait() finished" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    47
	}
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    49
	return qtResultCode;
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
}