Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Qt5Widget.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #include <vlQt5/Qt5Widget.hpp>
33 #include <vlCore/Log.hpp>
34 
35 using namespace vl;
36 using namespace vlQt5;
37 
38 void Qt5Widget::translateKeyEvent(QKeyEvent* ev, unsigned short& unicode_out, EKey& key_out)
39 {
40  // translate non unicode characters
41  key_out = Key_None;
42  unicode_out = 0;
43 
44  switch(ev->key())
45  {
46  case Qt::Key_Clear: key_out = Key_Clear; break;
47  case Qt::Key_Control: key_out = Key_Ctrl; break;
48  // case Qt::Key_LCONTROL: key_out = Key_LeftCtrl; break;
49  // case Qt::Key_RCONTROL: key_out = Key_RightCtrl; break;
50  case Qt::Key_Alt: key_out = Key_Alt; break;
51  // case Qt::Key_LMENU: key_out = Key_LeftAlt; break;
52  // case Qt::Key_RMENU: key_out = Key_RightAlt; break;
53  case Qt::Key_Shift: key_out = Key_Shift; break;
54  // case Qt::Key_LSHIFT: key_out = Key_LeftShift; break;
55  // case Qt::Key_RSHIFT: key_out = Key_RightShift; break;
56  case Qt::Key_Insert: key_out = Key_Insert; break;
57  case Qt::Key_Delete: key_out = Key_Delete; break;
58  case Qt::Key_Home: key_out = Key_Home; break;
59  case Qt::Key_End: key_out = Key_End; break;
60  case Qt::Key_Print: key_out = Key_Print; break;
61  case Qt::Key_Pause: key_out = Key_Pause; break;
62  case Qt::Key_PageUp: key_out = Key_PageUp; break;
63  case Qt::Key_PageDown: key_out = Key_PageDown; break;
64  case Qt::Key_Left: key_out = Key_Left; break;
65  case Qt::Key_Right: key_out = Key_Right; break;
66  case Qt::Key_Up: key_out = Key_Up; break;
67  case Qt::Key_Down: key_out = Key_Down; break;
68  case Qt::Key_F1: key_out = Key_F1; break;
69  case Qt::Key_F2: key_out = Key_F2; break;
70  case Qt::Key_F3: key_out = Key_F3; break;
71  case Qt::Key_F4: key_out = Key_F4; break;
72  case Qt::Key_F5: key_out = Key_F5; break;
73  case Qt::Key_F6: key_out = Key_F6; break;
74  case Qt::Key_F7: key_out = Key_F7; break;
75  case Qt::Key_F8: key_out = Key_F8; break;
76  case Qt::Key_F9: key_out = Key_F9; break;
77  case Qt::Key_F10: key_out = Key_F10; break;
78  case Qt::Key_F11: key_out = Key_F11; break;
79  case Qt::Key_F12: key_out = Key_F12; break;
80 
81  case Qt::Key_0: key_out = Key_0; break;
82  case Qt::Key_1: key_out = Key_1; break;
83  case Qt::Key_2: key_out = Key_2; break;
84  case Qt::Key_3: key_out = Key_3; break;
85  case Qt::Key_4: key_out = Key_4; break;
86  case Qt::Key_5: key_out = Key_5; break;
87  case Qt::Key_6: key_out = Key_6; break;
88  case Qt::Key_7: key_out = Key_7; break;
89  case Qt::Key_8: key_out = Key_8; break;
90  case Qt::Key_9: key_out = Key_9; break;
91 
92  case Qt::Key_A: key_out = Key_A; break;
93  case Qt::Key_B: key_out = Key_B; break;
94  case Qt::Key_C: key_out = Key_C; break;
95  case Qt::Key_D: key_out = Key_D; break;
96  case Qt::Key_E: key_out = Key_E; break;
97  case Qt::Key_F: key_out = Key_F; break;
98  case Qt::Key_G: key_out = Key_G; break;
99  case Qt::Key_H: key_out = Key_H; break;
100  case Qt::Key_I: key_out = Key_I; break;
101  case Qt::Key_J: key_out = Key_J; break;
102  case Qt::Key_K: key_out = Key_K; break;
103  case Qt::Key_L: key_out = Key_L; break;
104  case Qt::Key_M: key_out = Key_M; break;
105  case Qt::Key_N: key_out = Key_N; break;
106  case Qt::Key_O: key_out = Key_O; break;
107  case Qt::Key_P: key_out = Key_P; break;
108  case Qt::Key_Q: key_out = Key_Q; break;
109  case Qt::Key_R: key_out = Key_R; break;
110  case Qt::Key_S: key_out = Key_S; break;
111  case Qt::Key_T: key_out = Key_T; break;
112  case Qt::Key_U: key_out = Key_U; break;
113  case Qt::Key_V: key_out = Key_V; break;
114  case Qt::Key_W: key_out = Key_W; break;
115  case Qt::Key_X: key_out = Key_X; break;
116  case Qt::Key_Y: key_out = Key_Y; break;
117  case Qt::Key_Z: key_out = Key_Z; break;
118  }
119 
120  // fill unicode
121  QString ustring = ev->text();
122  if ( ustring.length() == 1 )
123  {
124  unicode_out = ustring[0].unicode();
125 
126  // fill key
127  switch(unicode_out)
128  {
129  case L'0': key_out = Key_0; break;
130  case L'1': key_out = Key_1; break;
131  case L'2': key_out = Key_2; break;
132  case L'3': key_out = Key_3; break;
133  case L'4': key_out = Key_4; break;
134  case L'5': key_out = Key_5; break;
135  case L'6': key_out = Key_6; break;
136  case L'7': key_out = Key_7; break;
137  case L'8': key_out = Key_8; break;
138  case L'9': key_out = Key_9; break;
139 
140  case L'A': key_out = Key_A; break;
141  case L'B': key_out = Key_B; break;
142  case L'C': key_out = Key_C; break;
143  case L'D': key_out = Key_D; break;
144  case L'E': key_out = Key_E; break;
145  case L'F': key_out = Key_F; break;
146  case L'G': key_out = Key_G; break;
147  case L'H': key_out = Key_H; break;
148  case L'I': key_out = Key_I; break;
149  case L'J': key_out = Key_J; break;
150  case L'K': key_out = Key_K; break;
151  case L'L': key_out = Key_L; break;
152  case L'M': key_out = Key_M; break;
153  case L'N': key_out = Key_N; break;
154  case L'O': key_out = Key_O; break;
155  case L'P': key_out = Key_P; break;
156  case L'Q': key_out = Key_Q; break;
157  case L'R': key_out = Key_R; break;
158  case L'S': key_out = Key_S; break;
159  case L'T': key_out = Key_T; break;
160  case L'U': key_out = Key_U; break;
161  case L'V': key_out = Key_V; break;
162  case L'W': key_out = Key_W; break;
163  case L'X': key_out = Key_X; break;
164  case L'Y': key_out = Key_Y; break;
165  case L'Z': key_out = Key_Z; break;
166 
167  case L'a': key_out = Key_A; break;
168  case L'b': key_out = Key_B; break;
169  case L'c': key_out = Key_C; break;
170  case L'd': key_out = Key_D; break;
171  case L'e': key_out = Key_E; break;
172  case L'f': key_out = Key_F; break;
173  case L'g': key_out = Key_G; break;
174  case L'h': key_out = Key_H; break;
175  case L'i': key_out = Key_I; break;
176  case L'j': key_out = Key_J; break;
177  case L'k': key_out = Key_K; break;
178  case L'l': key_out = Key_L; break;
179  case L'm': key_out = Key_M; break;
180  case L'n': key_out = Key_N; break;
181  case L'o': key_out = Key_O; break;
182  case L'p': key_out = Key_P; break;
183  case L'q': key_out = Key_Q; break;
184  case L'r': key_out = Key_R; break;
185  case L's': key_out = Key_S; break;
186  case L't': key_out = Key_T; break;
187  case L'u': key_out = Key_U; break;
188  case L'v': key_out = Key_V; break;
189  case L'w': key_out = Key_W; break;
190  case L'x': key_out = Key_X; break;
191  case L'y': key_out = Key_Y; break;
192  case L'z': key_out = Key_Z; break;
193 
194  case 13: key_out = Key_Return; break;
195  case 8: key_out = Key_BackSpace; break;
196  case 9: key_out = Key_Tab; break;
197  case L' ': key_out = Key_Space; break;
198 
199  case 27: key_out = Key_Escape; break;
200  case L'!': key_out = Key_Exclam; break;
201  case L'"': key_out = Key_QuoteDbl; break;
202  case L'#': key_out = Key_Hash; break;
203  case L'$': key_out = Key_Dollar; break;
204  case L'&': key_out = Key_Ampersand; break;
205  case L'\'': key_out = Key_Quote; break;
206  case L'(': key_out = Key_LeftParen; break;
207  case L')': key_out = Key_RightParen; break;
208  case L'*': key_out = Key_Asterisk; break;
209  case L'+': key_out = Key_Plus; break;
210  case L',': key_out = Key_Comma; break;
211  case L'-': key_out = Key_Minus; break;
212  case L'.': key_out = Key_Period; break;
213  case L'\\': key_out = Key_BackSlash; break;
214  case L':': key_out = Key_Colon; break;
215  case L';': key_out = Key_Semicolon; break;
216  case L'<': key_out = Key_Less; break;
217  case L'=': key_out = Key_Equal; break;
218  case L'>': key_out = Key_Greater; break;
219  case L'?': key_out = Key_Question; break;
220  case L'@': key_out = Key_At; break;
221  case L'[': key_out = Key_LeftBracket; break;
222  case L'/': key_out = Key_Slash; break;
223  case L']': key_out = Key_RightBracket; break;
224  case L'|': key_out = Key_Caret; break;
225  case L'_': key_out = Key_Underscore; break;
226  case L'`': key_out = Key_QuoteLeft; break;
227  }
228  }
229 }
230 //-----------------------------------------------------------------------------
Visualization Library main namespace.
VLEGL_EXPORT void translateKeyEvent(WPARAM wParam, LPARAM lParam, unsigned short &unicode_out, vl::EKey &key_out)
Definition: EGLWindow.cpp:584
The Qt5 bindings namespace.