author | František Kučera <franta-hg@frantovo.cz> |
Thu, 07 Mar 2019 16:20:51 +0100 | |
branch | v_0 |
changeset 6 | 49560660d230 |
parent 4 | 1383ad1c4f57 |
child 9 | d3716f03efcd |
permissions | -rw-r--r-- |
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Spacenav Demo Qt |
4 | 3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
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 |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* (at your option) any later version. |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
*/ |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#pragma once |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <QObject> |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <QThread> |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
4 | 23 |
#include "SpacenavWrapper.h" |
24 |
||
6
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
25 |
Q_DECLARE_METATYPE(SpacenavWrapper::Event::MotionEvent) |
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
26 |
Q_DECLARE_METATYPE(SpacenavWrapper::Event::ButtonEvent) |
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
class SpacenavReceiver : public QThread { |
4 | 29 |
Q_OBJECT |
30 |
private: |
|
31 |
SpacenavWrapper spnav; |
|
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
public: |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
SpacenavReceiver() : QThread() { |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
} |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
void run() { |
4 | 39 |
while (true) { |
40 |
SpacenavWrapper::Event e = spnav.waitEvent(); |
|
6
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
41 |
if (e.type == SpacenavWrapper::Event::Type::MOTION) emit spacenavMotionEvent(e.motion); |
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
42 |
if (e.type == SpacenavWrapper::Event::Type::BUTTON) emit spacenavButtonEvent(e.button); |
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
} |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
} |
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
|
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
signals: |
6
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
47 |
void spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e); |
49560660d230
emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
48 |
void spacenavButtonEvent(SpacenavWrapper::Event::ButtonEvent e); |
1
2a3e9f07c128
receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
}; |