summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlabel
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2010-02-02 14:29:11 +0100
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-02-02 14:29:11 +0100
commit42e181a6feba241997b041a2a58903f308264559 (patch)
treed6b0994ce1f73957f0cfea310e21b8ed1ad1ab8c /tests/auto/qlabel
parente9b0c9a1d25a2260bd7c0e7ead840cacb31ce424 (diff)
QLabel: add setSelection, hasSelectedText, selectedText, selectionStart.
When using TextSelectableByMouse or TextSelectableByKeyboard, this allows to programmatically control the selection. Needed in KDE's KSqueezedTextLabel, so that mouseReleaseEvent can get the selection and copy the un-squeezed text instead of the squeezed one. Merge-request: 454 Reviewed-by: Leonardo Sobral Cunha <leo.cunha@nokia.com>
Diffstat (limited to 'tests/auto/qlabel')
-rw-r--r--tests/auto/qlabel/tst_qlabel.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qlabel/tst_qlabel.cpp b/tests/auto/qlabel/tst_qlabel.cpp
index c3af495f1c..7099917836 100644
--- a/tests/auto/qlabel/tst_qlabel.cpp
+++ b/tests/auto/qlabel/tst_qlabel.cpp
@@ -119,6 +119,7 @@ private slots:
void mnemonic_data();
void mnemonic();
+ void selection();
private:
QLabel *testWidget;
@@ -559,6 +560,27 @@ void tst_QLabel::mnemonic()
QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor);
}
+void tst_QLabel::selection()
+{
+ QLabel label;
+ label.setText("Hello world");
+
+ label.setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QVERIFY(!label.hasSelectedText());
+ QCOMPARE(label.selectedText(), QString());
+ QCOMPARE(label.selectionStart(), -1);
+
+ label.setSelection(0, 4);
+ QVERIFY(label.hasSelectedText());
+ QCOMPARE(label.selectedText(), QString::fromLatin1("Hell"));
+ QCOMPARE(label.selectionStart(), 0);
+
+ label.setSelection(6, 5);
+ QVERIFY(label.hasSelectedText());
+ QCOMPARE(label.selectedText(), QString::fromLatin1("world"));
+ QCOMPARE(label.selectionStart(), 6);
+}
QTEST_MAIN(tst_QLabel)
#include "tst_qlabel.moc"