1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H |
5 | #define QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <Qt3DInput/QKeyEvent> |
19 | #include <Qt3DCore/qnodeid.h> |
20 | |
21 | #include <Qt3DInput/private/handle_types_p.h> |
22 | #include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | namespace Qt3DInput { |
27 | |
28 | class QInputAspect; |
29 | |
30 | namespace Input { |
31 | |
32 | class InputHandler; |
33 | |
34 | class Q_AUTOTEST_EXPORT KeyboardDevice : public Qt3DInput::QAbstractPhysicalDeviceBackendNode |
35 | { |
36 | public: |
37 | KeyboardDevice(); |
38 | void cleanup() override; |
39 | |
40 | void requestFocusForInput(Qt3DCore::QNodeId inputId); |
41 | void setInputHandler(InputHandler *handler); |
42 | |
43 | void setCurrentFocusItem(Qt3DCore::QNodeId input); |
44 | |
45 | float axisValue(int axisIdentifier) const override; |
46 | bool isButtonPressed(int buttonIdentifier) const override; |
47 | |
48 | void updateKeyEvent(QT_PREPEND_NAMESPACE(QKeyEvent) *event); |
49 | |
50 | inline Qt3DCore::QNodeId currentFocusItem() const { return m_currentFocusItem; } |
51 | inline Qt3DCore::QNodeId lastKeyboardInputRequester() const { return m_lastRequester; } |
52 | |
53 | private: |
54 | void setButtonValue(int key, bool value); |
55 | |
56 | InputHandler *m_inputHandler; |
57 | QList<Qt3DCore::QNodeId> m_keyboardInputs; |
58 | Qt3DCore::QNodeId m_lastRequester; |
59 | Qt3DCore::QNodeId m_currentFocusItem; |
60 | |
61 | union KeyStates { |
62 | |
63 | struct Buttons |
64 | { |
65 | // first 4 bytes |
66 | bool keyEscape:1; // 0 |
67 | bool keyTab:1; // 1 |
68 | bool keyBacktab:1; // 2 |
69 | bool keyBackspace:1; // 3 |
70 | bool keyReturn:1; // 4 |
71 | bool keyEnter:1; // 5 |
72 | bool keyInsert:1; // 6 |
73 | bool keyDelete:1; // 7 |
74 | bool keyPause:1; // 8 |
75 | bool keyPrint:1; // 9 |
76 | bool keySysReq:1; // 10 |
77 | bool keyClear:1; // 11 |
78 | bool keyHome:1; // 12 |
79 | bool keyEnd:1; // 13 |
80 | bool keyLeft:1; // 14 |
81 | bool keyUp:1; // 15 |
82 | bool keyRight:1; // 16 |
83 | bool keyDown:1; // 17 |
84 | bool keyPageUp:1; // 18 |
85 | bool keyPageDown:1; // 19 |
86 | bool keyShift:1; // 20 |
87 | bool keyControl:1; // 21 |
88 | bool keyMeta:1; // 22 |
89 | bool keyAlt:1; // 23 |
90 | bool keyCapsLock:1; // 24 |
91 | bool keyNumLock:1; // 25 |
92 | bool keyScrollLock:1; // 26 |
93 | bool keyF1:1; // 27 |
94 | bool keyF2:1; // 28 |
95 | bool keyF3:1; // 29 |
96 | bool keyF4:1; // 30 |
97 | bool keyF5:1; // 31 |
98 | |
99 | // second 4 bytes |
100 | bool keyF6:1; // 0 |
101 | bool keyF7:1; // 1 |
102 | bool keyF8:1; // 2 |
103 | bool keyF9:1; // 3 |
104 | bool keyF10:1; // 4 |
105 | bool keyF11:1; // 5 |
106 | bool keyF12:1; // 6 |
107 | bool keyF13:1; // 7 |
108 | bool keyF14:1; // 8 |
109 | bool keyF15:1; // 9 |
110 | bool keyF16:1; // 10 |
111 | bool keyF17:1; // 11 |
112 | bool keyF18:1; // 12 |
113 | bool keyF19:1; // 13 |
114 | bool keyF20:1; // 14 |
115 | bool keyF21:1; // 15 |
116 | bool keyF22:1; // 16 |
117 | bool keyF23:1; // 17 |
118 | bool keyF24:1; // 18 |
119 | bool keyF25:1; // 19 |
120 | bool keyF26:1; // 20 |
121 | bool keyF27:1; // 21 |
122 | bool keyF28:1; // 22 |
123 | bool keyF29:1; // 23 |
124 | bool keyF30:1; // 24 |
125 | bool keyF31:1; // 25 |
126 | bool keyF32:1; // 26 |
127 | bool keyF33:1; // 27 |
128 | bool keyF34:1; // 28 |
129 | bool keyF35:1; // 29 |
130 | bool keySuper_L:1; // 30 |
131 | bool keySuper_R:1; // 31 |
132 | |
133 | // third 4 bytes |
134 | // unused // 0 |
135 | bool :1; // 1 |
136 | bool keyHyper_L:1; // 2 |
137 | bool keyHyper_R:1; // 3 |
138 | bool keyHelp:1; // 4 |
139 | bool keyDirection_L:1; // 5 |
140 | bool keyDirection_R:1; // 6 |
141 | bool keySpace:1; // 7 |
142 | bool keyAny:1; // 8 |
143 | bool keyExclam:1; // 9 |
144 | bool keyQuoteDbl:1; // 10 |
145 | bool keyNumberSign:1; // 11 |
146 | bool keyDollar:1; // 12 |
147 | bool keyPercent:1; // 13 |
148 | bool keyAmpersand:1; // 14 |
149 | bool keyApostrophe:1; // 15 |
150 | bool keyParenLeft:1; // 16 |
151 | bool keyParenRight:1; // 17 |
152 | bool keyAsterisk:1; // 18 |
153 | bool keyPlus:1; // 19 |
154 | bool keyComma:1; // 20 |
155 | bool keyMinus:1; // 21 |
156 | bool keyPeriod:1; // 22 |
157 | bool keySlash:1; // 23 |
158 | bool key0:1; // 24 |
159 | bool key1:1; // 25 |
160 | bool key2:1; // 26 |
161 | bool key3:1; // 27 |
162 | bool key4:1; // 28 |
163 | bool key5:1; // 29 |
164 | bool key6:1; // 30 |
165 | bool key7:1; // 31 |
166 | |
167 | // fourth 4 bytes |
168 | bool key8:1; // 0 |
169 | bool key9:1; // 1 |
170 | bool keyColon:1; // 2 |
171 | bool keySemicolon:1; // 3 |
172 | bool keyLess:1; // 4 |
173 | bool keyEqual:1; // 5 |
174 | bool keyGreater:1; // 6 |
175 | bool keyQuestion:1; // 7 |
176 | bool keyAt:1; // 8 |
177 | bool keyA:1; // 9 |
178 | bool keyB:1; // 10 |
179 | bool keyC:1; // 11 |
180 | bool keyD:1; // 12 |
181 | bool keyE:1; // 13 |
182 | bool keyF:1; // 14 |
183 | bool keyG:1; // 15 |
184 | bool keyH:1; // 16 |
185 | bool keyI:1; // 17 |
186 | bool keyJ:1; // 18 |
187 | bool keyK:1; // 19 |
188 | bool keyL:1; // 20 |
189 | bool keyM:1; // 21 |
190 | bool keyN:1; // 22 |
191 | bool keyO:1; // 23 |
192 | bool keyP:1; // 24 |
193 | bool keyQ:1; // 25 |
194 | bool keyR:1; // 26 |
195 | bool keyS:1; // 27 |
196 | bool keyT:1; // 28 |
197 | bool keyU:1; // 29 |
198 | bool keyV:1; // 30 |
199 | bool keyW:1; // 31 |
200 | |
201 | // fifth 4 bytes |
202 | bool keyX:1; // 0 |
203 | bool keyY:1; // 1 |
204 | bool keyZ:1; // 2 |
205 | bool keyBracketLeft:1; // 3 |
206 | bool keyBackslash:1; // 4 |
207 | bool keyBracketRight:1; // 5 |
208 | bool keyAsciiCircum:1; // 6 |
209 | bool keyUnderscore:1; // 7 |
210 | bool keyQuoteLeft:1; // 8 |
211 | bool keyBraceLeft:1; // 9 |
212 | bool keyBar:1; // 10 |
213 | bool keyBraceRight:1; // 11 |
214 | bool keyAsciiTilde:1; // 12 |
215 | bool keyplusminus:1; // 13 |
216 | bool keyonesuperior:1; // 14 |
217 | bool keymultiply:1; // 15 |
218 | bool keydivision:1; // 16 |
219 | bool keyydiaeresis:1; // 17 |
220 | }; |
221 | qint32 keys[5]; |
222 | }; |
223 | |
224 | KeyStates m_keyStates; |
225 | }; |
226 | |
227 | class KeyboardDeviceFunctor : public Qt3DCore::QBackendNodeMapper |
228 | { |
229 | public: |
230 | explicit KeyboardDeviceFunctor(QInputAspect *inputaspect, InputHandler *handler); |
231 | |
232 | Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override; |
233 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override; |
234 | void destroy(Qt3DCore::QNodeId id) const override; |
235 | |
236 | private: |
237 | QInputAspect *m_inputAspect; |
238 | InputHandler *m_handler; |
239 | }; |
240 | |
241 | } // namespace Input |
242 | } // namespace Qt3DInput |
243 | |
244 | QT_END_NAMESPACE |
245 | |
246 | #endif // QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H |
247 | |