DYTSrouce/Source/src/viewer/KeyMapQtOsg.cpp
2024-11-22 23:11:48 +08:00

90 lines
4.6 KiB
C++

#include "viewer/KeyMapQtOsg.h"
#include <unordered_map>
#include <osgGA/GUIEventAdapter>
class KeyMapQtOsgPrivate {
public:
KeyMapQtOsgPrivate() {
m_keyMap[Qt::Key_Escape] = osgGA::GUIEventAdapter::KEY_Escape;
m_keyMap[Qt::Key_Delete] = osgGA::GUIEventAdapter::KEY_Delete;
m_keyMap[Qt::Key_Home] = osgGA::GUIEventAdapter::KEY_Home;
m_keyMap[Qt::Key_Enter] = osgGA::GUIEventAdapter::KEY_KP_Enter;
m_keyMap[Qt::Key_End] = osgGA::GUIEventAdapter::KEY_End;
m_keyMap[Qt::Key_Return] = osgGA::GUIEventAdapter::KEY_Return;
m_keyMap[Qt::Key_PageUp] = osgGA::GUIEventAdapter::KEY_Page_Up;
m_keyMap[Qt::Key_PageDown] = osgGA::GUIEventAdapter::KEY_Page_Down;
m_keyMap[Qt::Key_Left] = osgGA::GUIEventAdapter::KEY_Left;
m_keyMap[Qt::Key_Right] = osgGA::GUIEventAdapter::KEY_Right;
m_keyMap[Qt::Key_Up] = osgGA::GUIEventAdapter::KEY_Up;
m_keyMap[Qt::Key_Down] = osgGA::GUIEventAdapter::KEY_Down;
m_keyMap[Qt::Key_Backspace] = osgGA::GUIEventAdapter::KEY_BackSpace;
m_keyMap[Qt::Key_Tab] = osgGA::GUIEventAdapter::KEY_Tab;
m_keyMap[Qt::Key_Space] = osgGA::GUIEventAdapter::KEY_Space;
m_keyMap[Qt::Key_Delete] = osgGA::GUIEventAdapter::KEY_Delete;
m_keyMap[Qt::Key_Alt] = osgGA::GUIEventAdapter::KEY_Alt_L;
m_keyMap[Qt::Key_Shift] = osgGA::GUIEventAdapter::KEY_Shift_L;
m_keyMap[Qt::Key_Control] = osgGA::GUIEventAdapter::KEY_Control_L;
m_keyMap[Qt::Key_Meta] = osgGA::GUIEventAdapter::KEY_Meta_L;
m_keyMap[Qt::Key_F1] = osgGA::GUIEventAdapter::KEY_F1;
m_keyMap[Qt::Key_F2] = osgGA::GUIEventAdapter::KEY_F2;
m_keyMap[Qt::Key_F3] = osgGA::GUIEventAdapter::KEY_F3;
m_keyMap[Qt::Key_F4] = osgGA::GUIEventAdapter::KEY_F4;
m_keyMap[Qt::Key_F5] = osgGA::GUIEventAdapter::KEY_F5;
m_keyMap[Qt::Key_F6] = osgGA::GUIEventAdapter::KEY_F6;
m_keyMap[Qt::Key_F7] = osgGA::GUIEventAdapter::KEY_F7;
m_keyMap[Qt::Key_F8] = osgGA::GUIEventAdapter::KEY_F8;
m_keyMap[Qt::Key_F9] = osgGA::GUIEventAdapter::KEY_F9;
m_keyMap[Qt::Key_F10] = osgGA::GUIEventAdapter::KEY_F10;
m_keyMap[Qt::Key_F11] = osgGA::GUIEventAdapter::KEY_F11;
m_keyMap[Qt::Key_F12] = osgGA::GUIEventAdapter::KEY_F12;
m_keyMap[Qt::Key_F13] = osgGA::GUIEventAdapter::KEY_F13;
m_keyMap[Qt::Key_F14] = osgGA::GUIEventAdapter::KEY_F14;
m_keyMap[Qt::Key_F15] = osgGA::GUIEventAdapter::KEY_F15;
m_keyMap[Qt::Key_F16] = osgGA::GUIEventAdapter::KEY_F16;
m_keyMap[Qt::Key_F17] = osgGA::GUIEventAdapter::KEY_F17;
m_keyMap[Qt::Key_F18] = osgGA::GUIEventAdapter::KEY_F18;
m_keyMap[Qt::Key_F19] = osgGA::GUIEventAdapter::KEY_F19;
m_keyMap[Qt::Key_F20] = osgGA::GUIEventAdapter::KEY_F20;
m_keyMap[Qt::Key_hyphen] = '-';
m_keyMap[Qt::Key_Equal] = '=';
m_keyMap[Qt::Key_division] = osgGA::GUIEventAdapter::KEY_KP_Divide;
m_keyMap[Qt::Key_multiply] = osgGA::GUIEventAdapter::KEY_KP_Multiply;
m_keyMap[Qt::Key_Minus] = '-';
m_keyMap[Qt::Key_Plus] = '+';
//m_keyMap[Qt::Key_H ] = osgGA::GUIEventAdapter::KEY_KP_Home;
//m_keyMap[Qt::Key_ ] = osgGA::GUIEventAdapter::KEY_KP_Up;
//m_keyMap[92 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Up;
//m_keyMap[86 ] = osgGA::GUIEventAdapter::KEY_KP_Left;
//m_keyMap[87 ] = osgGA::GUIEventAdapter::KEY_KP_Begin;
//m_keyMap[88 ] = osgGA::GUIEventAdapter::KEY_KP_Right;
//m_keyMap[83 ] = osgGA::GUIEventAdapter::KEY_KP_End;
//m_keyMap[84 ] = osgGA::GUIEventAdapter::KEY_KP_Down;
//m_keyMap[85 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Down;
m_keyMap[Qt::Key_Insert] = osgGA::GUIEventAdapter::KEY_KP_Insert;
m_keyMap[Qt::Key_Delete] = osgGA::GUIEventAdapter::KEY_KP_Delete;
}
using KeyMap = std::unordered_map<unsigned int, int>;
KeyMap m_keyMap;
};
static KeyMapQtOsgPrivate skeyMapQtToOsg_;
int KeyMapQtOsg::RemapKey(int key) {
auto itor = skeyMapQtToOsg_.m_keyMap.find(
static_cast<unsigned int>(key));
if (skeyMapQtToOsg_.m_keyMap.end() == itor) {
return key;
}
return itor->second;
}
int KeyMapQtOsg::RemapKey(QKeyEvent *event) {
auto itor = skeyMapQtToOsg_.m_keyMap.find(
static_cast<unsigned int>(event->key()));
if (skeyMapQtToOsg_.m_keyMap.end() == itor) {
return int(*(event->text().toLatin1().data()));
}
return itor->second;
}