1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "hbautotest.h" |
|
19 #include <hbmainwindow.h> |
|
20 #include <hbwidget.h> |
|
21 |
|
22 |
|
23 const qreal STEP = 4; //How many pixels to drag before sending an event |
|
24 |
|
25 //Init static members |
|
26 bool HbAutoTest::pointerPressed = false; |
|
27 QPointF HbAutoTest::pressPoint = QPointF(); |
|
28 |
|
29 void HbAutoTest::mouseMove (HbAutoTestMainWindow *window, HbWidget *widget, QPointF pos, int delay) |
|
30 { |
|
31 if (delay!=-1) { |
|
32 QTest::qWait(delay); |
|
33 } |
|
34 QPointF targetPoint=QPointF(); |
|
35 if (pos==QPointF()) { |
|
36 targetPoint = middlePointOfWidget(widget); |
|
37 } else { |
|
38 targetPoint = widget->mapToScene(pos); |
|
39 } |
|
40 if (pointerPressed) { |
|
41 //Now we should drag an item |
|
42 drag(window, targetPoint); |
|
43 HbAutoTestMouseEvent me ( |
|
44 QEvent::MouseMove, |
|
45 targetPoint.toPoint(), |
|
46 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
47 Qt::NoButton, |
|
48 Qt::NoButton, |
|
49 Qt::NoModifier); |
|
50 QSpontaneKeyEvent::setSpontaneous(&me); |
|
51 qApp->notify((window->viewport()), &me); |
|
52 QCoreApplication::sendPostedEvents(); |
|
53 QTest::qWait(1); |
|
54 } else { |
|
55 HbAutoTestMouseEvent me ( |
|
56 QEvent::MouseMove, |
|
57 targetPoint.toPoint(), |
|
58 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
59 Qt::NoButton, |
|
60 Qt::NoButton, |
|
61 Qt::NoModifier); |
|
62 QSpontaneKeyEvent::setSpontaneous(&me); |
|
63 qApp->notify((window->viewport()), &me); |
|
64 QCoreApplication::sendPostedEvents(); |
|
65 QTest::qWait(1); |
|
66 |
|
67 } |
|
68 QTest::qWait(1); |
|
69 QTest::qWait(1); |
|
70 } |
|
71 |
|
72 void HbAutoTest::mousePress (HbAutoTestMainWindow *window, HbWidget *widget, QPointF pos, int delay) |
|
73 { |
|
74 if (delay!=-1) { |
|
75 QTest::qWait(delay); |
|
76 } |
|
77 pointerPressed=true; |
|
78 QPointF targetPoint=QPointF(); |
|
79 if (pos==QPointF()) { |
|
80 targetPoint = middlePointOfWidget(widget); |
|
81 } else { |
|
82 targetPoint = widget->mapToScene(pos); |
|
83 } |
|
84 QCursor::setPos(window->mapToGlobal(targetPoint.toPoint())); |
|
85 |
|
86 pressPoint=targetPoint; |
|
87 |
|
88 HbAutoTestMouseEvent me ( |
|
89 QEvent::MouseButtonPress, |
|
90 targetPoint.toPoint(), |
|
91 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
92 Qt::LeftButton, |
|
93 Qt::LeftButton, |
|
94 Qt::NoModifier); |
|
95 |
|
96 QSpontaneKeyEvent::setSpontaneous(&me); |
|
97 qApp->notify((window->viewport()), &me); |
|
98 QCoreApplication::sendPostedEvents(); |
|
99 QCoreApplication::sendPostedEvents(); |
|
100 QTest::qWait(1); |
|
101 } |
|
102 |
|
103 void HbAutoTest::mouseRelease (HbAutoTestMainWindow *window, HbWidget *widget, QPointF pos, int delay) |
|
104 { |
|
105 if (delay!=-1) { |
|
106 QTest::qWait(delay); |
|
107 } |
|
108 pointerPressed=false; |
|
109 QPointF targetPoint=QPointF(); |
|
110 if (pos==QPointF()) { |
|
111 targetPoint = middlePointOfWidget(widget); |
|
112 } else { |
|
113 targetPoint = widget->mapToScene(pos); |
|
114 } |
|
115 QCursor::setPos(window->mapToGlobal(targetPoint.toPoint())); |
|
116 pressPoint=QPointF(); |
|
117 HbAutoTestMouseEvent me ( |
|
118 QEvent::MouseButtonRelease, |
|
119 targetPoint.toPoint(), |
|
120 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
121 Qt::LeftButton, |
|
122 Qt::NoButton, |
|
123 Qt::NoModifier); |
|
124 |
|
125 QSpontaneKeyEvent::setSpontaneous(&me); |
|
126 qApp->notify((window->viewport()), &me); |
|
127 QCoreApplication::sendPostedEvents(); |
|
128 |
|
129 QTest::qWait(1); |
|
130 QTest::qWait(1); |
|
131 } |
|
132 |
|
133 void HbAutoTest::mouseClick (HbAutoTestMainWindow *window, const HbWidget *widget, QPointF pos, int delay) |
|
134 { |
|
135 if (delay!=-1) { |
|
136 QTest::qWait(delay); |
|
137 } |
|
138 QPointF targetPoint=QPointF(); |
|
139 if (pos==QPointF()) { |
|
140 targetPoint = middlePointOfWidget(widget); |
|
141 } else { |
|
142 targetPoint = widget->mapToScene(pos); |
|
143 } |
|
144 |
|
145 QCursor::setPos(window->mapToGlobal(targetPoint.toPoint())); |
|
146 |
|
147 HbAutoTestMouseEvent me ( |
|
148 QEvent::MouseButtonPress, |
|
149 targetPoint.toPoint(), |
|
150 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
151 Qt::LeftButton, |
|
152 Qt::LeftButton, |
|
153 Qt::NoModifier); |
|
154 QSpontaneKeyEvent::setSpontaneous(&me); |
|
155 qApp->notify((window->viewport()), &me); |
|
156 QCoreApplication::sendPostedEvents(); |
|
157 //QTime currentTime = QTime::currentTime(); |
|
158 //qDebug() << currentTime.toString("hh:mm:ss.zzz") << ": Left button down"; |
|
159 QTest::qWait(1); |
|
160 |
|
161 if (delay!=-1) { |
|
162 QTest::qWait(delay); |
|
163 } |
|
164 HbAutoTestMouseEvent me2 ( |
|
165 QEvent::MouseButtonRelease, |
|
166 targetPoint.toPoint(), |
|
167 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
168 Qt::LeftButton, |
|
169 Qt::NoButton, |
|
170 Qt::NoModifier); |
|
171 |
|
172 QSpontaneKeyEvent::setSpontaneous(&me2); |
|
173 qApp->notify((window->viewport()), &me2); |
|
174 QCoreApplication::sendPostedEvents(); |
|
175 //currentTime = QTime::currentTime(); |
|
176 //qDebug() << currentTime.toString("hh:mm:ss.zzz") << ": Left button up"; |
|
177 |
|
178 QTest::qWait(1); |
|
179 QTest::qWait(1); |
|
180 } |
|
181 |
|
182 QPointF HbAutoTest::middlePointOfWidget( const HbWidget* widget) |
|
183 { |
|
184 QRectF widgetRect = widget->rect(); |
|
185 QRectF widgetSceneRect = widget->mapRectToScene(widgetRect); |
|
186 qreal middleX = ((widgetSceneRect.right() - widgetSceneRect.left())/2)+widgetSceneRect.left(); |
|
187 qreal middleY = ((widgetSceneRect.bottom() - widgetSceneRect.top())/2)+widgetSceneRect.top(); |
|
188 return QPointF(middleX,middleY); |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 void HbAutoTest::drag(HbAutoTestMainWindow *window, QPointF targetPoint) |
|
194 { |
|
195 qreal tempX = targetPoint.x() - pressPoint.x(); |
|
196 qreal tempY = targetPoint.y() - pressPoint.y(); |
|
197 qreal totalTrip = sqrt ((tempX * tempX) + (tempY * tempY)); |
|
198 |
|
199 int numberOfSteps = qRound(totalTrip / STEP); |
|
200 HbAutoTestMouseEvent me ( |
|
201 QEvent::MouseMove, |
|
202 targetPoint.toPoint(), |
|
203 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
204 Qt::NoButton , |
|
205 Qt::LeftButton, |
|
206 Qt::NoModifier); |
|
207 |
|
208 QPointF nextPanPoint=pressPoint; |
|
209 for (int i=1; i<numberOfSteps; i++) { //On purpose not =< |
|
210 |
|
211 nextPanPoint.setY (pressPoint.y()+((i / (qreal)numberOfSteps) * tempY)); |
|
212 nextPanPoint.setX (pressPoint.x()+((i / (qreal)numberOfSteps) * tempX)); |
|
213 |
|
214 QCursor::setPos(window->mapToGlobal(nextPanPoint.toPoint())); |
|
215 |
|
216 me = HbAutoTestMouseEvent (QEvent::MouseMove, |
|
217 nextPanPoint.toPoint(), |
|
218 window->viewport()->mapToGlobal(nextPanPoint.toPoint()), |
|
219 Qt::NoButton, |
|
220 Qt::LeftButton, |
|
221 Qt::NoModifier); |
|
222 |
|
223 QSpontaneKeyEvent::setSpontaneous(&me); |
|
224 qApp->notify((window->viewport()), &me); |
|
225 QCoreApplication::sendPostedEvents(); |
|
226 } |
|
227 |
|
228 QCursor::setPos(window->mapToGlobal(targetPoint.toPoint())); |
|
229 |
|
230 //One more (or the only one) step to the target |
|
231 me = HbAutoTestMouseEvent (QEvent::MouseMove, |
|
232 targetPoint.toPoint(), |
|
233 window->viewport()->mapToGlobal(targetPoint.toPoint()), |
|
234 Qt::NoButton, |
|
235 Qt::LeftButton, |
|
236 Qt::NoModifier); |
|
237 QSpontaneKeyEvent::setSpontaneous(&me); |
|
238 qApp->notify((window->viewport()), &me); |
|
239 QCoreApplication::sendPostedEvents(); |
|
240 } |
|
241 |
|
242 |
|
243 void HbAutoTest::simulateEvent(QWidget *widget, bool press, int code, |
|
244 Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay) |
|
245 { |
|
246 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
247 extern int Q_TESTLIB_EXPORT defaultKeyDelay(); |
|
248 |
|
249 if (delay == -1 || delay < 10) // defaultKeyDelay()) |
|
250 delay = 10; //defaultKeyDelay(); |
|
251 if(delay > 0) |
|
252 QTest::qWait(delay); |
|
253 // Q_UNUSED(delay); |
|
254 // QTest::qWait(10); //TODO: Remove this and reveal above out-commented code |
|
255 |
|
256 HbAutoTestKeyEvent a(press ? QEvent::KeyPress : QEvent::KeyRelease, code, modifier, text, repeat); |
|
257 QSpontaneKeyEvent::setSpontaneous(&a); |
|
258 if (!qApp->notify(widget, &a)) |
|
259 QTest::qWarn("Keyboard event not accepted by receiving widget"); |
|
260 } |
|
261 |
|
262 void HbAutoTest::sendKeyEvent(QTest::KeyAction action, QWidget *widget, Qt::Key code, |
|
263 QString text, Qt::KeyboardModifiers modifier, int delay) |
|
264 { |
|
265 QTEST_ASSERT(qApp); |
|
266 |
|
267 if (!widget) |
|
268 widget = QWidget::keyboardGrabber(); |
|
269 if (!widget) { |
|
270 if (QWidget *apw = QApplication::activePopupWidget()) |
|
271 widget = apw->focusWidget() ? apw->focusWidget() : apw; |
|
272 else |
|
273 widget = QApplication::focusWidget(); |
|
274 } |
|
275 if (!widget) |
|
276 widget = QApplication::activeWindow(); |
|
277 |
|
278 QTEST_ASSERT(widget); |
|
279 |
|
280 if (action == QTest::Click) { |
|
281 QPointer<QWidget> ptr(widget); |
|
282 sendKeyEvent(QTest::Press, widget, code, text, modifier, delay); |
|
283 if (!ptr) { |
|
284 // if we send key-events to embedded widgets, they might be destroyed |
|
285 // when the user presses Return |
|
286 return; |
|
287 } |
|
288 sendKeyEvent(QTest::Release, widget, code, text, modifier, delay); |
|
289 return; |
|
290 } |
|
291 |
|
292 bool repeat = false; |
|
293 |
|
294 if (action == QTest::Press) { |
|
295 if (modifier & Qt::ShiftModifier) |
|
296 simulateEvent(widget, true, Qt::Key_Shift, 0, QString(), false, delay); |
|
297 |
|
298 if (modifier & Qt::ControlModifier) |
|
299 simulateEvent(widget, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay); |
|
300 |
|
301 if (modifier & Qt::AltModifier) |
|
302 simulateEvent(widget, true, Qt::Key_Alt, |
|
303 modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); |
|
304 if (modifier & Qt::MetaModifier) |
|
305 simulateEvent(widget, true, Qt::Key_Meta, modifier & (Qt::ShiftModifier |
|
306 | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); |
|
307 simulateEvent(widget, true, code, modifier, text, repeat, delay); |
|
308 } else if (action == QTest::Release) { |
|
309 simulateEvent(widget, false, code, modifier, text, repeat, delay); |
|
310 |
|
311 if (modifier & Qt::MetaModifier) |
|
312 simulateEvent(widget, false, Qt::Key_Meta, modifier, QString(), false, delay); |
|
313 if (modifier & Qt::AltModifier) |
|
314 simulateEvent(widget, false, Qt::Key_Alt, modifier & |
|
315 (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); |
|
316 |
|
317 if (modifier & Qt::ControlModifier) |
|
318 simulateEvent(widget, false, Qt::Key_Control, |
|
319 modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); |
|
320 |
|
321 if (modifier & Qt::ShiftModifier) |
|
322 simulateEvent(widget, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay); |
|
323 } |
|
324 } |
|
325 |
|
326 void HbAutoTest::sendKeyEvent(QTest::KeyAction action, QWidget *widget, Qt::Key code, |
|
327 char ascii, Qt::KeyboardModifiers modifier, int delay) |
|
328 { |
|
329 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
330 QString text; |
|
331 if (ascii) |
|
332 text = QString(QChar::fromLatin1(ascii)); |
|
333 sendKeyEvent(action, widget, code, text, modifier, delay); |
|
334 } |
|
335 |
|
336 void HbAutoTest::keyEvent(QTest::KeyAction action, QWidget *widget, char ascii, |
|
337 Qt::KeyboardModifiers modifier, int delay) |
|
338 { |
|
339 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
340 sendKeyEvent(action, widget, asciiToKey(ascii), ascii, modifier, delay); |
|
341 } |
|
342 |
|
343 void HbAutoTest::keyEvent(QTest::KeyAction action, QWidget *widget, Qt::Key key, |
|
344 Qt::KeyboardModifiers modifier, int delay) |
|
345 { |
|
346 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
347 sendKeyEvent(action, widget, key, keyToAscii(key), modifier, delay); |
|
348 } |
|
349 |
|
350 void HbAutoTest::keyClicks(QWidget *widget, const QString &sequence, |
|
351 Qt::KeyboardModifiers modifier, int delay) |
|
352 { |
|
353 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
354 for (int i=0; i < sequence.length(); i++) |
|
355 keyEvent(QTest::Click, widget, sequence.at(i).toLatin1(), modifier, delay); |
|
356 } |
|
357 |
|
358 void HbAutoTest::keyPress(QWidget *widget, char key, Qt::KeyboardModifiers modifier, int delay) |
|
359 { |
|
360 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
361 keyEvent(QTest::Press, widget, key, modifier, delay); |
|
362 } |
|
363 |
|
364 void HbAutoTest::keyRelease(QWidget *widget, char key, Qt::KeyboardModifiers modifier, int delay) |
|
365 { |
|
366 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
367 keyEvent(QTest::Release, widget, key, modifier, delay); |
|
368 } |
|
369 |
|
370 void HbAutoTest::keyClick(QWidget *widget, char key, Qt::KeyboardModifiers modifier, int delay) |
|
371 { |
|
372 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
373 keyEvent(QTest::Click, widget, key, modifier, delay); |
|
374 } |
|
375 |
|
376 void HbAutoTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier, int delay) |
|
377 { |
|
378 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
379 keyEvent(QTest::Press, widget, key, modifier, delay); |
|
380 } |
|
381 |
|
382 void HbAutoTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier, int delay) |
|
383 { |
|
384 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
385 keyEvent(QTest::Release, widget, key, modifier, delay); } |
|
386 |
|
387 void HbAutoTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier, int delay) |
|
388 { |
|
389 Q_ASSERT_X(dynamic_cast<HbAutoTestMainWindow *>(( widget) ) != 0, "HbAutoTest", "Always use with HbAutoTestMainWindow"); |
|
390 keyEvent(QTest::Click, widget, key, modifier, delay); |
|
391 } |
|
392 |
|
393 Qt::Key HbAutoTest::asciiToKey(char ascii) |
|
394 { |
|
395 switch ((unsigned char)ascii) { |
|
396 case 0x08: return Qt::Key_Backspace; |
|
397 case 0x09: return Qt::Key_Tab; |
|
398 case 0x0b: return Qt::Key_Backtab; |
|
399 case 0x0d: return Qt::Key_Return; |
|
400 case 0x1b: return Qt::Key_Escape; |
|
401 case 0x20: return Qt::Key_Space; |
|
402 case 0x21: return Qt::Key_Exclam; |
|
403 case 0x22: return Qt::Key_QuoteDbl; |
|
404 case 0x23: return Qt::Key_NumberSign; |
|
405 case 0x24: return Qt::Key_Dollar; |
|
406 case 0x25: return Qt::Key_Percent; |
|
407 case 0x26: return Qt::Key_Ampersand; |
|
408 case 0x27: return Qt::Key_Apostrophe; |
|
409 case 0x28: return Qt::Key_ParenLeft; |
|
410 case 0x29: return Qt::Key_ParenRight; |
|
411 case 0x2a: return Qt::Key_Asterisk; |
|
412 case 0x2b: return Qt::Key_Plus; |
|
413 case 0x2c: return Qt::Key_Comma; |
|
414 case 0x2d: return Qt::Key_Minus; |
|
415 case 0x2e: return Qt::Key_Period; |
|
416 case 0x2f: return Qt::Key_Slash; |
|
417 case 0x30: return Qt::Key_0; |
|
418 case 0x31: return Qt::Key_1; |
|
419 case 0x32: return Qt::Key_2; |
|
420 case 0x33: return Qt::Key_3; |
|
421 case 0x34: return Qt::Key_4; |
|
422 case 0x35: return Qt::Key_5; |
|
423 case 0x36: return Qt::Key_6; |
|
424 case 0x37: return Qt::Key_7; |
|
425 case 0x38: return Qt::Key_8; |
|
426 case 0x39: return Qt::Key_9; |
|
427 case 0x3a: return Qt::Key_Colon; |
|
428 case 0x3b: return Qt::Key_Semicolon; |
|
429 case 0x3c: return Qt::Key_Less; |
|
430 case 0x3d: return Qt::Key_Equal; |
|
431 case 0x3e: return Qt::Key_Greater; |
|
432 case 0x3f: return Qt::Key_Question; |
|
433 case 0x40: return Qt::Key_At; |
|
434 case 0x41: return Qt::Key_A; |
|
435 case 0x42: return Qt::Key_B; |
|
436 case 0x43: return Qt::Key_C; |
|
437 case 0x44: return Qt::Key_D; |
|
438 case 0x45: return Qt::Key_E; |
|
439 case 0x46: return Qt::Key_F; |
|
440 case 0x47: return Qt::Key_G; |
|
441 case 0x48: return Qt::Key_H; |
|
442 case 0x49: return Qt::Key_I; |
|
443 case 0x4a: return Qt::Key_J; |
|
444 case 0x4b: return Qt::Key_K; |
|
445 case 0x4c: return Qt::Key_L; |
|
446 case 0x4d: return Qt::Key_M; |
|
447 case 0x4e: return Qt::Key_N; |
|
448 case 0x4f: return Qt::Key_O; |
|
449 case 0x50: return Qt::Key_P; |
|
450 case 0x51: return Qt::Key_Q; |
|
451 case 0x52: return Qt::Key_R; |
|
452 case 0x53: return Qt::Key_S; |
|
453 case 0x54: return Qt::Key_T; |
|
454 case 0x55: return Qt::Key_U; |
|
455 case 0x56: return Qt::Key_V; |
|
456 case 0x57: return Qt::Key_W; |
|
457 case 0x58: return Qt::Key_X; |
|
458 case 0x59: return Qt::Key_Y; |
|
459 case 0x5a: return Qt::Key_Z; |
|
460 case 0x5b: return Qt::Key_BracketLeft; |
|
461 case 0x5c: return Qt::Key_Backslash; |
|
462 case 0x5d: return Qt::Key_BracketRight; |
|
463 case 0x5e: return Qt::Key_AsciiCircum; |
|
464 case 0x5f: return Qt::Key_Underscore; |
|
465 case 0x60: return Qt::Key_QuoteLeft; |
|
466 case 0x61: return Qt::Key_A; |
|
467 case 0x62: return Qt::Key_B; |
|
468 case 0x63: return Qt::Key_C; |
|
469 case 0x64: return Qt::Key_D; |
|
470 case 0x65: return Qt::Key_E; |
|
471 case 0x66: return Qt::Key_F; |
|
472 case 0x67: return Qt::Key_G; |
|
473 case 0x68: return Qt::Key_H; |
|
474 case 0x69: return Qt::Key_I; |
|
475 case 0x6a: return Qt::Key_J; |
|
476 case 0x6b: return Qt::Key_K; |
|
477 case 0x6c: return Qt::Key_L; |
|
478 case 0x6d: return Qt::Key_M; |
|
479 case 0x6e: return Qt::Key_N; |
|
480 case 0x6f: return Qt::Key_O; |
|
481 case 0x70: return Qt::Key_P; |
|
482 case 0x71: return Qt::Key_Q; |
|
483 case 0x72: return Qt::Key_R; |
|
484 case 0x73: return Qt::Key_S; |
|
485 case 0x74: return Qt::Key_T; |
|
486 case 0x75: return Qt::Key_U; |
|
487 case 0x76: return Qt::Key_V; |
|
488 case 0x77: return Qt::Key_W; |
|
489 case 0x78: return Qt::Key_X; |
|
490 case 0x79: return Qt::Key_Y; |
|
491 case 0x7a: return Qt::Key_Z; |
|
492 case 0x7b: return Qt::Key_BraceLeft; |
|
493 case 0x7c: return Qt::Key_Bar; |
|
494 case 0x7d: return Qt::Key_BraceRight; |
|
495 case 0x7e: return Qt::Key_AsciiTilde; |
|
496 |
|
497 // Latin 1 codes adapted from X: keysymdef.h,v 1.21 94/08/28 16:17:06 |
|
498 case 0xa0: return Qt::Key_nobreakspace; |
|
499 case 0xa1: return Qt::Key_exclamdown; |
|
500 case 0xa2: return Qt::Key_cent; |
|
501 case 0xa3: return Qt::Key_sterling; |
|
502 case 0xa4: return Qt::Key_currency; |
|
503 case 0xa5: return Qt::Key_yen; |
|
504 case 0xa6: return Qt::Key_brokenbar; |
|
505 case 0xa7: return Qt::Key_section; |
|
506 case 0xa8: return Qt::Key_diaeresis; |
|
507 case 0xa9: return Qt::Key_copyright; |
|
508 case 0xaa: return Qt::Key_ordfeminine; |
|
509 case 0xab: return Qt::Key_guillemotleft; |
|
510 case 0xac: return Qt::Key_notsign; |
|
511 case 0xad: return Qt::Key_hyphen; |
|
512 case 0xae: return Qt::Key_registered; |
|
513 case 0xaf: return Qt::Key_macron; |
|
514 case 0xb0: return Qt::Key_degree; |
|
515 case 0xb1: return Qt::Key_plusminus; |
|
516 case 0xb2: return Qt::Key_twosuperior; |
|
517 case 0xb3: return Qt::Key_threesuperior; |
|
518 case 0xb4: return Qt::Key_acute; |
|
519 case 0xb5: return Qt::Key_mu; |
|
520 case 0xb6: return Qt::Key_paragraph; |
|
521 case 0xb7: return Qt::Key_periodcentered; |
|
522 case 0xb8: return Qt::Key_cedilla; |
|
523 case 0xb9: return Qt::Key_onesuperior; |
|
524 case 0xba: return Qt::Key_masculine; |
|
525 case 0xbb: return Qt::Key_guillemotright; |
|
526 case 0xbc: return Qt::Key_onequarter; |
|
527 case 0xbd: return Qt::Key_onehalf; |
|
528 case 0xbe: return Qt::Key_threequarters; |
|
529 case 0xbf: return Qt::Key_questiondown; |
|
530 case 0xc0: return Qt::Key_Agrave; |
|
531 case 0xc1: return Qt::Key_Aacute; |
|
532 case 0xc2: return Qt::Key_Acircumflex; |
|
533 case 0xc3: return Qt::Key_Atilde; |
|
534 case 0xc4: return Qt::Key_Adiaeresis; |
|
535 case 0xc5: return Qt::Key_Aring; |
|
536 case 0xc6: return Qt::Key_AE; |
|
537 case 0xc7: return Qt::Key_Ccedilla; |
|
538 case 0xc8: return Qt::Key_Egrave; |
|
539 case 0xc9: return Qt::Key_Eacute; |
|
540 case 0xca: return Qt::Key_Ecircumflex; |
|
541 case 0xcb: return Qt::Key_Ediaeresis; |
|
542 case 0xcc: return Qt::Key_Igrave; |
|
543 case 0xcd: return Qt::Key_Iacute; |
|
544 case 0xce: return Qt::Key_Icircumflex; |
|
545 case 0xcf: return Qt::Key_Idiaeresis; |
|
546 case 0xd0: return Qt::Key_ETH; |
|
547 case 0xd1: return Qt::Key_Ntilde; |
|
548 case 0xd2: return Qt::Key_Ograve; |
|
549 case 0xd3: return Qt::Key_Oacute; |
|
550 case 0xd4: return Qt::Key_Ocircumflex; |
|
551 case 0xd5: return Qt::Key_Otilde; |
|
552 case 0xd6: return Qt::Key_Odiaeresis; |
|
553 case 0xd7: return Qt::Key_multiply; |
|
554 case 0xd8: return Qt::Key_Ooblique; |
|
555 case 0xd9: return Qt::Key_Ugrave; |
|
556 case 0xda: return Qt::Key_Uacute; |
|
557 case 0xdb: return Qt::Key_Ucircumflex; |
|
558 case 0xdc: return Qt::Key_Udiaeresis; |
|
559 case 0xdd: return Qt::Key_Yacute; |
|
560 case 0xde: return Qt::Key_THORN; |
|
561 case 0xdf: return Qt::Key_ssharp; |
|
562 case 0xe5: return Qt::Key_Aring; |
|
563 case 0xe6: return Qt::Key_AE; |
|
564 case 0xf7: return Qt::Key_division; |
|
565 case 0xf8: return Qt::Key_Ooblique; |
|
566 case 0xff: return Qt::Key_ydiaeresis; |
|
567 default: QTEST_ASSERT(false); return Qt::Key(0); |
|
568 } |
|
569 } |
|
570 |
|
571 char HbAutoTest::keyToAscii(Qt::Key key) |
|
572 { |
|
573 switch (key) { |
|
574 case Qt::Key_Backspace: return 0x8; //BS |
|
575 case Qt::Key_Tab: return 0x09; // HT |
|
576 case Qt::Key_Backtab: return 0x0b; // VT |
|
577 case Qt::Key_Enter: |
|
578 case Qt::Key_Return: return 0x0d; // CR |
|
579 case Qt::Key_Escape: return 0x1b; // ESC |
|
580 case Qt::Key_Space: return 0x20; // 7 bit printable ASCII |
|
581 case Qt::Key_Exclam: return 0x21; |
|
582 case Qt::Key_QuoteDbl: return 0x22; |
|
583 case Qt::Key_NumberSign: return 0x23; |
|
584 case Qt::Key_Dollar: return 0x24; |
|
585 case Qt::Key_Percent: return 0x25; |
|
586 case Qt::Key_Ampersand: return 0x26; |
|
587 case Qt::Key_Apostrophe: return 0x27; |
|
588 case Qt::Key_ParenLeft: return 0x28; |
|
589 case Qt::Key_ParenRight: return 0x29; |
|
590 case Qt::Key_Asterisk: return 0x2a; |
|
591 case Qt::Key_Plus: return 0x2b; |
|
592 case Qt::Key_Comma: return 0x2c; |
|
593 case Qt::Key_Minus: return 0x2d; |
|
594 case Qt::Key_Period: return 0x2e; |
|
595 case Qt::Key_Slash: return 0x2f; |
|
596 case Qt::Key_0: return 0x30; |
|
597 case Qt::Key_1: return 0x31; |
|
598 case Qt::Key_2: return 0x32; |
|
599 case Qt::Key_3: return 0x33; |
|
600 case Qt::Key_4: return 0x34; |
|
601 case Qt::Key_5: return 0x35; |
|
602 case Qt::Key_6: return 0x36; |
|
603 case Qt::Key_7: return 0x37; |
|
604 case Qt::Key_8: return 0x38; |
|
605 case Qt::Key_9: return 0x39; |
|
606 case Qt::Key_Colon: return 0x3a; |
|
607 case Qt::Key_Semicolon: return 0x3b; |
|
608 case Qt::Key_Less: return 0x3c; |
|
609 case Qt::Key_Equal: return 0x3d; |
|
610 case Qt::Key_Greater: return 0x3e; |
|
611 case Qt::Key_Question: return 0x3f; |
|
612 case Qt::Key_At: return 0x40; |
|
613 case Qt::Key_A: return 0x61; // 0x41 == 'A', 0x61 == 'a' |
|
614 case Qt::Key_B: return 0x62; |
|
615 case Qt::Key_C: return 0x63; |
|
616 case Qt::Key_D: return 0x64; |
|
617 case Qt::Key_E: return 0x65; |
|
618 case Qt::Key_F: return 0x66; |
|
619 case Qt::Key_G: return 0x67; |
|
620 case Qt::Key_H: return 0x68; |
|
621 case Qt::Key_I: return 0x69; |
|
622 case Qt::Key_J: return 0x6a; |
|
623 case Qt::Key_K: return 0x6b; |
|
624 case Qt::Key_L: return 0x6c; |
|
625 case Qt::Key_M: return 0x6d; |
|
626 case Qt::Key_N: return 0x6e; |
|
627 case Qt::Key_O: return 0x6f; |
|
628 case Qt::Key_P: return 0x70; |
|
629 case Qt::Key_Q: return 0x71; |
|
630 case Qt::Key_R: return 0x72; |
|
631 case Qt::Key_S: return 0x73; |
|
632 case Qt::Key_T: return 0x74; |
|
633 case Qt::Key_U: return 0x75; |
|
634 case Qt::Key_V: return 0x76; |
|
635 case Qt::Key_W: return 0x77; |
|
636 case Qt::Key_X: return 0x78; |
|
637 case Qt::Key_Y: return 0x79; |
|
638 case Qt::Key_Z: return 0x7a; |
|
639 case Qt::Key_BracketLeft: return 0x5b; |
|
640 case Qt::Key_Backslash: return 0x5c; |
|
641 case Qt::Key_BracketRight: return 0x5d; |
|
642 case Qt::Key_AsciiCircum: return 0x5e; |
|
643 case Qt::Key_Underscore: return 0x5f; |
|
644 case Qt::Key_QuoteLeft: return 0x60; |
|
645 |
|
646 case Qt::Key_BraceLeft: return 0x7b; |
|
647 case Qt::Key_Bar: return 0x7c; |
|
648 case Qt::Key_BraceRight: return 0x7d; |
|
649 case Qt::Key_AsciiTilde: return 0x7e; |
|
650 |
|
651 case Qt::Key_Delete: return 0; |
|
652 case Qt::Key_Insert: return 0; // = 0x1006, |
|
653 case Qt::Key_Pause: return 0; // = 0x1008, |
|
654 case Qt::Key_Print: return 0; // = 0x1009, |
|
655 case Qt::Key_SysReq: return 0; // = 0x100a, |
|
656 |
|
657 case Qt::Key_Clear: return 0; // = 0x100b, |
|
658 |
|
659 case Qt::Key_Home: return 0; // = 0x1010, // cursor movement |
|
660 case Qt::Key_End: return 0; // = 0x1011, |
|
661 case Qt::Key_Left: return 0; // = 0x1012, |
|
662 case Qt::Key_Up: return 0; // = 0x1013, |
|
663 case Qt::Key_Right: return 0; // = 0x1014, |
|
664 case Qt::Key_Down: return 0; // = 0x1015, |
|
665 case Qt::Key_PageUp: return 0; // = 0x1016, |
|
666 case Qt::Key_PageDown: return 0; // = 0x1017, |
|
667 case Qt::Key_Shift: return 0; // = 0x1020, // modifiers |
|
668 case Qt::Key_Control: return 0; // = 0x1021, |
|
669 case Qt::Key_Meta: return 0; // = 0x1022, |
|
670 case Qt::Key_Alt: return 0; // = 0x1023, |
|
671 case Qt::Key_CapsLock: return 0; // = 0x1024, |
|
672 case Qt::Key_NumLock: return 0; // = 0x1025, |
|
673 case Qt::Key_ScrollLock: return 0; // = 0x1026, |
|
674 case Qt::Key_F1: return 0; // = 0x1030, // function keys |
|
675 case Qt::Key_F2: return 0; // = 0x1031, |
|
676 case Qt::Key_F3: return 0; // = 0x1032, |
|
677 case Qt::Key_F4: return 0; // = 0x1033, |
|
678 case Qt::Key_F5: return 0; // = 0x1034, |
|
679 case Qt::Key_F6: return 0; // = 0x1035, |
|
680 case Qt::Key_F7: return 0; // = 0x1036, |
|
681 case Qt::Key_F8: return 0; // = 0x1037, |
|
682 case Qt::Key_F9: return 0; // = 0x1038, |
|
683 case Qt::Key_F10: return 0; // = 0x1039, |
|
684 case Qt::Key_F11: return 0; // = 0x103a, |
|
685 case Qt::Key_F12: return 0; // = 0x103b, |
|
686 case Qt::Key_F13: return 0; // = 0x103c, |
|
687 case Qt::Key_F14: return 0; // = 0x103d, |
|
688 case Qt::Key_F15: return 0; // = 0x103e, |
|
689 case Qt::Key_F16: return 0; // = 0x103f, |
|
690 case Qt::Key_F17: return 0; // = 0x1040, |
|
691 case Qt::Key_F18: return 0; // = 0x1041, |
|
692 case Qt::Key_F19: return 0; // = 0x1042, |
|
693 case Qt::Key_F20: return 0; // = 0x1043, |
|
694 case Qt::Key_F21: return 0; // = 0x1044, |
|
695 case Qt::Key_F22: return 0; // = 0x1045, |
|
696 case Qt::Key_F23: return 0; // = 0x1046, |
|
697 case Qt::Key_F24: return 0; // = 0x1047, |
|
698 case Qt::Key_F25: return 0; // = 0x1048, // F25 .. F35 only on X11 |
|
699 case Qt::Key_F26: return 0; // = 0x1049, |
|
700 case Qt::Key_F27: return 0; // = 0x104a, |
|
701 case Qt::Key_F28: return 0; // = 0x104b, |
|
702 case Qt::Key_F29: return 0; // = 0x104c, |
|
703 case Qt::Key_F30: return 0; // = 0x104d, |
|
704 case Qt::Key_F31: return 0; // = 0x104e, |
|
705 case Qt::Key_F32: return 0; // = 0x104f, |
|
706 case Qt::Key_F33: return 0; // = 0x1050, |
|
707 case Qt::Key_F34: return 0; // = 0x1051, |
|
708 case Qt::Key_F35: return 0; // = 0x1052, |
|
709 case Qt::Key_Super_L: return 0; // = 0x1053, // extra keys |
|
710 case Qt::Key_Super_R: return 0; // = 0x1054, |
|
711 case Qt::Key_Menu: return 0; // = 0x1055, |
|
712 case Qt::Key_Hyper_L: return 0; // = 0x1056, |
|
713 case Qt::Key_Hyper_R: return 0; // = 0x1057, |
|
714 case Qt::Key_Help: return 0; // = 0x1058, |
|
715 case Qt::Key_Direction_L: return 0; // = 0x1059, |
|
716 case Qt::Key_Direction_R: return 0; // = 0x1060, |
|
717 |
|
718 // Latin 1 codes adapted from X: keysymdef.h,v 1.21 94/08/28 16:17:06 |
|
719 case Qt::Key_nobreakspace: return char(0xa0); |
|
720 case Qt::Key_exclamdown: return char(0xa1); |
|
721 case Qt::Key_cent: return char(0xa2); |
|
722 case Qt::Key_sterling: return char(0xa3); |
|
723 case Qt::Key_currency: return char(0xa4); |
|
724 case Qt::Key_yen: return char(0xa5); |
|
725 case Qt::Key_brokenbar: return char(0xa6); |
|
726 case Qt::Key_section: return char(0xa7); |
|
727 case Qt::Key_diaeresis: return char(0xa8); |
|
728 case Qt::Key_copyright: return char(0xa9); |
|
729 case Qt::Key_ordfeminine: return char(0xaa); |
|
730 case Qt::Key_guillemotleft: return char(0xab); // left angle quotation mar |
|
731 case Qt::Key_notsign: return char(0xac); |
|
732 case Qt::Key_hyphen: return char(0xad); |
|
733 case Qt::Key_registered: return char(0xae); |
|
734 case Qt::Key_macron: return char(0xaf); |
|
735 case Qt::Key_degree: return char(0xb0); |
|
736 case Qt::Key_plusminus: return char(0xb1); |
|
737 case Qt::Key_twosuperior: return char(0xb2); |
|
738 case Qt::Key_threesuperior: return char(0xb3); |
|
739 case Qt::Key_acute: return char(0xb4); |
|
740 case Qt::Key_mu: return char(0xb5); |
|
741 case Qt::Key_paragraph: return char(0xb6); |
|
742 case Qt::Key_periodcentered: return char(0xb7); |
|
743 case Qt::Key_cedilla: return char(0xb8); |
|
744 case Qt::Key_onesuperior: return char(0xb9); |
|
745 case Qt::Key_masculine: return char(0xba); |
|
746 case Qt::Key_guillemotright: return char(0xbb); // right angle quotation mar |
|
747 case Qt::Key_onequarter: return char(0xbc); |
|
748 case Qt::Key_onehalf: return char(0xbd); |
|
749 case Qt::Key_threequarters: return char(0xbe); |
|
750 case Qt::Key_questiondown: return char(0xbf); |
|
751 case Qt::Key_Agrave: return char(0xc0); |
|
752 case Qt::Key_Aacute: return char(0xc1); |
|
753 case Qt::Key_Acircumflex: return char(0xc2); |
|
754 case Qt::Key_Atilde: return char(0xc3); |
|
755 case Qt::Key_Adiaeresis: return char(0xc4); |
|
756 case Qt::Key_Aring: return char(0xe5); |
|
757 case Qt::Key_AE: return char(0xe6); |
|
758 case Qt::Key_Ccedilla: return char(0xc7); |
|
759 case Qt::Key_Egrave: return char(0xc8); |
|
760 case Qt::Key_Eacute: return char(0xc9); |
|
761 case Qt::Key_Ecircumflex: return char(0xca); |
|
762 case Qt::Key_Ediaeresis: return char(0xcb); |
|
763 case Qt::Key_Igrave: return char(0xcc); |
|
764 case Qt::Key_Iacute: return char(0xcd); |
|
765 case Qt::Key_Icircumflex: return char(0xce); |
|
766 case Qt::Key_Idiaeresis: return char(0xcf); |
|
767 case Qt::Key_ETH: return char(0xd0); |
|
768 case Qt::Key_Ntilde: return char(0xd1); |
|
769 case Qt::Key_Ograve: return char(0xd2); |
|
770 case Qt::Key_Oacute: return char(0xd3); |
|
771 case Qt::Key_Ocircumflex: return char(0xd4); |
|
772 case Qt::Key_Otilde: return char(0xd5); |
|
773 case Qt::Key_Odiaeresis: return char(0xd6); |
|
774 case Qt::Key_multiply: return char(0xd7); |
|
775 case Qt::Key_Ooblique: return char(0xf8); |
|
776 case Qt::Key_Ugrave: return char(0xd9); |
|
777 case Qt::Key_Uacute: return char(0xda); |
|
778 case Qt::Key_Ucircumflex: return char(0xdb); |
|
779 case Qt::Key_Udiaeresis: return char(0xdc); |
|
780 case Qt::Key_Yacute: return char(0xdd); |
|
781 case Qt::Key_THORN: return char(0xde); |
|
782 case Qt::Key_ssharp: return char(0xdf); |
|
783 case Qt::Key_division: return char(0xf7); |
|
784 case Qt::Key_ydiaeresis: return char(0xff); |
|
785 |
|
786 // multimedia/internet keys - ignored by default - see QKeyEvent c'tor |
|
787 |
|
788 case Qt::Key_Back : return 0; // = 0x1061, |
|
789 case Qt::Key_Forward : return 0; // = 0x1062, |
|
790 case Qt::Key_Stop : return 0; // = 0x1063, |
|
791 case Qt::Key_Refresh : return 0; // = 0x1064, |
|
792 |
|
793 case Qt::Key_VolumeDown: return 0; // = 0x1070, |
|
794 case Qt::Key_VolumeMute : return 0; // = 0x1071, |
|
795 case Qt::Key_VolumeUp: return 0; // = 0x1072, |
|
796 case Qt::Key_BassBoost: return 0; // = 0x1073, |
|
797 case Qt::Key_BassUp: return 0; // = 0x1074, |
|
798 case Qt::Key_BassDown: return 0; // = 0x1075, |
|
799 case Qt::Key_TrebleUp: return 0; // = 0x1076, |
|
800 case Qt::Key_TrebleDown: return 0; // = 0x1077, |
|
801 |
|
802 case Qt::Key_MediaPlay : return 0; // = 0x1080, |
|
803 case Qt::Key_MediaStop : return 0; // = 0x1081, |
|
804 case Qt::Key_MediaPrevious : return 0; // = 0x1082, |
|
805 case Qt::Key_MediaNext : return 0; // = 0x1083, |
|
806 case Qt::Key_MediaRecord: return 0; // = 0x1084, |
|
807 |
|
808 case Qt::Key_HomePage : return 0; // = 0x1090, |
|
809 case Qt::Key_Favorites : return 0; // = 0x1091, |
|
810 case Qt::Key_Search : return 0; // = 0x1092, |
|
811 case Qt::Key_Standby: return 0; // = 0x1093, |
|
812 case Qt::Key_OpenUrl: return 0; // = 0x1094, |
|
813 |
|
814 case Qt::Key_LaunchMail : return 0; // = 0x10a0, |
|
815 case Qt::Key_LaunchMedia: return 0; // = 0x10a1, |
|
816 case Qt::Key_Launch0 : return 0; // = 0x10a2, |
|
817 case Qt::Key_Launch1 : return 0; // = 0x10a3, |
|
818 case Qt::Key_Launch2 : return 0; // = 0x10a4, |
|
819 case Qt::Key_Launch3 : return 0; // = 0x10a5, |
|
820 case Qt::Key_Launch4 : return 0; // = 0x10a6, |
|
821 case Qt::Key_Launch5 : return 0; // = 0x10a7, |
|
822 case Qt::Key_Launch6 : return 0; // = 0x10a8, |
|
823 case Qt::Key_Launch7 : return 0; // = 0x10a9, |
|
824 case Qt::Key_Launch8 : return 0; // = 0x10aa, |
|
825 case Qt::Key_Launch9 : return 0; // = 0x10ab, |
|
826 case Qt::Key_LaunchA : return 0; // = 0x10ac, |
|
827 case Qt::Key_LaunchB : return 0; // = 0x10ad, |
|
828 case Qt::Key_LaunchC : return 0; // = 0x10ae, |
|
829 case Qt::Key_LaunchD : return 0; // = 0x10af, |
|
830 case Qt::Key_LaunchE : return 0; // = 0x10b0, |
|
831 case Qt::Key_LaunchF : return 0; // = 0x10b1, |
|
832 |
|
833 default: QTEST_ASSERT(false); return 0; |
|
834 } |
|
835 } |
|