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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtTest
import QtQuick.Controls
TestCase {
id: testCase
width: 400
height: 400
visible: true
when: windowShown
name: "PageIndicator"
Component {
id: pageIndicator
PageIndicator {
objectName: "pageIndicator"
contentItem.objectName: "pageIndicatorContentItem"
}
}
Component {
id: mouseArea
MouseArea {
objectName: "mouseArea"
}
}
function init() {
failOnWarning(/.?/)
}
function test_defaults() {
let control = createTemporaryObject(pageIndicator, testCase)
verify(control)
}
function test_count() {
let control = createTemporaryObject(pageIndicator, testCase)
verify(control)
compare(control.count, 0)
control.count = 3
compare(control.count, 3)
}
function test_currentIndex() {
let control = createTemporaryObject(pageIndicator, testCase)
verify(control)
compare(control.currentIndex, 0)
control.currentIndex = 5
compare(control.currentIndex, 5)
}
function test_interactive_data() {
return [
{ tag: "mouse", touch: false },
{ tag: "touch", touch: true }
]
}
function test_interactive(data) {
let control = createTemporaryObject(pageIndicator, testCase, {count: 5, spacing: 10, topPadding: 10, leftPadding: 10, rightPadding: 10, bottomPadding: 10})
verify(control)
verify(!control.interactive)
compare(control.currentIndex, 0)
let touch = touchEvent(control)
if (data.touch)
touch.press(0, control).commit().release(0, control).commit()
else
mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.currentIndex, 0)
control.interactive = true
verify(control.interactive)
if (data.touch)
touch.press(0, control).commit().release(0, control).commit()
else
mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.currentIndex, 2)
// test also clicking outside delegates => the nearest should be selected
for (let i = 0; i < control.count; ++i) {
let child = control.contentItem.children[i]
let points = [
Qt.point(child.width / 2, -2), // top
Qt.point(-2, child.height / 2), // left
Qt.point(child.width + 2, child.height / 2), // right
Qt.point(child.width / 2, child.height + 2), // bottom
Qt.point(-2, -2), // top-left
Qt.point(child.width + 2, -2), // top-right
Qt.point(-2, child.height + 2), // bottom-left
Qt.point(child.width + 2, child.height + 2), // bottom-right
]
for (let j = 0; j < points.length; ++j) {
control.currentIndex = -1
compare(control.currentIndex, -1)
let point = points[j]
let pos = control.mapFromItem(child, x, y)
if (data.touch)
touch.press(0, control, pos.x, pos.y).commit().release(0, control, pos.x, pos.y).commit()
else
mouseClick(control, pos.x, pos.y, Qt.LeftButton)
compare(control.currentIndex, i)
}
}
}
function test_mouseArea_data() {
return [
{ tag: "interactive", interactive: true },
{ tag: "non-interactive", interactive: false }
]
}
// QTBUG-61785
function test_mouseArea(data) {
let ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height})
verify(ma)
let control = pageIndicator.createObject(ma, {count: 5, interactive: data.interactive, width: testCase.width, height: testCase.height})
verify(control)
compare(control.interactive, data.interactive)
mousePress(control)
compare(ma.pressed, !data.interactive)
mouseRelease(control)
verify(!ma.pressed)
let touch = touchEvent(control)
touch.press(0, control).commit()
compare(ma.pressed, !data.interactive)
touch.release(0, control).commit()
verify(!ma.pressed)
}
}
|