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 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
|
// 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
import QtQuick.Layouts
import Qt.test.controls
TestCase {
id: testCase
width: 400
height: 400
visible: true
when: windowShown
name: "TextField"
Component {
id: textField
TextField { }
}
Component {
id: rectangle
Rectangle { }
}
Component {
id: signalSpy
SignalSpy { }
}
function init() {
failOnWarning(/.?/)
}
function test_creation() {
let control = createTemporaryObject(textField, testCase)
verify(control)
}
function test_implicitSize() {
let control = createTemporaryObject(textField, testCase)
verify(control)
let implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} )
verify(implicitWidthSpy.valid)
let implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} )
verify(implicitHeightSpy.valid)
let implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"})
verify(implicitBackgroundWidthSpy.valid)
let implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"})
verify(implicitBackgroundHeightSpy.valid)
let implicitWidthChanges = 0
let implicitHeightChanges = 0
let implicitBackgroundWidthChanges = 0
let implicitBackgroundHeightChanges = 0
verify(control.implicitWidth >= control.leftPadding + control.rightPadding)
verify(control.implicitHeight >= control.contentHeight + control.topPadding + control.bottomPadding)
compare(control.implicitBackgroundWidth, control.background.implicitWidth)
compare(control.implicitBackgroundHeight, control.background.implicitHeight)
control.background = rectangle.createObject(control, {implicitWidth: 400, implicitHeight: 200})
compare(control.implicitWidth, 400)
compare(control.implicitHeight, 200)
compare(control.implicitBackgroundWidth, 400)
compare(control.implicitBackgroundHeight, 200)
compare(implicitWidthSpy.count, ++implicitWidthChanges)
compare(implicitHeightSpy.count, ++implicitHeightChanges)
compare(implicitBackgroundWidthSpy.count, ++implicitBackgroundWidthChanges)
compare(implicitBackgroundHeightSpy.count, ++implicitBackgroundHeightChanges)
control.background = null
compare(control.implicitWidth, control.leftPadding + control.rightPadding)
compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding)
compare(control.implicitBackgroundWidth, 0)
compare(control.implicitBackgroundHeight, 0)
compare(implicitWidthSpy.count, ++implicitWidthChanges)
compare(implicitHeightSpy.count, ++implicitHeightChanges)
compare(implicitBackgroundWidthSpy.count, ++implicitBackgroundWidthChanges)
compare(implicitBackgroundHeightSpy.count, ++implicitBackgroundHeightChanges)
control.text = "TextField"
compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding)
compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding)
compare(control.implicitBackgroundWidth, 0)
compare(control.implicitBackgroundHeight, 0)
compare(implicitWidthSpy.count, ++implicitWidthChanges)
compare(implicitHeightSpy.count, implicitHeightChanges)
compare(implicitBackgroundWidthSpy.count, implicitBackgroundWidthChanges)
compare(implicitBackgroundHeightSpy.count, implicitBackgroundHeightChanges)
control.placeholderText = "..."
compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding)
compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding)
compare(control.implicitBackgroundWidth, 0)
compare(control.implicitBackgroundHeight, 0)
compare(implicitWidthSpy.count, implicitWidthChanges)
compare(implicitHeightSpy.count, implicitHeightChanges)
compare(implicitBackgroundWidthSpy.count, implicitBackgroundWidthChanges)
compare(implicitBackgroundHeightSpy.count, implicitBackgroundHeightChanges)
}
function test_alignment_data() {
return [
{ tag: "empty", text: "", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "empty,left", text: "", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "empty,center", text: "", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "empty,right", text: "", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "empty,ltr", text: "", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "empty,ltr,left", text: "", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "empty,ltr,center", text: "", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "empty,ltr,right", text: "", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "empty,rtl", text: "", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight },
{ tag: "empty,rtl,left", text: "", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "empty,rtl,center", text: "", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "empty,rtl,right", text: "", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "ltr,empty", text: "Text", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "ltr,empty,left", text: "Text", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "ltr,empty,center", text: "Text", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "ltr,empty,right", text: "Text", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "ltr,ltr", text: "Text", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "ltr,ltr,left", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "ltr,ltr,center", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "ltr,ltr,right", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "ltr,rtl", text: "Text", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight },
{ tag: "ltr,rtl,left", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "ltr,rtl,center", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "ltr,rtl,right", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "rtl,empty", text: "نص", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "rtl,empty,left", text: "نص", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "rtl,empty,center", text: "نص", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "rtl,empty,right", text: "نص", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "rtl,ltr", text: "نص", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft },
{ tag: "rtl,ltr,left", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "rtl,ltr,center", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "rtl,ltr,right", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
{ tag: "rtl,rtl", text: "نص", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight },
{ tag: "rtl,rtl,left", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft },
{ tag: "rtl,rtl,center", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter },
{ tag: "rtl,rtl,right", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight },
]
}
function test_alignment(data) {
let control = createTemporaryObject(textField, testCase, {text: data.text, placeholderText: data.placeholderText})
if (data.textAlignment !== undefined) {
control.horizontalAlignment = data.textAlignment
compare(control.horizontalAlignment, data.textAlignment)
}
// The placeholder text of the Material style doesn't currently respect the alignment of the control.
if (StyleInfo.styleName !== "Material") {
for (let i = 0; i < control.children.length; ++i) {
if (control.children[i].hasOwnProperty("text") && control.children[i].hasOwnProperty("horizontalAlignment"))
compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder
}
}
control.verticalAlignment = TextField.AlignBottom
compare(control.verticalAlignment, TextField.AlignBottom)
if (StyleInfo.styleName !== "Material") {
for (let j = 0; j < control.children.length; ++j) {
if (control.children[j].hasOwnProperty("text") && control.children[j].hasOwnProperty("verticalAlignment"))
compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder
}
}
}
function test_font_explicit_attributes_data() {
return [
{tag: "bold", value: true},
{tag: "capitalization", value: Font.Capitalize},
{tag: "family", value: "Tahoma"},
{tag: "italic", value: true},
{tag: "strikeout", value: true},
{tag: "underline", value: true},
{tag: "weight", value: Font.Black},
{tag: "wordSpacing", value: 55}
]
}
function test_font_explicit_attributes(data) {
let control = createTemporaryObject(textField, testCase)
verify(control)
let child = textField.createObject(control)
verify(child)
let controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"})
verify(controlSpy.valid)
let childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"})
verify(childSpy.valid)
let defaultValue = control.font[data.tag]
child.font[data.tag] = defaultValue
compare(child.font[data.tag], defaultValue)
compare(childSpy.count, 0)
control.font[data.tag] = data.value
compare(control.font[data.tag], data.value)
compare(controlSpy.count, 1)
compare(child.font[data.tag], defaultValue)
compare(childSpy.count, 0)
}
function test_hover_data() {
return [
{ tag: "enabled", hoverEnabled: true },
{ tag: "disabled", hoverEnabled: false },
]
}
function test_hover(data) {
let control = createTemporaryObject(textField, testCase, {hoverEnabled: data.hoverEnabled})
verify(control)
compare(control.hovered, false)
mouseMove(control, control.width / 2, control.height / 2)
compare(control.hovered, data.hoverEnabled)
mouseMove(control, -1, -1)
compare(control.hovered, false)
}
function test_pressedReleased_data() {
return [
{
tag: "pressed outside", x: -1, y: -1, button: Qt.LeftButton,
controlPressEvent: null,
controlReleaseEvent: null,
parentPressEvent: {
x: 0, y: 0, button: Qt.LeftButton, buttons: Qt.LeftButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
parentReleaseEvent: {
x: 0, y: 0, button: Qt.LeftButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
},
{
tag: "left click", x: 0, y: 0, button: Qt.LeftButton,
controlPressEvent: {
x: 0, y: 0, button: Qt.LeftButton, buttons: Qt.LeftButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
controlReleaseEvent: {
x: 0, y: 0, button: Qt.LeftButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
parentPressEvent: null,
parentReleaseEvent: null,
},
{
tag: "right click", x: 0, y: 0, button: Qt.RightButton,
controlPressEvent: {
x: 0, y: 0, button: Qt.RightButton, buttons: Qt.RightButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
controlReleaseEvent: {
x: 0, y: 0, button: Qt.RightButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false
},
parentPressEvent: null,
parentReleaseEvent: null,
},
];
}
Component {
id: mouseAreaComponent
MouseArea {
anchors.fill: parent
}
}
function checkMouseEvent(event, expectedEvent) {
compare(event.x, expectedEvent.x)
compare(event.y, expectedEvent.y)
compare(event.button, expectedEvent.button)
compare(event.buttons, expectedEvent.buttons)
}
function test_pressedReleased(data) {
let mouseArea = createTemporaryObject(mouseAreaComponent, testCase)
verify(mouseArea)
let control = textField.createObject(mouseArea)
verify(control)
// Give enough room to check presses outside of the control and on the parent.
control.x = 1;
control.y = 1;
function checkControlPressEvent(event) {
checkMouseEvent(event, data.controlPressEvent)
}
function checkControlReleaseEvent(event) {
checkMouseEvent(event, data.controlReleaseEvent)
}
function checkParentPressEvent(event) {
checkMouseEvent(event, data.parentPressEvent)
}
function checkParentReleaseEvent(event) {
checkMouseEvent(event, data.parentReleaseEvent)
}
// Can't use signalArguments, because the event won't live that long.
if (data.controlPressEvent)
control.onPressed.connect(checkControlPressEvent)
if (data.controlReleaseEvent)
control.onReleased.connect(checkControlReleaseEvent)
if (data.parentPressEvent)
control.onPressed.connect(checkParentPressEvent)
if (data.parentReleaseEvent)
control.onReleased.connect(checkParentReleaseEvent)
let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" })
verify(controlPressedSpy.valid)
let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" })
verify(controlReleasedSpy.valid)
let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" })
verify(parentPressedSpy.valid)
let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" })
verify(parentReleasedSpy.valid)
mousePress(control, data.x, data.y, data.button)
compare(controlPressedSpy.count, data.controlPressEvent ? 1 : 0)
compare(parentPressedSpy.count, data.parentPressEvent ? 1 : 0)
mouseRelease(control, data.x, data.y, data.button)
compare(controlReleasedSpy.count, data.controlReleaseEvent ? 1 : 0)
compare(parentReleasedSpy.count, data.parentReleaseEvent ? 1 : 0)
}
Component {
id: ignoreTextField
TextField {
property bool ignorePress: false
property bool ignoreRelease: false
onPressed: function (event) { if (ignorePress) event.accepted = false }
onReleased: function (event) { if (ignoreRelease) event.accepted = false }
}
}
function checkEventAccepted(event) {
compare(event.accepted, true)
}
function checkEventIgnored(event) {
compare(event.accepted, false)
}
function test_ignorePressRelease() {
let mouseArea = createTemporaryObject(mouseAreaComponent, testCase)
verify(mouseArea)
let control = ignoreTextField.createObject(mouseArea)
verify(control)
let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" })
verify(controlPressedSpy.valid)
let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" })
verify(controlReleasedSpy.valid)
let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" })
verify(parentPressedSpy.valid)
let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" })
verify(parentReleasedSpy.valid)
// Ignore only press events.
control.onPressed.connect(checkEventIgnored)
control.ignorePress = true
mousePress(control, 0, 0, data.button)
// The control will still get the signal, it just won't accept the event.
compare(controlPressedSpy.count, 1)
compare(parentPressedSpy.count, 1)
mouseRelease(control, 0, 0, data.button)
compare(controlReleasedSpy.count, 0)
compare(parentReleasedSpy.count, 1)
control.onPressed.disconnect(checkEventIgnored)
// Ignore only release events.
control.onPressed.connect(checkEventAccepted)
control.onReleased.connect(checkEventIgnored)
control.ignorePress = false
control.ignoreRelease = true
mousePress(control, 0, 0, data.button)
compare(controlPressedSpy.count, 2)
compare(parentPressedSpy.count, 1)
mouseRelease(control, 0, 0, data.button)
compare(controlReleasedSpy.count, 1)
compare(parentReleasedSpy.count, 1)
control.onPressed.disconnect(checkEventAccepted)
control.onReleased.disconnect(checkEventIgnored)
}
function test_multiClick() {
let control = createTemporaryObject(textField, testCase, {text: "Qt Quick Controls 2 TextArea"})
verify(control)
waitForRendering(control)
control.width = control.contentWidth
let rect = control.positionToRectangle(12)
// double click -> select word
mouseDoubleClickSequence(control, rect.x + rect.width / 2, rect.y + rect.height / 2)
compare(control.selectedText, "Controls")
// tripple click -> select whole line
mouseClick(control, rect.x + rect.width / 2, rect.y + rect.height / 2)
compare(control.selectedText, "Qt Quick Controls 2 TextArea")
}
// QTBUG-64048
function test_rightClick() {
let control = createTemporaryObject(textField, testCase, {text: "TextField"})
verify(control)
control.selectAll()
compare(control.selectedText, "TextField")
mouseClick(control, control.width / 2, control.height / 2, Qt.RightButton)
compare(control.selectedText, "TextField")
mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton | Qt.RightButton)
compare(control.selectedText, "")
}
function test_mouseSelect() {
let control = createTemporaryObject(textField, testCase, {text: "Text", width: parent.width})
verify(control)
verify(control.selectByMouse) // true by default since 6.4
let pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"})
const y = control.height / 2
mousePress(control, 0, y, Qt.LeftButton)
tryCompare(pressSpy, "count", 1)
mouseMove(control, control.implicitWidth, y, 0, Qt.LeftButton)
mouseRelease(control, control.implicitWidth, y, Qt.LeftButton)
tryVerify(function() { return control.selectedText.length > 1 }) // ideally the whole 4-letter word
}
function test_noTouchSelect() {
let control = createTemporaryObject(textField, testCase, {text: "Text"})
verify(control)
verify(control.selectByMouse) // true by default since 6.4
let touch = touchEvent(control)
const y = control.height / 2
touch.press(0, control, 0, y).commit()
touch.move(0, control, control.implicitWidth, 0).commit()
touch.release(0, control)
compare(control.selectedText, "")
}
function test_aaTouchPressAndHold() {
let control = createTemporaryObject(textField, testCase, {text: "Text"})
verify(control)
verify(control.selectByMouse) // true by default since 6.4
let pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"})
let pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"})
let touch = touchEvent(control)
touch.press(0, control).commit()
tryCompare(pressSpy, "count", 1)
tryCompare(pressAndHoldSpy, "count", 1)
touch.release(0, control).commit()
}
// QTBUG-66260
function test_placeholderTextColor() {
let control = createTemporaryObject(textField, testCase)
verify(control)
// usually default value should not be pure opacue black
verify(control.placeholderTextColor !== "#ff000000")
control.placeholderTextColor = "#12345678"
compare(control.placeholderTextColor, "#12345678")
for (let i = 0; i < control.children.length; ++i) {
if (control.children[i].hasOwnProperty("text"))
compare(control.children[i].color, control.placeholderTextColor) // placeholder.color
}
}
function test_inset() {
let control = createTemporaryObject(textField, testCase, {background: rectangle.createObject(testCase)})
verify(control)
let topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"})
verify(topInsetSpy.valid)
let leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"})
verify(leftInsetSpy.valid)
let rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"})
verify(rightInsetSpy.valid)
let bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"})
verify(bottomInsetSpy.valid)
let topInsetChanges = 0
let leftInsetChanges = 0
let rightInsetChanges = 0
let bottomInsetChanges = 0
compare(control.topInset, 0)
compare(control.leftInset, 0)
compare(control.rightInset, 0)
compare(control.bottomInset, 0)
control.width = 100
control.height = 100
compare(control.background.x, 0)
compare(control.background.y, 0)
compare(control.background.width, 100)
compare(control.background.height, 100)
control.topInset = 10
compare(control.topInset, 10)
compare(control.leftInset, 0)
compare(control.rightInset, 0)
compare(control.bottomInset, 0)
compare(topInsetSpy.count, ++topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 0)
compare(control.background.y, 10)
compare(control.background.width, 100)
compare(control.background.height, 90)
control.leftInset = 20
compare(control.topInset, 10)
compare(control.leftInset, 20)
compare(control.rightInset, 0)
compare(control.bottomInset, 0)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, ++leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 20)
compare(control.background.y, 10)
compare(control.background.width, 80)
compare(control.background.height, 90)
control.rightInset = 30
compare(control.topInset, 10)
compare(control.leftInset, 20)
compare(control.rightInset, 30)
compare(control.bottomInset, 0)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, ++rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 20)
compare(control.background.y, 10)
compare(control.background.width, 50)
compare(control.background.height, 90)
control.bottomInset = 40
compare(control.topInset, 10)
compare(control.leftInset, 20)
compare(control.rightInset, 30)
compare(control.bottomInset, 40)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, ++bottomInsetChanges)
compare(control.background.x, 20)
compare(control.background.y, 10)
compare(control.background.width, 50)
compare(control.background.height, 50)
control.topInset = undefined
compare(control.topInset, 0)
compare(control.leftInset, 20)
compare(control.rightInset, 30)
compare(control.bottomInset, 40)
compare(topInsetSpy.count, ++topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 20)
compare(control.background.y, 0)
compare(control.background.width, 50)
compare(control.background.height, 60)
control.leftInset = undefined
compare(control.topInset, 0)
compare(control.leftInset, 0)
compare(control.rightInset, 30)
compare(control.bottomInset, 40)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, ++leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 0)
compare(control.background.y, 0)
compare(control.background.width, 70)
compare(control.background.height, 60)
control.rightInset = undefined
compare(control.topInset, 0)
compare(control.leftInset, 0)
compare(control.rightInset, 0)
compare(control.bottomInset, 40)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, ++rightInsetChanges)
compare(bottomInsetSpy.count, bottomInsetChanges)
compare(control.background.x, 0)
compare(control.background.y, 0)
compare(control.background.width, 100)
compare(control.background.height, 60)
control.bottomInset = undefined
compare(control.topInset, 0)
compare(control.leftInset, 0)
compare(control.rightInset, 0)
compare(control.bottomInset, 0)
compare(topInsetSpy.count, topInsetChanges)
compare(leftInsetSpy.count, leftInsetChanges)
compare(rightInsetSpy.count, rightInsetChanges)
compare(bottomInsetSpy.count, ++bottomInsetChanges)
compare(control.background.x, 0)
compare(control.background.y, 0)
compare(control.background.width, 100)
compare(control.background.height, 100)
}
Component {
id: layoutComponent
ColumnLayout {
anchors.fill: parent
property alias textField: textField
TextField {
id: textField
placeholderText: "Placeholder"
Layout.fillWidth: true
}
}
}
function test_inLayout() {
let layout = createTemporaryObject(layoutComponent, testCase)
verify(layout)
let control = layout.textField
verify(control)
compare(control.width, control.parent.width)
compare(control.background.width, control.width)
}
// QTBUG-95558
Component {
id: textFieldWithPointSizeSet
TextField {
font.pointSize: 24
}
}
Component {
id: textFieldWithPixelSizeSet
TextField {
font.pixelSize: 42
}
}
function test_setPointSizeDoesNotWarn() { // QTBUG-95558
// macOS is special: 43eca45b061fe965fe2a6f1876d4a35a58e3a9e4
if (Qt.platform.os === "osx" || Qt.platform.os === "macos")
skip("TextField hard-codes pixel size on macOS")
let textField = createTemporaryObject(textFieldWithPointSizeSet, testCase)
verify(textField)
}
function test_setPixelSizeDoesNotWarn() {
let textField = createTemporaryObject(textFieldWithPixelSizeSet, testCase)
verify(textField)
}
}
|