| 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 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | namespace Qt3DInput { |
| 63 | |
| 64 | class QInputAspect; |
| 65 | |
| 66 | namespace Input { |
| 67 | |
| 68 | class InputHandler; |
| 69 | |
| 70 | class Q_AUTOTEST_EXPORT KeyboardDevice : public Qt3DInput::QAbstractPhysicalDeviceBackendNode |
| 71 | { |
| 72 | public: |
| 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 | |
| 89 | private: |
| 90 | void setButtonValue(int key, bool value); |
| 91 | |
| 92 | InputHandler *m_inputHandler; |
| 93 | QVector<Qt3DCore::QNodeId> m_keyboardInputs; |
| 94 | Qt3DCore::QNodeId m_lastRequester; |
| 95 | Qt3DCore::QNodeId m_currentFocusItem; |
| 96 | |
| 97 | union KeyStates { |
| 98 | |
| 99 | struct Buttons |
| 100 | { |
| 101 | // first 4 bytes |
| 102 | bool keyEscape:1; // 0 |
| 103 | bool keyTab:1; // 1 |
| 104 | bool keyBacktab:1; // 2 |
| 105 | bool keyBackspace:1; // 3 |
| 106 | bool keyReturn:1; // 4 |
| 107 | bool keyEnter:1; // 5 |
| 108 | bool keyInsert:1; // 6 |
| 109 | bool keyDelete:1; // 7 |
| 110 | bool keyPause:1; // 8 |
| 111 | bool keyPrint:1; // 9 |
| 112 | bool keySysReq:1; // 10 |
| 113 | bool keyClear:1; // 11 |
| 114 | bool keyHome:1; // 12 |
| 115 | bool keyEnd:1; // 13 |
| 116 | bool keyLeft:1; // 14 |
| 117 | bool keyUp:1; // 15 |
| 118 | bool keyRight:1; // 16 |
| 119 | bool keyDown:1; // 17 |
| 120 | bool keyPageUp:1; // 18 |
| 121 | bool keyPageDown:1; // 19 |
| 122 | bool keyShift:1; // 20 |
| 123 | bool keyControl:1; // 21 |
| 124 | bool keyMeta:1; // 22 |
| 125 | bool keyAlt:1; // 23 |
| 126 | bool keyCapsLock:1; // 24 |
| 127 | bool keyNumLock:1; // 25 |
| 128 | bool keyScrollLock:1; // 26 |
| 129 | bool keyF1:1; // 27 |
| 130 | bool keyF2:1; // 28 |
| 131 | bool keyF3:1; // 29 |
| 132 | bool keyF4:1; // 30 |
| 133 | bool keyF5:1; // 31 |
| 134 | |
| 135 | // second 4 bytes |
| 136 | bool keyF6:1; // 0 |
| 137 | bool keyF7:1; // 1 |
| 138 | bool keyF8:1; // 2 |
| 139 | bool keyF9:1; // 3 |
| 140 | bool keyF10:1; // 4 |
| 141 | bool keyF11:1; // 5 |
| 142 | bool keyF12:1; // 6 |
| 143 | bool keyF13:1; // 7 |
| 144 | bool keyF14:1; // 8 |
| 145 | bool keyF15:1; // 9 |
| 146 | bool keyF16:1; // 10 |
| 147 | bool keyF17:1; // 11 |
| 148 | bool keyF18:1; // 12 |
| 149 | bool keyF19:1; // 13 |
| 150 | bool keyF20:1; // 14 |
| 151 | bool keyF21:1; // 15 |
| 152 | bool keyF22:1; // 16 |
| 153 | bool keyF23:1; // 17 |
| 154 | bool keyF24:1; // 18 |
| 155 | bool keyF25:1; // 19 |
| 156 | bool keyF26:1; // 20 |
| 157 | bool keyF27:1; // 21 |
| 158 | bool keyF28:1; // 22 |
| 159 | bool keyF29:1; // 23 |
| 160 | bool keyF30:1; // 24 |
| 161 | bool keyF31:1; // 25 |
| 162 | bool keyF32:1; // 26 |
| 163 | bool keyF33:1; // 27 |
| 164 | bool keyF34:1; // 28 |
| 165 | bool keyF35:1; // 29 |
| 166 | bool keySuper_L:1; // 30 |
| 167 | bool keySuper_R:1; // 31 |
| 168 | |
| 169 | // third 4 bytes |
| 170 | // unused // 0 |
| 171 | bool :1; // 1 |
| 172 | bool keyHyper_L:1; // 2 |
| 173 | bool keyHyper_R:1; // 3 |
| 174 | bool keyHelp:1; // 4 |
| 175 | bool keyDirection_L:1; // 5 |
| 176 | bool keyDirection_R:1; // 6 |
| 177 | bool keySpace:1; // 7 |
| 178 | bool keyAny:1; // 8 |
| 179 | bool keyExclam:1; // 9 |
| 180 | bool keyQuoteDbl:1; // 10 |
| 181 | bool keyNumberSign:1; // 11 |
| 182 | bool keyDollar:1; // 12 |
| 183 | bool keyPercent:1; // 13 |
| 184 | bool keyAmpersand:1; // 14 |
| 185 | bool keyApostrophe:1; // 15 |
| 186 | bool keyParenLeft:1; // 16 |
| 187 | bool keyParenRight:1; // 17 |
| 188 | bool keyAsterisk:1; // 18 |
| 189 | bool keyPlus:1; // 19 |
| 190 | bool keyComma:1; // 20 |
| 191 | bool keyMinus:1; // 21 |
| 192 | bool keyPeriod:1; // 22 |
| 193 | bool keySlash:1; // 23 |
| 194 | bool key0:1; // 24 |
| 195 | bool key1:1; // 25 |
| 196 | bool key2:1; // 26 |
| 197 | bool key3:1; // 27 |
| 198 | bool key4:1; // 28 |
| 199 | bool key5:1; // 29 |
| 200 | bool key6:1; // 30 |
| 201 | bool key7:1; // 31 |
| 202 | |
| 203 | // fourth 4 bytes |
| 204 | bool key8:1; // 0 |
| 205 | bool key9:1; // 1 |
| 206 | bool keyColon:1; // 2 |
| 207 | bool keySemicolon:1; // 3 |
| 208 | bool keyLess:1; // 4 |
| 209 | bool keyEqual:1; // 5 |
| 210 | bool keyGreater:1; // 6 |
| 211 | bool keyQuestion:1; // 7 |
| 212 | bool keyAt:1; // 8 |
| 213 | bool keyA:1; // 9 |
| 214 | bool keyB:1; // 10 |
| 215 | bool keyC:1; // 11 |
| 216 | bool keyD:1; // 12 |
| 217 | bool keyE:1; // 13 |
| 218 | bool keyF:1; // 14 |
| 219 | bool keyG:1; // 15 |
| 220 | bool keyH:1; // 16 |
| 221 | bool keyI:1; // 17 |
| 222 | bool keyJ:1; // 18 |
| 223 | bool keyK:1; // 19 |
| 224 | bool keyL:1; // 20 |
| 225 | bool keyM:1; // 21 |
| 226 | bool keyN:1; // 22 |
| 227 | bool keyO:1; // 23 |
| 228 | bool keyP:1; // 24 |
| 229 | bool keyQ:1; // 25 |
| 230 | bool keyR:1; // 26 |
| 231 | bool keyS:1; // 27 |
| 232 | bool keyT:1; // 28 |
| 233 | bool keyU:1; // 29 |
| 234 | bool keyV:1; // 30 |
| 235 | bool keyW:1; // 31 |
| 236 | |
| 237 | // fifth 4 bytes |
| 238 | bool keyX:1; // 0 |
| 239 | bool keyY:1; // 1 |
| 240 | bool keyZ:1; // 2 |
| 241 | bool keyBracketLeft:1; // 3 |
| 242 | bool keyBackslash:1; // 4 |
| 243 | bool keyBracketRight:1; // 5 |
| 244 | bool keyAsciiCircum:1; // 6 |
| 245 | bool keyUnderscore:1; // 7 |
| 246 | bool keyQuoteLeft:1; // 8 |
| 247 | bool keyBraceLeft:1; // 9 |
| 248 | bool keyBar:1; // 10 |
| 249 | bool keyBraceRight:1; // 11 |
| 250 | bool keyAsciiTilde:1; // 12 |
| 251 | bool keyplusminus:1; // 13 |
| 252 | bool keyonesuperior:1; // 14 |
| 253 | bool keymultiply:1; // 15 |
| 254 | bool keydivision:1; // 16 |
| 255 | bool keyydiaeresis:1; // 17 |
| 256 | }; |
| 257 | qint32 keys[5]; |
| 258 | }; |
| 259 | |
| 260 | KeyStates m_keyStates; |
| 261 | }; |
| 262 | |
| 263 | class KeyboardDeviceFunctor : public Qt3DCore::QBackendNodeMapper |
| 264 | { |
| 265 | public: |
| 266 | explicit KeyboardDeviceFunctor(QInputAspect *inputaspect, InputHandler *handler); |
| 267 | |
| 268 | Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const override; |
| 269 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override; |
| 270 | void destroy(Qt3DCore::QNodeId id) const override; |
| 271 | |
| 272 | private: |
| 273 | QInputAspect *m_inputAspect; |
| 274 | InputHandler *m_handler; |
| 275 | }; |
| 276 | |
| 277 | } // namespace Input |
| 278 | } // namespace Qt3DInput |
| 279 | |
| 280 | QT_END_NAMESPACE |
| 281 | |
| 282 | #endif // QT3DINPUT_INPUT_KEYBOARDDEVICE_P_H |
| 283 | |