summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlabel
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-12 14:34:01 +0100
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-12 14:40:24 +0100
commit037c1c3b3e1abc07f0570336bd7958121f32848a (patch)
treed36de93b4f95b03b462d4064c26587ac4ce5b871 /tests/auto/qlabel
parent65f38e884f40f02be6497819c876013750cce4ea (diff)
QLabel: Fixed text underlined when te label has a control and the text contains &
We need to search for '&' in the text each time the QTextControl's document is updated. Also make sure not to match && Task-number: QTBUG-4154 Reviewed-by: Thierry
Diffstat (limited to 'tests/auto/qlabel')
-rw-r--r--tests/auto/qlabel/tst_qlabel.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qlabel/tst_qlabel.cpp b/tests/auto/qlabel/tst_qlabel.cpp
index 9d957a5b60..6b7e1063a6 100644
--- a/tests/auto/qlabel/tst_qlabel.cpp
+++ b/tests/auto/qlabel/tst_qlabel.cpp
@@ -51,6 +51,7 @@
#include <qmovie.h>
#include <qpicture.h>
#include <qmessagebox.h>
+#include <private/qlabel_p.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -116,6 +117,9 @@ private slots:
void unicodeText_data();
void unicodeText();
+ void mnemonic_data();
+ void mnemonic();
+
private:
QLabel *testWidget;
QPointer<Widget> test_box;
@@ -224,6 +228,7 @@ void tst_QLabel::setBuddy()
QVERIFY( !test_edit->hasFocus() );
QTest::keyClick( test_box, 't', Qt::AltModifier );
QVERIFY( test_edit->hasFocus() );
+ delete test_box;
}
void tst_QLabel::text()
@@ -245,6 +250,7 @@ void tst_QLabel::setText_data()
QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier");
QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica");
QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier");
+ QTest::newRow( QString(prefix + "data4").toLatin1() ) << QString("I Have a &shortcut") << QString("Helvetica");
}
void tst_QLabel::setText()
@@ -509,5 +515,50 @@ void tst_QLabel::unicodeText()
testWidget->show();
}
+void tst_QLabel::mnemonic_data()
+{
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<QString>("expectedDocText");
+ QTest::addColumn<QString>("expectedShortcutCursor");
+
+ QTest::newRow("1") << QString("Normal") << QString("Normal") << QString();
+ QTest::newRow("2") << QString("&Simple") << QString("Simple") << QString("S");
+ QTest::newRow("3") << QString("Also &simple") << QString("Also simple") << QString("s");
+ QTest::newRow("4") << QString("&&With &Double &&amp;") << QString("&With Double &amp;") << QString("D");
+ QTest::newRow("5") << QString("Hep&&Hop") << QString("Hep&Hop") << QString("");
+ QTest::newRow("6") << QString("Hep&&&Hop") << QString("Hep&Hop") << QString("H");
+}
+
+
+void tst_QLabel::mnemonic()
+{
+ // this test that the mnemonics appears correctly when the label has a text control.
+
+ QFETCH(QString, text);
+ QFETCH(QString, expectedDocText);
+ QFETCH(QString, expectedShortcutCursor);
+
+ QWidget w;
+ QHBoxLayout *hbox = new QHBoxLayout;
+ QLabel *lab = new QLabel(text);
+ //lab->setText("plop &plop");
+ QLineEdit *lineedit = new QLineEdit;
+ lab->setBuddy(lineedit);
+ lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ hbox->addWidget(lab);
+ hbox->addWidget(lineedit);
+ hbox->addWidget(new QLineEdit);
+ w.setLayout(hbox);
+ w.show();
+ QTest::qWaitForWindowShown(&w);
+
+ QLabelPrivate *d = static_cast<QLabelPrivate *>(QObjectPrivate::get(lab));
+ QVERIFY(d->control);
+ QCOMPARE(d->control->document()->toPlainText(), expectedDocText);
+ QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor);
+}
+
+
QTEST_MAIN(tst_QLabel)
#include "tst_qlabel.moc"