qt-osg-keyboard.hh
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef GEPETTO_GUI_QT_OSG_KEYBOARD_HH__
18 # define GEPETTO_GUI_QT_OSG_KEYBOARD_HH__
19 
20 #include <QKeyEvent>
21 
22 namespace gepetto {
23  namespace gui {
26  class QtOsgKeyboard {
27  public:
29  {
30  mKeyMap[Qt::Key_Escape ] = osgGA::GUIEventAdapter::KEY_Escape;
31  mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete;
32  mKeyMap[Qt::Key_Home ] = osgGA::GUIEventAdapter::KEY_Home;
33  mKeyMap[Qt::Key_Enter ] = osgGA::GUIEventAdapter::KEY_KP_Enter;
34  mKeyMap[Qt::Key_End ] = osgGA::GUIEventAdapter::KEY_End;
35  mKeyMap[Qt::Key_Return ] = osgGA::GUIEventAdapter::KEY_Return;
36  mKeyMap[Qt::Key_PageUp ] = osgGA::GUIEventAdapter::KEY_Page_Up;
37  mKeyMap[Qt::Key_PageDown ] = osgGA::GUIEventAdapter::KEY_Page_Down;
38  mKeyMap[Qt::Key_Left ] = osgGA::GUIEventAdapter::KEY_Left;
39  mKeyMap[Qt::Key_Right ] = osgGA::GUIEventAdapter::KEY_Right;
40  mKeyMap[Qt::Key_Up ] = osgGA::GUIEventAdapter::KEY_Up;
41  mKeyMap[Qt::Key_Down ] = osgGA::GUIEventAdapter::KEY_Down;
42  mKeyMap[Qt::Key_Backspace ] = osgGA::GUIEventAdapter::KEY_BackSpace;
43  mKeyMap[Qt::Key_Tab ] = osgGA::GUIEventAdapter::KEY_Tab;
44  mKeyMap[Qt::Key_Space ] = osgGA::GUIEventAdapter::KEY_Space;
45  mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete;
46  mKeyMap[Qt::Key_Alt ] = osgGA::GUIEventAdapter::KEY_Alt_L;
47  mKeyMap[Qt::Key_Shift ] = osgGA::GUIEventAdapter::KEY_Shift_L;
48  mKeyMap[Qt::Key_Control ] = osgGA::GUIEventAdapter::KEY_Control_L;
49  mKeyMap[Qt::Key_Meta ] = osgGA::GUIEventAdapter::KEY_Meta_L;
50 
51  mKeyMap[Qt::Key_F1 ] = osgGA::GUIEventAdapter::KEY_F1;
52  mKeyMap[Qt::Key_F2 ] = osgGA::GUIEventAdapter::KEY_F2;
53  mKeyMap[Qt::Key_F3 ] = osgGA::GUIEventAdapter::KEY_F3;
54  mKeyMap[Qt::Key_F4 ] = osgGA::GUIEventAdapter::KEY_F4;
55  mKeyMap[Qt::Key_F5 ] = osgGA::GUIEventAdapter::KEY_F5;
56  mKeyMap[Qt::Key_F6 ] = osgGA::GUIEventAdapter::KEY_F6;
57  mKeyMap[Qt::Key_F7 ] = osgGA::GUIEventAdapter::KEY_F7;
58  mKeyMap[Qt::Key_F8 ] = osgGA::GUIEventAdapter::KEY_F8;
59  mKeyMap[Qt::Key_F9 ] = osgGA::GUIEventAdapter::KEY_F9;
60  mKeyMap[Qt::Key_F10 ] = osgGA::GUIEventAdapter::KEY_F10;
61  mKeyMap[Qt::Key_F11 ] = osgGA::GUIEventAdapter::KEY_F11;
62  mKeyMap[Qt::Key_F12 ] = osgGA::GUIEventAdapter::KEY_F12;
63  mKeyMap[Qt::Key_F13 ] = osgGA::GUIEventAdapter::KEY_F13;
64  mKeyMap[Qt::Key_F14 ] = osgGA::GUIEventAdapter::KEY_F14;
65  mKeyMap[Qt::Key_F15 ] = osgGA::GUIEventAdapter::KEY_F15;
66  mKeyMap[Qt::Key_F16 ] = osgGA::GUIEventAdapter::KEY_F16;
67  mKeyMap[Qt::Key_F17 ] = osgGA::GUIEventAdapter::KEY_F17;
68  mKeyMap[Qt::Key_F18 ] = osgGA::GUIEventAdapter::KEY_F18;
69  mKeyMap[Qt::Key_F19 ] = osgGA::GUIEventAdapter::KEY_F19;
70  mKeyMap[Qt::Key_F20 ] = osgGA::GUIEventAdapter::KEY_F20;
71 
72  mKeyMap[Qt::Key_hyphen ] = '-';
73  mKeyMap[Qt::Key_Equal ] = '=';
74 
75  mKeyMap[Qt::Key_division ] = osgGA::GUIEventAdapter::KEY_KP_Divide;
76  mKeyMap[Qt::Key_multiply ] = osgGA::GUIEventAdapter::KEY_KP_Multiply;
77  mKeyMap[Qt::Key_Minus ] = '-';
78  mKeyMap[Qt::Key_Plus ] = '+';
79  //mKeyMap[Qt::Key_H ] = osgGA::GUIEventAdapter::KEY_KP_Home;
80  //mKeyMap[Qt::Key_ ] = osgGA::GUIEventAdapter::KEY_KP_Up;
81  //mKeyMap[92 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Up;
82  //mKeyMap[86 ] = osgGA::GUIEventAdapter::KEY_KP_Left;
83  //mKeyMap[87 ] = osgGA::GUIEventAdapter::KEY_KP_Begin;
84  //mKeyMap[88 ] = osgGA::GUIEventAdapter::KEY_KP_Right;
85  //mKeyMap[83 ] = osgGA::GUIEventAdapter::KEY_KP_End;
86  //mKeyMap[84 ] = osgGA::GUIEventAdapter::KEY_KP_Down;
87  //mKeyMap[85 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Down;
88  mKeyMap[Qt::Key_Insert ] = osgGA::GUIEventAdapter::KEY_KP_Insert;
89  //mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_KP_Delete;
90 
91  modKeyMap[osgGA::GUIEventAdapter::MODKEY_CTRL ] = Qt::ControlModifier;
92  }
93 
95  {
96  }
97 
98  int remapKey(QKeyEvent* event)
99  {
100  KeyMap::iterator itr = mKeyMap.find((Qt::Key)event->key());
101  if (itr == mKeyMap.end())
102  {
103  return int(*(event->text().toLatin1().data()));
104  }
105  else
106  return itr->second;
107  }
108 
109  QKeyEvent* remapKey(int key)
110  {
111  if (key == 0)
112  return NULL;
113  for (KeyMap::iterator itr = mKeyMap.begin(); itr != mKeyMap.end(); ++itr) {
114  if (itr->second == key)
115  return new QKeyEvent(QEvent::KeyPress, itr->first, 0);
116  }
117  return NULL;
118  }
119 
120  QKeyEvent* remapModKey(int modMask)
121  {
122  if (modMask == 0)
123  return NULL;
124  ModKeyMap::const_iterator it = modKeyMap.find(modMask);
125  if (it != modKeyMap.end())
126  return new QKeyEvent(QEvent::KeyPress, it->second, 0);
127  return NULL;
128  }
129 
130  Qt::KeyboardModifiers getQtModKey(int modMask)
131  {
132  ModKeyMap::const_iterator it = modKeyMap.find(modMask);
133  if (it != modKeyMap.end())
134  return it->second;
135  return Qt::NoModifier;
136  }
137 
138  private:
139  typedef std::map<Qt::Key, int> KeyMap;
140  KeyMap mKeyMap;
141 
142  typedef std::map<int, Qt::KeyboardModifiers> ModKeyMap;
143  ModKeyMap modKeyMap;
144  };
145  }
146 }
147 
148 #endif /* GEPETTO_GUI_QT_OSG_KEYBOARD_HH__ */
~QtOsgKeyboard()
Definition: qt-osg-keyboard.hh:94
Definition: action-search-bar.hh:27
QKeyEvent * remapKey(int key)
Definition: qt-osg-keyboard.hh:109
QtOsgKeyboard()
Definition: qt-osg-keyboard.hh:28
Qt::KeyboardModifiers getQtModKey(int modMask)
Definition: qt-osg-keyboard.hh:130
QKeyEvent * remapModKey(int modMask)
Definition: qt-osg-keyboard.hh:120
int remapKey(QKeyEvent *event)
Definition: qt-osg-keyboard.hh:98
Definition: qt-osg-keyboard.hh:26