1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H
41#define QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <Qt3DInput/QKeyEvent>
55#include <Qt3DCore/qnodeid.h>
56
57#include <Qt3DInput/private/handle_types_p.h>
58#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
59
60QT_BEGIN_NAMESPACE
61
62namespace Qt3DInput {
63
64class QInputAspect;
65
66namespace Input {
67
68class InputHandler;
69
70class Q_AUTOTEST_EXPORT KeyboardDevice : public Qt3DInput::QAbstractPhysicalDeviceBackendNode
71{
72public:
73 KeyboardDevice();
74 void cleanup() override;
75
76 void requestFocusForInput(Qt3DCore::QNodeId inputId);
77 void setInputHandler(InputHandler *handler);
78
79 void setCurrentFocusItem(Qt3DCore::QNodeId input);
80
81 float axisValue(int axisIdentifier) const override;
82 bool isButtonPressed(int buttonIdentifier) const override;
83
84 void updateKeyEvents(const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events);
85
86 inline Qt3DCore::QNodeId currentFocusItem() const { return m_currentFocusItem; }
87 inline Qt3DCore::QNodeId lastKeyboardInputRequester() const { return m_lastRequester; }
88
89protected:
90 void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) override;
91
92private:
93 void setButtonValue(int key, bool value);
94
95 InputHandler *m_inputHandler;
96 QVector<Qt3DCore::QNodeId> m_keyboardInputs;
97 Qt3DCore::QNodeId m_lastRequester;
98 Qt3DCore::QNodeId m_currentFocusItem;
99
100 union KeyStates {
101
102 struct Buttons
103 {
104 // first 4 bytes
105 bool keyEscape:1; // 0
106 bool keyTab:1; // 1
107 bool keyBacktab:1; // 2
108 bool keyBackspace:1; // 3
109 bool keyReturn:1; // 4
110 bool keyEnter:1; // 5
111 bool keyInsert:1; // 6
112 bool keyDelete:1; // 7
113 bool keyPause:1; // 8
114 bool keyPrint:1; // 9
115 bool keySysReq:1; // 10
116 bool keyClear:1; // 11
117 bool keyHome:1; // 12
118 bool keyEnd:1; // 13
119 bool keyLeft:1; // 14
120 bool keyUp:1; // 15
121 bool keyRight:1; // 16
122 bool keyDown:1; // 17
123 bool keyPageUp:1; // 18
124 bool keyPageDown:1; // 19
125 bool keyShift:1; // 20
126 bool keyControl:1; // 21
127 bool keyMeta:1; // 22
128 bool keyAlt:1; // 23
129 bool keyCapsLock:1; // 24
130 bool keyNumLock:1; // 25
131 bool keyScrollLock:1; // 26
132 bool keyF1:1; // 27
133 bool keyF2:1; // 28
134 bool keyF3:1; // 29
135 bool keyF4:1; // 30
136 bool keyF5:1; // 31
137
138 // second 4 bytes
139 bool keyF6:1; // 0
140 bool keyF7:1; // 1
141 bool keyF8:1; // 2
142 bool keyF9:1; // 3
143 bool keyF10:1; // 4
144 bool keyF11:1; // 5
145 bool keyF12:1; // 6
146 bool keyF13:1; // 7
147 bool keyF14:1; // 8
148 bool keyF15:1; // 9
149 bool keyF16:1; // 10
150 bool keyF17:1; // 11
151 bool keyF18:1; // 12
152 bool keyF19:1; // 13
153 bool keyF20:1; // 14
154 bool keyF21:1; // 15
155 bool keyF22:1; // 16
156 bool keyF23:1; // 17
157 bool keyF24:1; // 18
158 bool keyF25:1; // 19
159 bool keyF26:1; // 20
160 bool keyF27:1; // 21
161 bool keyF28:1; // 22
162 bool keyF29:1; // 23
163 bool keyF30:1; // 24
164 bool keyF31:1; // 25
165 bool keyF32:1; // 26
166 bool keyF33:1; // 27
167 bool keyF34:1; // 28
168 bool keyF35:1; // 29
169 bool keySuper_L:1; // 30
170 bool keySuper_R:1; // 31
171
172 // third 4 bytes
173 // unused // 0
174 bool keyMenu:1; // 1
175 bool keyHyper_L:1; // 2
176 bool keyHyper_R:1; // 3
177 bool keyHelp:1; // 4
178 bool keyDirection_L:1; // 5
179 bool keyDirection_R:1; // 6
180 bool keySpace:1; // 7
181 bool keyAny:1; // 8
182 bool keyExclam:1; // 9
183 bool keyQuoteDbl:1; // 10
184 bool keyNumberSign:1; // 11
185 bool keyDollar:1; // 12
186 bool keyPercent:1; // 13
187 bool keyAmpersand:1; // 14
188 bool keyApostrophe:1; // 15
189 bool keyParenLeft:1; // 16
190 bool keyParenRight:1; // 17
191 bool keyAsterisk:1; // 18
192 bool keyPlus:1; // 19
193 bool keyComma:1; // 20
194 bool keyMinus:1; // 21
195 bool keyPeriod:1; // 22
196 bool keySlash:1; // 23
197 bool key0:1; // 24
198 bool key1:1; // 25
199 bool key2:1; // 26
200 bool key3:1; // 27
201 bool key4:1; // 28
202 bool key5:1; // 29
203 bool key6:1; // 30
204 bool key7:1; // 31
205
206 // fourth 4 bytes
207 bool key8:1; // 0
208 bool key9:1; // 1
209 bool keyColon:1; // 2
210 bool keySemicolon:1; // 3
211 bool keyLess:1; // 4
212 bool keyEqual:1; // 5
213 bool keyGreater:1; // 6
214 bool keyQuestion:1; // 7
215 bool keyAt:1; // 8
216 bool keyA:1; // 9
217 bool keyB:1; // 10
218 bool keyC:1; // 11
219 bool keyD:1; // 12
220 bool keyE:1; // 13
221 bool keyF:1; // 14
222 bool keyG:1; // 15
223 bool keyH:1; // 16
224 bool keyI:1; // 17
225 bool keyJ:1; // 18
226 bool keyK:1; // 19
227 bool keyL:1; // 20
228 bool keyM:1; // 21
229 bool keyN:1; // 22
230 bool keyO:1; // 23
231 bool keyP:1; // 24
232 bool keyQ:1; // 25
233 bool keyR:1; // 26
234 bool keyS:1; // 27
235 bool keyT:1; // 28
236 bool keyU:1; // 29
237 bool keyV:1; // 30
238 bool keyW:1; // 31
239
240 // fifth 4 bytes
241 bool keyX:1; // 0
242 bool keyY:1; // 1
243 bool keyZ:1; // 2
244 bool keyBracketLeft:1; // 3
245 bool keyBackslash:1; // 4
246 bool keyBracketRight:1; // 5
247 bool keyAsciiCircum:1; // 6
248 bool keyUnderscore:1; // 7
249 bool keyQuoteLeft:1; // 8
250 bool keyBraceLeft:1; // 9
251 bool keyBar:1; // 10
252 bool keyBraceRight:1; // 11
253 bool keyAsciiTilde:1; // 12
254 bool keyplusminus:1; // 13
255 bool keyonesuperior:1; // 14
256 bool keymultiply:1; // 15
257 bool keydivision:1; // 16
258 bool keyydiaeresis:1; // 17
259 };
260 qint32 keys[5];
261 };
262
263 KeyStates m_keyStates;
264};
265
266class KeyboardDeviceFunctor : public Qt3DCore::QBackendNodeMapper
267{
268public:
269 explicit KeyboardDeviceFunctor(QInputAspect *inputaspect, InputHandler *handler);
270
271 Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const override;
272 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override;
273 void destroy(Qt3DCore::QNodeId id) const override;
274
275private:
276 QInputAspect *m_inputAspect;
277 InputHandler *m_handler;
278};
279
280} // namespace Input
281} // namespace Qt3DInput
282
283QT_END_NAMESPACE
284
285#endif // QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H
286