1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
/****************************************************************************
**
** Copyright (C) 2015 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://www.qt.io
**
** This file is part of the Qt Virtual Keyboard add-on for Qt Enterprise.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io
**
****************************************************************************/
import QtTest 1.0
import QtQuick 2.0
import QtQuick.Enterprise.VirtualKeyboard 1.2
import QtQuick.Enterprise.VirtualKeyboard.Settings 1.2
InputPanel {
id: inputPanel
z: 99
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
visible: Qt.inputMethod.visible
property var testcase
property var virtualKeyPressPoint: null
readonly property bool autoCapitalizationEnabled: InputContext.shiftHandler.autoCapitalizationEnabled
readonly property bool toggleShiftEnabled: InputContext.shiftHandler.toggleShiftEnabled
readonly property var keyboard: findChildByProperty(inputPanel, "objectName", "keyboard", null)
readonly property var keyboardLayoutLoader: findChildByProperty(keyboard, "objectName", "keyboardLayoutLoader", null)
readonly property var keyboardInputArea: findChildByProperty(keyboard, "objectName", "keyboardInputArea", null)
readonly property var characterPreviewBubble: findChildByProperty(keyboard, "objectName", "characterPreviewBubble", null)
readonly property var alternativeKeys: findChildByProperty(keyboard, "objectName", "alternativeKeys", null)
readonly property var naviationHighlight: findChildByProperty(keyboard, "objectName", "naviationHighlight", null)
readonly property var wordCandidateView: findChildByProperty(keyboard, "objectName", "wordCandidateView", null)
readonly property bool keyboardLayoutsAvailable: keyboard.availableLocaleIndices.length > 0 && keyboard.availableLocaleIndices.indexOf(-1) === -1
property alias keyboardLayoutsAvailableSpy: keyboardLayoutsAvailableSpy
property alias keyboardLayoutLoaderItemSpy: keyboardLayoutLoaderItemSpy
property alias characterPreviewBubbleSpy: characterPreviewBubbleSpy
property alias alternativeKeysSpy: alternativeKeysSpy
property alias activeKeyChangedSpy: activeKeyChangedSpy
property alias virtualKeyClickedSpy: virtualKeyClickedSpy
property alias dragSymbolModeSpy: dragSymbolModeSpy
property alias styleSpy: styleSpy
property alias soundEffectSpy: soundEffectSpy
SignalSpy {
id: keyboardLayoutsAvailableSpy
target: inputPanel
signalName: "onKeyboardLayoutsAvailableChanged"
}
SignalSpy {
id: keyboardLayoutLoaderItemSpy
target: keyboardLayoutLoader
signalName: "onItemChanged"
}
SignalSpy {
id: characterPreviewBubbleSpy
target: characterPreviewBubble
signalName: "onVisibleChanged"
}
SignalSpy {
id: alternativeKeysSpy
target: alternativeKeys
signalName: "onVisibleChanged"
}
SignalSpy {
id: activeKeyChangedSpy
target: InputContext.inputEngine
signalName: "activeKeyChanged"
}
SignalSpy {
id: virtualKeyClickedSpy
target: InputContext.inputEngine
signalName: "virtualKeyClicked"
}
SignalSpy {
id: dragSymbolModeSpy
target: keyboardInputArea
signalName: "onDragSymbolModeChanged"
}
SignalSpy {
id: styleSpy
target: keyboard
signalName: "onStyleChanged"
}
SignalSpy {
id: soundEffectSpy
target: keyboard.soundEffect
signalName: "onPlayingChanged"
}
function findChildByProperty(parent, propertyName, propertyValue, compareCb) {
var obj = null
if (parent === null)
return null
var children = parent.children
for (var i = 0; i < children.length; i++) {
obj = children[i]
if (obj.hasOwnProperty(propertyName)) {
if (compareCb !== null) {
if (compareCb(obj[propertyName], propertyValue))
break
} else if (obj[propertyName] === propertyValue) {
break
}
}
obj = findChildByProperty(obj, propertyName, propertyValue, compareCb)
if (obj)
break
}
return obj
}
function isLocaleSupported(inputLocale) {
var localeIndex = keyboard.findLocale(inputLocale, -1)
return localeIndex !== -1
}
function setLocale(inputLocale) {
var localeIndex = keyboard.findLocale(inputLocale, -1)
if (localeIndex === -1)
return false
var origLocaleIndex = keyboard.localeIndex
if (keyboard.localeIndex !== localeIndex) {
keyboard.localeIndex = localeIndex
keyboardLayoutLoaderItemSpy.wait()
}
var success = keyboardLayoutLoader.item !== null
if (keyboardLayoutLoader.item === null) {
if (keyboard.localeIndex !== origLocaleIndex) {
keyboard.localeIndex = origLocaleIndex
keyboardLayoutLoaderItemSpy.wait()
}
}
return success
}
function findVirtualKey(key) {
return findChildByProperty(keyboardLayoutLoader, (typeof key == "number") ? "key" : "text", key, null)
}
function findVirtualKeyAlternative(key) {
if (typeof key != "string")
return null
return findChildByProperty(keyboardLayoutLoader, "alternativeKeys", key, function(propertyValue, key) { return propertyValue.indexOf(key) !== -1 })
}
function virtualKeyPressOnCurrentLayout(key) {
var keyObj = findVirtualKey(key)
var alternativeKey = false
if (!keyObj && typeof key == "string") {
keyObj = findVirtualKeyAlternative(key)
alternativeKey = keyObj !== null
if (alternativeKey)
alternativeKeysSpy.clear()
}
if (keyObj) {
virtualKeyPressPoint = inputPanel.mapFromItem(keyObj, keyObj.width / 2, keyObj.height / 2)
testcase.mousePress(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y)
testcase.waitForRendering(inputPanel)
if (alternativeKey) {
alternativeKeysSpy.wait()
var keyIndex = keyObj.alternativeKeys.indexOf(key)
var itemX = keyIndex * keyboard.style.alternateKeysListItemWidth + keyboard.style.alternateKeysListItemWidth / 2
virtualKeyPressPoint.x = inputPanel.mapFromItem(alternativeKeys.listView, itemX, 0).x
testcase.mouseMove(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y)
testcase.waitForRendering(inputPanel)
}
return true
}
return false
}
function multiLayoutKeyActionHelper(key, keyActionOnCurrentLayoutCb) {
var success = keyActionOnCurrentLayoutCb(key)
if (success === false) {
// Check if the current layout contains multiple layouts
if (keyboardLayoutLoader.item.hasOwnProperty("item")) {
// If already in symbolMode, try the other page
if (keyboard.symbolMode) {
if (keyboardLayoutLoader.item.hasOwnProperty("secondPage")) {
keyboardLayoutLoader.item.secondPage = !keyboardLayoutLoader.item.secondPage
testcase.waitForRendering(inputPanel)
success = keyActionOnCurrentLayoutCb(key)
keyboardLayoutLoader.item.secondPage = !keyboardLayoutLoader.item.secondPage
}
} else {
// Some layouts (such as Arabic, Hindi) may have a second layout
InputContext.shiftHandler.toggleShift()
testcase.waitForRendering(inputPanel)
success = keyActionOnCurrentLayoutCb(key)
InputContext.shiftHandler.toggleShift()
}
} else if (!keyboard.symbolMode) {
// Switch to symbol mode
keyboard.symbolMode = true
testcase.waitForRendering(inputPanel)
success = keyActionOnCurrentLayoutCb(key)
if (!success && keyboardLayoutLoader.item.hasOwnProperty("secondPage")) {
// Try the second page
keyboardLayoutLoader.item.secondPage = true
testcase.waitForRendering(inputPanel)
success = keyActionOnCurrentLayoutCb(key)
}
keyboard.symbolMode = false
}
}
if (!success)
console.warn("Key not found '%1'".arg(key))
return success
}
function virtualKeyPress(key) {
return multiLayoutKeyActionHelper(key, virtualKeyPressOnCurrentLayout)
}
function virtualKeyDrag(key) {
if (virtualKeyPressPoint !== null) {
var keyObj = findChildByProperty(keyboardLayoutLoader, (typeof key == "number") ? "key" : "text", key, null)
if (keyObj !== null) {
virtualKeyPressPoint = inputPanel.mapFromItem(keyObj, keyObj.width / 2, keyObj.height / 2)
testcase.mouseMove(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y)
testcase.waitForRendering(inputPanel)
return true
}
}
return false
}
function virtualKeyRelease() {
if (virtualKeyPressPoint !== null) {
testcase.mouseRelease(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y)
virtualKeyPressPoint = null
return true
}
return false
}
function virtualKeyClick(key) {
if (virtualKeyPress(key)) {
virtualKeyRelease()
return true
}
return false
}
function emulateNavigationKeyClick(navigationKey) {
testcase.keyClick(navigationKey)
testcase.waitForRendering(inputPanel)
}
function navigationHighlightContains(point) {
var navigationPoint = inputPanel.mapToItem(inputPanel.naviationHighlight, point.x, point.y)
return inputPanel.naviationHighlight.contains(Qt.point(navigationPoint.x, navigationPoint.y))
}
function navigateToKeyOnPoint(point) {
activateNavigationKeyMode()
if (inputPanel.naviationHighlight.visible) {
while (true) {
var navigationPoint = inputPanel.mapToItem(inputPanel.naviationHighlight, point.x, point.y)
if (navigationHighlightContains(point))
return true
if (inputPanel.naviationHighlight.y > point.y)
emulateNavigationKeyClick(Qt.Key_Up)
else if (inputPanel.naviationHighlight.y + inputPanel.naviationHighlight.height < point.y)
emulateNavigationKeyClick(Qt.Key_Down)
else if (inputPanel.naviationHighlight.x > point.x)
emulateNavigationKeyClick(Qt.Key_Left)
else if (inputPanel.naviationHighlight.x + inputPanel.naviationHighlight.width < point.x)
emulateNavigationKeyClick(Qt.Key_Right)
testcase.wait(inputPanel.naviationHighlight.moveDuration)
}
}
return false
}
function navigateToKeyOnCurrentLayout(key) {
var keyObj = findVirtualKey(key)
var alternativeKey = false
if (!keyObj && typeof key == "string") {
keyObj = findVirtualKeyAlternative(key)
alternativeKey = keyObj !== null
}
if (keyObj) {
var point = inputPanel.mapFromItem(keyObj, keyObj.width / 2, keyObj.height / 2)
if (!navigateToKeyOnPoint(point))
return false
if (alternativeKey) {
alternativeKeysSpy.clear()
testcase.keyPress(Qt.Key_Return)
alternativeKeysSpy.wait()
testcase.keyRelease(Qt.Key_Return)
var keyIndex = keyObj.alternativeKeys.indexOf(key)
while (inputPanel.alternativeKeys.listView.currentIndex !== keyIndex) {
testcase.verify(inputPanel.alternativeKeys.listView.currentIndex !== -1)
emulateNavigationKeyClick(inputPanel.alternativeKeys.listView.currentIndex < keyIndex ? Qt.Key_Right : Qt.Key_Left)
}
}
return true
}
return false
}
function navigationKeyClickOnCurrentLayout(key) {
if (navigateToKeyOnCurrentLayout(key)) {
testcase.keyClick(Qt.Key_Return)
return true
}
return false
}
function navigateToKey(key) {
return multiLayoutKeyActionHelper(key, navigateToKeyOnCurrentLayout)
}
function navigationKeyClick(key) {
return multiLayoutKeyActionHelper(key, navigationKeyClickOnCurrentLayout)
}
function activateNavigationKeyMode() {
if (!inputPanel.naviationHighlight.visible) {
emulateNavigationKeyClick(Qt.Key_Right)
if (inputPanel.naviationHighlight.visible)
testcase.wait(inputPanel.naviationHighlight.moveDuration)
}
return inputPanel.naviationHighlight.visible
}
function toggleShift() {
InputContext.shiftHandler.toggleShift()
}
function style() {
return VirtualKeyboardSettings.styleName
}
function setStyle(style) {
VirtualKeyboardSettings.styleName = style
}
function selectionListSearchSuggestion(suggestion) {
var suggestionFound = false
var origIndex = inputPanel.wordCandidateView.currentIndex
if (origIndex !== -1) {
while (true) {
if (inputPanel.wordCandidateView.model.itemData(inputPanel.wordCandidateView.currentIndex) === suggestion) {
suggestionFound = true
break
}
if (inputPanel.wordCandidateView.currentIndex === inputPanel.wordCandidateView.count - 1)
break
inputPanel.wordCandidateView.incrementCurrentIndex()
}
if (!suggestionFound) {
while (inputPanel.wordCandidateView.currentIndex !== origIndex) {
inputPanel.wordCandidateView.decrementCurrentIndex()
}
}
testcase.waitForRendering(inputPanel)
}
return suggestionFound
}
function selectionListSelectCurrentItem() {
if (inputPanel.wordCandidateView.currentItem === -1)
return false
var itemPos = inputPanel.mapFromItem(inputPanel.wordCandidateView.currentItem, 0, 0)
testcase.mouseClick(inputPanel, itemPos.x, itemPos.y)
testcase.waitForRendering(inputPanel)
return true
}
}
|