222 test_label->setBuddy( test_edit ); |
226 test_label->setBuddy( test_edit ); |
223 test_label->setFocus(); |
227 test_label->setFocus(); |
224 QVERIFY( !test_edit->hasFocus() ); |
228 QVERIFY( !test_edit->hasFocus() ); |
225 QTest::keyClick( test_box, 't', Qt::AltModifier ); |
229 QTest::keyClick( test_box, 't', Qt::AltModifier ); |
226 QVERIFY( test_edit->hasFocus() ); |
230 QVERIFY( test_edit->hasFocus() ); |
|
231 delete test_box; |
227 } |
232 } |
228 |
233 |
229 void tst_QLabel::text() |
234 void tst_QLabel::text() |
230 { |
235 { |
231 DEPENDS_ON( "setText" ); |
236 DEPENDS_ON( "setText" ); |
243 |
248 |
244 QTest::newRow( QString(prefix + "data0").toLatin1() ) << QString("This is a single line") << QString("Helvetica"); |
249 QTest::newRow( QString(prefix + "data0").toLatin1() ) << QString("This is a single line") << QString("Helvetica"); |
245 QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier"); |
250 QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier"); |
246 QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica"); |
251 QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica"); |
247 QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier"); |
252 QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier"); |
|
253 QTest::newRow( QString(prefix + "data4").toLatin1() ) << QString("I Have a &shortcut") << QString("Helvetica"); |
248 } |
254 } |
249 |
255 |
250 void tst_QLabel::setText() |
256 void tst_QLabel::setText() |
251 { |
257 { |
252 QFETCH( QString, txt ); |
258 QFETCH( QString, txt ); |
326 QTest::addColumn<int>("textInteractionFlags"); |
332 QTest::addColumn<int>("textInteractionFlags"); |
327 QTest::addColumn<int>("focusPolicy"); |
333 QTest::addColumn<int>("focusPolicy"); |
328 QTest::addColumn<bool>("propagation"); |
334 QTest::addColumn<bool>("propagation"); |
329 |
335 |
330 QTest::newRow("plain text1") << QString("plain text") << int(Qt::LinksAccessibleByMouse) << int(Qt::NoFocus) << true; |
336 QTest::newRow("plain text1") << QString("plain text") << int(Qt::LinksAccessibleByMouse) << int(Qt::NoFocus) << true; |
331 QTest::newRow("plain text2") << QString("plain text") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << false; |
337 QTest::newRow("plain text2") << QString("plain text") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << true; |
332 QTest::newRow("plain text3") << QString("plain text") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
338 QTest::newRow("plain text3") << QString("plain text") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
333 QTest::newRow("plain text4") << QString("plain text") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
339 QTest::newRow("plain text4") << QString("plain text") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
334 QTest::newRow("rich text1") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByMouse << (int)Qt::NoFocus << false; |
340 QTest::newRow("rich text1") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByMouse << (int)Qt::NoFocus << true; |
335 QTest::newRow("rich text2") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << false; |
341 QTest::newRow("rich text2") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << true; |
336 QTest::newRow("rich text3") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
342 QTest::newRow("rich text3") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
337 QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
343 QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
338 QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByKeyboard << (int)Qt::StrongFocus << false; |
344 QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByKeyboard << (int)Qt::StrongFocus << true; |
339 |
345 |
340 if (!test_box) |
346 if (!test_box) |
341 test_box = new Widget; |
347 test_box = new Widget; |
342 if (!test_label) |
348 if (!test_label) |
343 test_label = new QLabel(test_box); |
349 test_label = new QLabel(test_box); |
507 QTest::qWaitForWindowShown(&frame); |
513 QTest::qWaitForWindowShown(&frame); |
508 QVERIFY(frame.isVisible()); // was successfully sized and shown |
514 QVERIFY(frame.isVisible()); // was successfully sized and shown |
509 testWidget->show(); |
515 testWidget->show(); |
510 } |
516 } |
511 |
517 |
|
518 void tst_QLabel::mnemonic_data() |
|
519 { |
|
520 QTest::addColumn<QString>("text"); |
|
521 QTest::addColumn<QString>("expectedDocText"); |
|
522 QTest::addColumn<QString>("expectedShortcutCursor"); |
|
523 |
|
524 QTest::newRow("1") << QString("Normal") << QString("Normal") << QString(); |
|
525 QTest::newRow("2") << QString("&Simple") << QString("Simple") << QString("S"); |
|
526 QTest::newRow("3") << QString("Also &simple") << QString("Also simple") << QString("s"); |
|
527 QTest::newRow("4") << QString("&&With &Double &&") << QString("&With Double &") << QString("D"); |
|
528 QTest::newRow("5") << QString("Hep&&Hop") << QString("Hep&Hop") << QString(""); |
|
529 QTest::newRow("6") << QString("Hep&&&Hop") << QString("Hep&Hop") << QString("H"); |
|
530 } |
|
531 |
|
532 |
|
533 void tst_QLabel::mnemonic() |
|
534 { |
|
535 // this test that the mnemonics appears correctly when the label has a text control. |
|
536 |
|
537 QFETCH(QString, text); |
|
538 QFETCH(QString, expectedDocText); |
|
539 QFETCH(QString, expectedShortcutCursor); |
|
540 |
|
541 QWidget w; |
|
542 QHBoxLayout *hbox = new QHBoxLayout; |
|
543 QLabel *lab = new QLabel(text); |
|
544 //lab->setText("plop &plop"); |
|
545 QLineEdit *lineedit = new QLineEdit; |
|
546 lab->setBuddy(lineedit); |
|
547 lab->setTextInteractionFlags(Qt::TextSelectableByMouse); |
|
548 |
|
549 hbox->addWidget(lab); |
|
550 hbox->addWidget(lineedit); |
|
551 hbox->addWidget(new QLineEdit); |
|
552 w.setLayout(hbox); |
|
553 w.show(); |
|
554 QTest::qWaitForWindowShown(&w); |
|
555 |
|
556 QLabelPrivate *d = static_cast<QLabelPrivate *>(QObjectPrivate::get(lab)); |
|
557 QVERIFY(d->control); |
|
558 QCOMPARE(d->control->document()->toPlainText(), expectedDocText); |
|
559 QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); |
|
560 } |
|
561 |
|
562 |
512 QTEST_MAIN(tst_QLabel) |
563 QTEST_MAIN(tst_QLabel) |
513 #include "tst_qlabel.moc" |
564 #include "tst_qlabel.moc" |