1 /***************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins 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 QQNXKEYTRANSLATOR_H
41 #define QQNXKEYTRANSLATOR_H
42 
43 #include <sys/keycodes.h>
44 
45 #if defined(QQNXEVENTTHREAD_DEBUG)
46 #include <QtCore/QDebug>
47 #endif
48 
49 QT_BEGIN_NAMESPACE
50 
qtKeyForPrivateUseQnxKey(int key)51 int qtKeyForPrivateUseQnxKey( int key )
52 {
53     switch (key) {
54     case KEYCODE_PAUSE:       return Qt::Key_Pause;
55     case KEYCODE_SCROLL_LOCK: return Qt::Key_ScrollLock;
56     case KEYCODE_PRINT:       return Qt::Key_Print;
57     case KEYCODE_SYSREQ:      return Qt::Key_SysReq;
58 //    case KEYCODE_BREAK:
59     case KEYCODE_ESCAPE:      return Qt::Key_Escape;
60     case KEYCODE_BACKSPACE:   return Qt::Key_Backspace;
61     case KEYCODE_TAB:         return Qt::Key_Tab;
62     case KEYCODE_BACK_TAB:    return Qt::Key_Backtab;
63     case KEYCODE_RETURN:      return Qt::Key_Return;
64     case KEYCODE_CAPS_LOCK:   return Qt::Key_CapsLock;
65     case KEYCODE_LEFT_SHIFT:  return Qt::Key_Shift;
66     case KEYCODE_RIGHT_SHIFT: return Qt::Key_Shift;
67     case KEYCODE_LEFT_CTRL:   return Qt::Key_Control;
68     case KEYCODE_RIGHT_CTRL:  return Qt::Key_Control;
69     case KEYCODE_LEFT_ALT:    return Qt::Key_Alt;
70     case KEYCODE_RIGHT_ALT:   return Qt::Key_Alt;
71     case KEYCODE_MENU:        return Qt::Key_Menu;
72     case KEYCODE_LEFT_HYPER:  return Qt::Key_Hyper_L;
73     case KEYCODE_RIGHT_HYPER: return Qt::Key_Hyper_R;
74     case KEYCODE_INSERT:      return Qt::Key_Insert;
75     case KEYCODE_HOME:        return Qt::Key_Home;
76     case KEYCODE_PG_UP:       return Qt::Key_PageUp;
77     case KEYCODE_DELETE:      return Qt::Key_Delete;
78     case KEYCODE_END:         return Qt::Key_End;
79     case KEYCODE_PG_DOWN:     return Qt::Key_PageDown;
80     case KEYCODE_LEFT:        return Qt::Key_Left;
81     case KEYCODE_RIGHT:       return Qt::Key_Right;
82     case KEYCODE_UP:          return Qt::Key_Up;
83     case KEYCODE_DOWN:        return Qt::Key_Down;
84     case KEYCODE_NUM_LOCK:    return Qt::Key_NumLock;
85     case KEYCODE_KP_PLUS:     return Qt::Key_Plus;
86     case KEYCODE_KP_MINUS:    return Qt::Key_Minus;
87     case KEYCODE_KP_MULTIPLY: return Qt::Key_Asterisk;
88     case KEYCODE_KP_DIVIDE:   return Qt::Key_Slash;
89     case KEYCODE_KP_ENTER:    return Qt::Key_Enter;
90     case KEYCODE_KP_HOME:     return Qt::Key_Home;
91     case KEYCODE_KP_UP:       return Qt::Key_Up;
92     case KEYCODE_KP_PG_UP:    return Qt::Key_PageUp;
93     case KEYCODE_KP_LEFT:     return Qt::Key_Left;
94     case KEYCODE_KP_FIVE:     return Qt::Key_5;
95     case KEYCODE_KP_RIGHT:    return Qt::Key_Right;
96     case KEYCODE_KP_END:      return Qt::Key_End;
97     case KEYCODE_KP_DOWN:     return Qt::Key_Down;
98     case KEYCODE_KP_PG_DOWN:  return Qt::Key_PageDown;
99     case KEYCODE_KP_INSERT:   return Qt::Key_Insert;
100     case KEYCODE_KP_DELETE:   return Qt::Key_Delete;
101     case KEYCODE_F1:          return Qt::Key_F1;
102     case KEYCODE_F2:          return Qt::Key_F2;
103     case KEYCODE_F3:          return Qt::Key_F3;
104     case KEYCODE_F4:          return Qt::Key_F4;
105     case KEYCODE_F5:          return Qt::Key_F5;
106     case KEYCODE_F6:          return Qt::Key_F6;
107     case KEYCODE_F7:          return Qt::Key_F7;
108     case KEYCODE_F8:          return Qt::Key_F8;
109     case KEYCODE_F9:          return Qt::Key_F9;
110     case KEYCODE_F10:         return Qt::Key_F10;
111     case KEYCODE_F11:         return Qt::Key_F11;
112     case KEYCODE_F12:         return Qt::Key_F12;
113 
114     // See keycodes.h for more, but these are all the basics. And printables are already included.
115 
116     default:
117 #if defined(QQNXEVENTTHREAD_DEBUG)
118         qDebug() << "QQNX: unknown key for translation:" << key;
119 #endif
120         break;
121     }
122 
123     return Qt::Key_unknown;
124 }
125 
keyStringForPrivateUseQnxKey(int key)126 QString keyStringForPrivateUseQnxKey( int key )
127 {
128     switch (key) {
129     case KEYCODE_ESCAPE:    return QStringLiteral("\x1B");
130     case KEYCODE_BACKSPACE: return QStringLiteral("\b");
131     case KEYCODE_TAB:       return QStringLiteral("\t");
132     case KEYCODE_RETURN:    return QStringLiteral("\r");
133     case KEYCODE_DELETE:    return QStringLiteral("\x7F");
134     case KEYCODE_KP_ENTER:  return QStringLiteral("\r");
135     }
136 
137     return QString();
138 }
139 
isKeypadKey(int key)140 bool isKeypadKey( int key )
141 {
142     switch (key)
143     {
144     case KEYCODE_KP_PLUS:
145     case KEYCODE_KP_MINUS:
146     case KEYCODE_KP_MULTIPLY:
147     case KEYCODE_KP_DIVIDE:
148     case KEYCODE_KP_ENTER:
149     case KEYCODE_KP_HOME:
150     case KEYCODE_KP_UP:
151     case KEYCODE_KP_PG_UP:
152     case KEYCODE_KP_LEFT:
153     case KEYCODE_KP_FIVE:
154     case KEYCODE_KP_RIGHT:
155     case KEYCODE_KP_END:
156     case KEYCODE_KP_DOWN:
157     case KEYCODE_KP_PG_DOWN:
158     case KEYCODE_KP_INSERT:
159     case KEYCODE_KP_DELETE:
160         return true;
161     default:
162         break;
163     }
164 
165     return false;
166 }
167 
168 QT_END_NAMESPACE
169 
170 #endif // QQNXKEYTRANSLATOR_H
171