author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtTest/QtTest> |
|
43 |
#include "../../shared/util.h" |
|
44 |
||
45 |
#include <qinputcontext.h> |
|
46 |
#include <qlineedit.h> |
|
47 |
#include <qplaintextedit.h> |
|
48 |
#include <qlayout.h> |
|
49 |
#include <qradiobutton.h> |
|
50 |
#include <qwindowsstyle.h> |
|
51 |
||
52 |
class tst_QInputContext : public QObject |
|
53 |
{ |
|
54 |
Q_OBJECT |
|
55 |
||
56 |
public: |
|
57 |
tst_QInputContext() {} |
|
58 |
virtual ~tst_QInputContext() {} |
|
59 |
||
60 |
public slots: |
|
61 |
void initTestCase() {} |
|
62 |
void cleanupTestCase() {} |
|
63 |
void init() {} |
|
64 |
void cleanup() {} |
|
65 |
private slots: |
|
66 |
void maximumTextLength(); |
|
67 |
void filterMouseEvents(); |
|
68 |
void requestSoftwareInputPanel(); |
|
69 |
void closeSoftwareInputPanel(); |
|
70 |
void selections(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
void focusProxy(); |
0 | 72 |
}; |
73 |
||
74 |
void tst_QInputContext::maximumTextLength() |
|
75 |
{ |
|
76 |
QLineEdit le; |
|
77 |
||
78 |
le.setMaxLength(15); |
|
79 |
QVariant variant = le.inputMethodQuery(Qt::ImMaximumTextLength); |
|
80 |
QVERIFY(variant.isValid()); |
|
81 |
QCOMPARE(variant.toInt(), 15); |
|
82 |
||
83 |
QPlainTextEdit pte; |
|
84 |
// For BC/historical reasons, QPlainTextEdit::inputMethodQuery is protected. |
|
85 |
variant = static_cast<QWidget *>(&pte)->inputMethodQuery(Qt::ImMaximumTextLength); |
|
86 |
QVERIFY(!variant.isValid()); |
|
87 |
} |
|
88 |
||
89 |
class QFilterInputContext : public QInputContext |
|
90 |
{ |
|
91 |
public: |
|
92 |
QFilterInputContext() {} |
|
93 |
~QFilterInputContext() {} |
|
94 |
||
95 |
QString identifierName() { return QString(); } |
|
96 |
QString language() { return QString(); } |
|
97 |
||
98 |
void reset() {} |
|
99 |
||
100 |
bool isComposing() const { return false; } |
|
101 |
||
102 |
bool filterEvent( const QEvent *event ) |
|
103 |
{ |
|
104 |
lastTypes.append(event->type()); |
|
105 |
return false; |
|
106 |
} |
|
107 |
||
108 |
public: |
|
109 |
QList<QEvent::Type> lastTypes; |
|
110 |
}; |
|
111 |
||
112 |
void tst_QInputContext::filterMouseEvents() |
|
113 |
{ |
|
114 |
QLineEdit le; |
|
115 |
le.show(); |
|
116 |
QApplication::setActiveWindow(&le); |
|
117 |
||
118 |
QFilterInputContext *ic = new QFilterInputContext; |
|
119 |
le.setInputContext(ic); |
|
120 |
QTest::mouseClick(&le, Qt::LeftButton); |
|
121 |
||
122 |
QVERIFY(ic->lastTypes.indexOf(QEvent::MouseButtonRelease) >= 0); |
|
123 |
||
124 |
le.setInputContext(0); |
|
125 |
} |
|
126 |
||
127 |
class RequestSoftwareInputPanelStyle : public QWindowsStyle |
|
128 |
{ |
|
129 |
public: |
|
130 |
RequestSoftwareInputPanelStyle() |
|
131 |
: m_rsipBehavior(RSIP_OnMouseClickAndAlreadyFocused) |
|
132 |
{ |
|
133 |
#ifdef Q_OS_WINCE |
|
134 |
qApp->setAutoSipEnabled(true); |
|
135 |
#endif |
|
136 |
} |
|
137 |
~RequestSoftwareInputPanelStyle() |
|
138 |
{ |
|
139 |
} |
|
140 |
||
141 |
int styleHint(StyleHint hint, const QStyleOption *opt = 0, |
|
142 |
const QWidget *widget = 0, QStyleHintReturn* returnData = 0) const |
|
143 |
{ |
|
144 |
if (hint == SH_RequestSoftwareInputPanel) { |
|
145 |
return m_rsipBehavior; |
|
146 |
} else { |
|
147 |
return QWindowsStyle::styleHint(hint, opt, widget, returnData); |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
RequestSoftwareInputPanel m_rsipBehavior; |
|
152 |
}; |
|
153 |
||
154 |
void tst_QInputContext::requestSoftwareInputPanel() |
|
155 |
{ |
|
156 |
QStyle *oldStyle = qApp->style(); |
|
157 |
oldStyle->setParent(this); // Prevent it being deleted. |
|
158 |
RequestSoftwareInputPanelStyle *newStyle = new RequestSoftwareInputPanelStyle; |
|
159 |
qApp->setStyle(newStyle); |
|
160 |
||
161 |
QWidget w; |
|
162 |
QLayout *layout = new QVBoxLayout; |
|
163 |
QLineEdit *le1, *le2; |
|
164 |
le1 = new QLineEdit; |
|
165 |
le2 = new QLineEdit; |
|
166 |
layout->addWidget(le1); |
|
167 |
layout->addWidget(le2); |
|
168 |
w.setLayout(layout); |
|
169 |
||
170 |
QFilterInputContext *ic1, *ic2; |
|
171 |
ic1 = new QFilterInputContext; |
|
172 |
ic2 = new QFilterInputContext; |
|
173 |
le1->setInputContext(ic1); |
|
174 |
le2->setInputContext(ic2); |
|
175 |
||
176 |
w.show(); |
|
177 |
QApplication::setActiveWindow(&w); |
|
178 |
||
179 |
// Testing single click panel activation. |
|
180 |
newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClick; |
|
181 |
QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
182 |
QVERIFY(ic2->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) >= 0); |
|
183 |
ic2->lastTypes.clear(); |
|
184 |
||
185 |
// Testing double click panel activation. |
|
186 |
newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClickAndAlreadyFocused; |
|
187 |
QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
188 |
QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0); |
|
189 |
QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
190 |
QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) >= 0); |
|
191 |
ic1->lastTypes.clear(); |
|
192 |
||
193 |
// Testing right mouse button |
|
194 |
QTest::mouseClick(le1, Qt::RightButton, Qt::NoModifier, QPoint(5, 5)); |
|
195 |
QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0); |
|
196 |
||
197 |
qApp->setStyle(oldStyle); |
|
198 |
oldStyle->setParent(qApp); |
|
199 |
} |
|
200 |
||
201 |
void tst_QInputContext::closeSoftwareInputPanel() |
|
202 |
{ |
|
203 |
QWidget w; |
|
204 |
QLayout *layout = new QVBoxLayout; |
|
205 |
QLineEdit *le1, *le2; |
|
206 |
QRadioButton *rb; |
|
207 |
le1 = new QLineEdit; |
|
208 |
le2 = new QLineEdit; |
|
209 |
rb = new QRadioButton; |
|
210 |
layout->addWidget(le1); |
|
211 |
layout->addWidget(le2); |
|
212 |
layout->addWidget(rb); |
|
213 |
w.setLayout(layout); |
|
214 |
||
215 |
QFilterInputContext *ic1, *ic2; |
|
216 |
ic1 = new QFilterInputContext; |
|
217 |
ic2 = new QFilterInputContext; |
|
218 |
le1->setInputContext(ic1); |
|
219 |
le2->setInputContext(ic2); |
|
220 |
||
221 |
w.show(); |
|
222 |
QApplication::setActiveWindow(&w); |
|
223 |
||
224 |
// Testing that panel doesn't close between two input methods aware widgets. |
|
225 |
QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
226 |
QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
227 |
QVERIFY(ic2->lastTypes.indexOf(QEvent::CloseSoftwareInputPanel) < 0); |
|
228 |
||
229 |
// Testing that panel closes when focusing non-aware widget. |
|
230 |
QTest::mouseClick(rb, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
231 |
QVERIFY(ic2->lastTypes.indexOf(QEvent::CloseSoftwareInputPanel) >= 0); |
|
232 |
} |
|
233 |
||
234 |
void tst_QInputContext::selections() |
|
235 |
{ |
|
236 |
QLineEdit le; |
|
237 |
le.setText("Test text"); |
|
238 |
le.setSelection(2, 2); |
|
239 |
QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 4); |
|
240 |
QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 2); |
|
241 |
||
242 |
QList<QInputMethodEvent::Attribute> attributes; |
|
243 |
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 5, 3, QVariant())); |
|
244 |
QInputMethodEvent event("", attributes); |
|
245 |
QApplication::sendEvent(&le, &event); |
|
246 |
QCOMPARE(le.cursorPosition(), 8); |
|
247 |
QCOMPARE(le.selectionStart(), 5); |
|
248 |
QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 8); |
|
249 |
QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 5); |
|
250 |
} |
|
251 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
void tst_QInputContext::focusProxy() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
QWidget toplevel(0, Qt::X11BypassWindowManagerHint); toplevel.setObjectName("toplevel"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
QWidget w(&toplevel); w.setObjectName("w"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
QWidget proxy(&w); proxy.setObjectName("proxy"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
QWidget proxy2(&w); proxy2.setObjectName("proxy2"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
w.setFocusProxy(&proxy); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
w.setAttribute(Qt::WA_InputMethodEnabled); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
toplevel.show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
QApplication::setActiveWindow(&toplevel); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
QTest::qWaitForWindowShown(&toplevel); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
w.setFocus(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
w.setAttribute(Qt::WA_NativeWindow); // we shouldn't crash! |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
proxy.setAttribute(Qt::WA_InputMethodEnabled); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
proxy2.setAttribute(Qt::WA_InputMethodEnabled); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
proxy2.setFocus(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
w.setFocus(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
QInputContext *gic = qApp->inputContext(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
QVERIFY(gic); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
qDebug() << gic->focusWidget() << &proxy; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
QCOMPARE(gic->focusWidget(), &proxy); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
// then change the focus proxy and check that input context is valid |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
QVERIFY(w.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
QVERIFY(proxy.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
QVERIFY(!proxy2.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
w.setFocusProxy(&proxy2); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
QVERIFY(!w.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
QVERIFY(proxy.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
QVERIFY(!proxy2.hasFocus()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
QCOMPARE(gic->focusWidget(), &proxy); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
|
0 | 288 |
QTEST_MAIN(tst_QInputContext) |
289 |
#include "tst_qinputcontext.moc" |