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: Dialpad test utility |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGraphicsWidget> |
|
19 #include <QtTest/QtTest> |
|
20 #include <hbmainwindow.h> |
|
21 |
|
22 #include "dialpadtestutil.h" |
|
23 |
|
24 const int WAIT_TIME = 300; |
|
25 |
|
26 DialpadTestUtil::DialpadTestUtil(HbMainWindow& mainWindow, QObject* parent) : |
|
27 QObject(parent), mMainWindow(mainWindow) |
|
28 { |
|
29 mKeyNames.insert(Qt::Key_1,"keypad"); |
|
30 mKeyNames.insert(Qt::Key_2,"keypad"); |
|
31 mKeyNames.insert(Qt::Key_3,"keypad"); |
|
32 mKeyNames.insert(Qt::Key_4,"keypad"); |
|
33 mKeyNames.insert(Qt::Key_5,"keypad"); |
|
34 mKeyNames.insert(Qt::Key_6,"keypad"); |
|
35 mKeyNames.insert(Qt::Key_7,"keypad"); |
|
36 mKeyNames.insert(Qt::Key_8,"keypad"); |
|
37 mKeyNames.insert(Qt::Key_9,"keypad"); |
|
38 mKeyNames.insert(Qt::Key_Asterisk,"keypad"); |
|
39 mKeyNames.insert(Qt::Key_0,"keypad"); |
|
40 mKeyNames.insert(Qt::Key_NumberSign,"keypad"); |
|
41 mKeyNames.insert(Qt::Key_Backspace,"16777219"); |
|
42 mKeyNames.insert(Qt::Key_Yes,"16842753"); |
|
43 } |
|
44 |
|
45 DialpadTestUtil::~DialpadTestUtil() |
|
46 { |
|
47 } |
|
48 |
|
49 QGraphicsWidget* DialpadTestUtil::getWidgetByName(const QString& name) |
|
50 { |
|
51 QGraphicsWidget* widget = 0; |
|
52 |
|
53 QList<QGraphicsItem*> items = mMainWindow.scene()->items(); |
|
54 foreach (QGraphicsItem* item, items) { |
|
55 if (item->isWidget()) { |
|
56 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item); |
|
57 if (w->objectName()==name) { |
|
58 widget = w; |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 return widget; |
|
64 } |
|
65 |
|
66 QPointF DialpadTestUtil::keyPosition(QGraphicsWidget* widget, int key) |
|
67 { |
|
68 QPointF keyPos; |
|
69 QRectF rect = widget->rect(); |
|
70 |
|
71 // 3 x 4 grid |
|
72 int cellWidth = rect.width() / 3; |
|
73 int cellHeight = rect.height() / 4; |
|
74 |
|
75 if (key==Qt::Key_Asterisk) { |
|
76 keyPos = QPointF( 0.5 * cellWidth, 3.5 * cellHeight ); |
|
77 } else if (key==Qt::Key_NumberSign) { |
|
78 keyPos = QPointF( 2.5 * cellWidth, 3.5 * cellHeight ); |
|
79 } else if (key==Qt::Key_0) { |
|
80 keyPos = QPointF( 1.5 * cellWidth, 3.5 * cellHeight ); |
|
81 } else { |
|
82 int normalized = key - 49; |
|
83 // qDebug() << normalized; |
|
84 int column = normalized % 3; |
|
85 int row = (normalized / 3); |
|
86 // qDebug() << column << row; |
|
87 |
|
88 keyPos = QPointF((column+0.5)*cellWidth,(row+0.5)*cellHeight); |
|
89 } |
|
90 |
|
91 return keyPos; |
|
92 } |
|
93 |
|
94 void DialpadTestUtil::mouseClickDialpad(int key, MouseEventType type, bool pause) |
|
95 { |
|
96 QString name = mKeyNames.value(key); |
|
97 |
|
98 QGraphicsWidget* widget = getWidgetByName(name); |
|
99 |
|
100 if ( widget ) { |
|
101 QPointF widgetPos; |
|
102 |
|
103 if (name=="keypad") { |
|
104 widgetPos = widget->scenePos() + |
|
105 keyPosition(widget, key); |
|
106 } else { |
|
107 widgetPos = widget->scenePos() + |
|
108 widget->rect().center(); |
|
109 } |
|
110 |
|
111 QPoint windowPos = mMainWindow.mapFromScene( widgetPos ); |
|
112 |
|
113 if (type==Press) { |
|
114 QTest::mousePress( mMainWindow.viewport(), Qt::LeftButton, |
|
115 0, windowPos ); |
|
116 } else if (type==Release) { |
|
117 QTest::mouseRelease( mMainWindow.viewport(), Qt::LeftButton, |
|
118 0, windowPos ); |
|
119 } else { |
|
120 QTest::mouseClick( mMainWindow.viewport(), Qt::LeftButton, |
|
121 0, windowPos ); |
|
122 } |
|
123 |
|
124 if (pause) { |
|
125 QTest::qWait( WAIT_TIME ); |
|
126 } |
|
127 } else { |
|
128 QFAIL( "Button could not be accessed!" ); |
|
129 } |
|
130 } |
|
131 |
|
132 |
|