AntiMicroX
qtkeymapperbase.h
Go to the documentation of this file.
1 /* antimicrox Gamepad to KB+M event mapper
2  * Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
3  * Copyright (C) 2020 Jagoda Górska <juliagoda.pl@protonmail>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef QTKEYMAPPERBASE_H
20 #define QTKEYMAPPERBASE_H
21 
22 #include <QHash>
23 #include <QObject>
24 
25 class QtKeyMapperBase : public QObject
26 {
27  Q_OBJECT
28 
29  public:
30  explicit QtKeyMapperBase(QObject *parent = nullptr);
31 
32  typedef struct _charKeyInformation
33  {
34  Qt::KeyboardModifiers modifiers;
37 
38  virtual int returnVirtualKey(int qkey);
39  virtual int returnQtKey(int key, int scancode = 0);
40  virtual bool isModifier(int qkey);
42  QString getIdentifier();
43 
44  static const int customQtKeyPrefix = 0x10000000;
45  static const int customKeyPrefix = 0x20000000;
46  static const int nativeKeyPrefix = 0x60000000;
47 
48  enum
49  {
50  AntKey_Shift_R = Qt::Key_Shift | customQtKeyPrefix,
51  AntKey_Control_R = Qt::Key_Control | customQtKeyPrefix,
52  AntKey_Shift_Lock = 0xffe6 | customKeyPrefix, // XK_Shift_Lock | 0x20000000
53  AntKey_Meta_R = Qt::Key_Meta | customQtKeyPrefix,
56  AntKey_KP_Multiply = Qt::Key_Asterisk | customQtKeyPrefix,
58  AntKey_KP_Add = Qt::Key_Plus | customQtKeyPrefix,
60  AntKey_KP_Insert = Qt::Key_Insert | customQtKeyPrefix,
61  AntKey_Delete = Qt::Key_Delete | customQtKeyPrefix,
65  AntKey_KP_Prior = Qt::Key_PageUp | customQtKeyPrefix,
71  AntKey_KP_Next = Qt::Key_PageDown | customQtKeyPrefix,
83  };
84 
85  protected:
86  virtual void populateMappingHashes() = 0;
87  virtual void populateCharKeyInformation() = 0;
88 
89  QHash<int, int> qtKeyToVirtKeyHash;
90  QHash<int, int> virtKeyToQtKeyHash;
91  QHash<int, charKeyInformation> virtkeyToCharKeyInfo; // Unicode representation -> VK+Modifier information
92  QString identifier;
93 };
94 
95 #endif // QTKEYMAPPERBASE_H
QtKeyMapperBase::AntKey_Meta_R
@ AntKey_Meta_R
Definition: qtkeymapperbase.h:53
QtKeyMapperBase::QtKeyMapperBase
QtKeyMapperBase(QObject *parent=nullptr)
Definition: qtkeymapperbase.cpp:27
QtKeyMapperBase::AntKey_Shift_R
@ AntKey_Shift_R
Definition: qtkeymapperbase.h:50
QtKeyMapperBase::AntKey_KP_Add
@ AntKey_KP_Add
Definition: qtkeymapperbase.h:58
QtKeyMapperBase::AntKey_KP_Divide
@ AntKey_KP_Divide
Definition: qtkeymapperbase.h:55
QtKeyMapperBase::getCharKeyInformation
charKeyInformation getCharKeyInformation(QChar value)
Definition: qtkeymapperbase.cpp:69
QtKeyMapperBase::AntKey_KP_Insert
@ AntKey_KP_Insert
Definition: qtkeymapperbase.h:60
QtKeyMapperBase::AntKey_KP_7
@ AntKey_KP_7
Definition: qtkeymapperbase.h:80
QtKeyMapperBase::AntKey_KP_Home
@ AntKey_KP_Home
Definition: qtkeymapperbase.h:69
QtKeyMapperBase::AntKey_KP_5
@ AntKey_KP_5
Definition: qtkeymapperbase.h:78
QtKeyMapperBase::AntKey_KP_Subtract
@ AntKey_KP_Subtract
Definition: qtkeymapperbase.h:57
QtKeyMapperBase::AntKey_KP_Begin
@ AntKey_KP_Begin
Definition: qtkeymapperbase.h:67
QtKeyMapperBase::AntKey_KP_Down
@ AntKey_KP_Down
Definition: qtkeymapperbase.h:64
QtKeyMapperBase::virtkeyToCharKeyInfo
QHash< int, charKeyInformation > virtkeyToCharKeyInfo
Definition: qtkeymapperbase.h:91
QtKeyMapperBase::charKeyInformation
struct QtKeyMapperBase::_charKeyInformation charKeyInformation
QtKeyMapperBase::AntKey_KP_3
@ AntKey_KP_3
Definition: qtkeymapperbase.h:76
QtKeyMapperBase::AntKey_KP_9
@ AntKey_KP_9
Definition: qtkeymapperbase.h:82
QtKeyMapperBase::AntKey_Alt_R
@ AntKey_Alt_R
Definition: qtkeymapperbase.h:54
QtKeyMapperBase::AntKey_KP_0
@ AntKey_KP_0
Definition: qtkeymapperbase.h:73
QtKeyMapperBase::returnQtKey
virtual int returnQtKey(int key, int scancode=0)
Definition: qtkeymapperbase.cpp:32
QtKeyMapperBase::getIdentifier
QString getIdentifier()
Obtain identifier string for key mapper.
Definition: qtkeymapperbase.cpp:85
QtKeyMapperBase::AntKey_KP_Multiply
@ AntKey_KP_Multiply
Definition: qtkeymapperbase.h:56
QtKeyMapperBase::AntKey_Delete
@ AntKey_Delete
Definition: qtkeymapperbase.h:61
QtKeyMapperBase::populateMappingHashes
virtual void populateMappingHashes()=0
QtKeyMapperBase::virtKeyToQtKeyHash
QHash< int, int > virtKeyToQtKeyHash
Definition: qtkeymapperbase.h:90
QtKeyMapperBase::AntKey_KP_8
@ AntKey_KP_8
Definition: qtkeymapperbase.h:81
QtKeyMapperBase::AntKey_KP_Left
@ AntKey_KP_Left
Definition: qtkeymapperbase.h:66
QtKeyMapperBase::AntKey_KP_Next
@ AntKey_KP_Next
Definition: qtkeymapperbase.h:71
QtKeyMapperBase::identifier
QString identifier
Definition: qtkeymapperbase.h:92
QtKeyMapperBase::returnVirtualKey
virtual int returnVirtualKey(int qkey)
Definition: qtkeymapperbase.cpp:39
QtKeyMapperBase::AntKey_KP_6
@ AntKey_KP_6
Definition: qtkeymapperbase.h:79
QtKeyMapperBase::AntKey_KP_End
@ AntKey_KP_End
Definition: qtkeymapperbase.h:63
QtKeyMapperBase
Definition: qtkeymapperbase.h:25
QtKeyMapperBase::AntKey_KP_Right
@ AntKey_KP_Right
Definition: qtkeymapperbase.h:68
QtKeyMapperBase::AntKey_Control_R
@ AntKey_Control_R
Definition: qtkeymapperbase.h:51
QtKeyMapperBase::AntKey_Shift_Lock
@ AntKey_Shift_Lock
Definition: qtkeymapperbase.h:52
QtKeyMapperBase::AntKey_KP_Decimal
@ AntKey_KP_Decimal
Definition: qtkeymapperbase.h:59
qtkeymapperbase.h
QtKeyMapperBase::AntKey_KP_2
@ AntKey_KP_2
Definition: qtkeymapperbase.h:75
QtKeyMapperBase::customKeyPrefix
static const int customKeyPrefix
Definition: qtkeymapperbase.h:45
QtKeyMapperBase::qtKeyToVirtKeyHash
QHash< int, int > qtKeyToVirtKeyHash
Definition: qtkeymapperbase.h:89
QtKeyMapperBase::AntKey_KP_Enter
@ AntKey_KP_Enter
Definition: qtkeymapperbase.h:72
QtKeyMapperBase::nativeKeyPrefix
static const int nativeKeyPrefix
Definition: qtkeymapperbase.h:46
QtKeyMapperBase::isModifier
virtual bool isModifier(int qkey)
Definition: qtkeymapperbase.cpp:41
QtKeyMapperBase::AntKey_KP_1
@ AntKey_KP_1
Definition: qtkeymapperbase.h:74
QtKeyMapperBase::AntKey_KP_4
@ AntKey_KP_4
Definition: qtkeymapperbase.h:77
QtKeyMapperBase::customQtKeyPrefix
static const int customQtKeyPrefix
Definition: qtkeymapperbase.h:44
QtKeyMapperBase::populateCharKeyInformation
virtual void populateCharKeyInformation()=0
QtKeyMapperBase::AntKey_KP_Up
@ AntKey_KP_Up
Definition: qtkeymapperbase.h:70
QtKeyMapperBase::_charKeyInformation::virtualkey
int virtualkey
Definition: qtkeymapperbase.h:35
QtKeyMapperBase::AntKey_KP_Prior
@ AntKey_KP_Prior
Definition: qtkeymapperbase.h:65
QtKeyMapperBase::_charKeyInformation::modifiers
Qt::KeyboardModifiers modifiers
Definition: qtkeymapperbase.h:34
QtKeyMapperBase::_charKeyInformation
Definition: qtkeymapperbase.h:32
QtKeyMapperBase::AntKey_KP_Delete
@ AntKey_KP_Delete
Definition: qtkeymapperbase.h:62