GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/gui/qt-osg-keyboard.hh Lines: 0 54 0.0 %
Date: 2023-03-14 11:04:37 Branches: 0 100 0.0 %

Line Branch Exec Source
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
#include <osgGA/GUIEventAdapter>
22
23
namespace gepetto {
24
namespace gui {
25
/// This class is a modified version of class QtKeyboardMap of
26
/// OpenSceneGraph version 3.4.0 (file src/osgQt/GraphicsWindowQt.cpp)
27
class QtOsgKeyboard {
28
 public:
29
  QtOsgKeyboard() {
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_                    ] =
81
    // osgGA::GUIEventAdapter::KEY_KP_Up; mKeyMap[92                    ] =
82
    // osgGA::GUIEventAdapter::KEY_KP_Page_Up; mKeyMap[86                    ] =
83
    // osgGA::GUIEventAdapter::KEY_KP_Left; mKeyMap[87                    ] =
84
    // osgGA::GUIEventAdapter::KEY_KP_Begin; mKeyMap[88                    ] =
85
    // osgGA::GUIEventAdapter::KEY_KP_Right; mKeyMap[83                    ] =
86
    // osgGA::GUIEventAdapter::KEY_KP_End; mKeyMap[84                    ] =
87
    // osgGA::GUIEventAdapter::KEY_KP_Down; mKeyMap[85                    ] =
88
    // osgGA::GUIEventAdapter::KEY_KP_Page_Down;
89
    mKeyMap[Qt::Key_Insert] = osgGA::GUIEventAdapter::KEY_KP_Insert;
90
    // mKeyMap[Qt::Key_Delete        ] = osgGA::GUIEventAdapter::KEY_KP_Delete;
91
92
    modKeyMap[osgGA::GUIEventAdapter::MODKEY_CTRL] = Qt::ControlModifier;
93
  }
94
95
  ~QtOsgKeyboard() {}
96
97
  int remapKey(QKeyEvent* event) {
98
    KeyMap::iterator itr = mKeyMap.find((Qt::Key)event->key());
99
    if (itr == mKeyMap.end()) {
100
      return int(*(event->text().toLatin1().data()));
101
    } else
102
      return itr->second;
103
  }
104
105
  QKeyEvent* remapKey(int key) {
106
    if (key == 0) return NULL;
107
    for (KeyMap::iterator itr = mKeyMap.begin(); itr != mKeyMap.end(); ++itr) {
108
      if (itr->second == key)
109
        return new QKeyEvent(QEvent::KeyPress, itr->first, 0);
110
    }
111
    return NULL;
112
  }
113
114
  QKeyEvent* remapModKey(int modMask) {
115
    if (modMask == 0) return NULL;
116
    ModKeyMap::const_iterator it = modKeyMap.find(modMask);
117
    if (it != modKeyMap.end())
118
      return new QKeyEvent(QEvent::KeyPress, it->second, 0);
119
    return NULL;
120
  }
121
122
  Qt::KeyboardModifiers getQtModKey(int modMask) {
123
    ModKeyMap::const_iterator it = modKeyMap.find(modMask);
124
    if (it != modKeyMap.end()) return it->second;
125
    return Qt::NoModifier;
126
  }
127
128
 private:
129
  typedef std::map<Qt::Key, int> KeyMap;
130
  KeyMap mKeyMap;
131
132
  typedef std::map<int, Qt::KeyboardModifiers> ModKeyMap;
133
  ModKeyMap modKeyMap;
134
};
135
}  // namespace gui
136
}  // namespace gepetto
137
138
#endif /* GEPETTO_GUI_QT_OSG_KEYBOARD_HH__ */