diff options
Diffstat (limited to 'tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp')
-rw-r--r-- | tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index 01c4005bfe..2ae31849bf 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -24,17 +24,24 @@ private slots: void cleanupTestCase(); void defaultPageSizeHandling(); void idealWidth(); +#ifndef QT_NO_TEXTHTMLPARSER void lineSeparatorFollowingTable(); +#endif #ifndef QT_NO_WIDGETS void wrapAtWordBoundaryOrAnywhere(); #endif void inlineImage(); +#ifndef QT_NO_TEXTHTMLPARSER void clippedTableCell(); +#endif void floatingTablePageBreak(); void imageAtRightAlignedTab(); void blockVisibility(); +#ifndef QT_NO_TEXTHTMLPARSER + void testHitTest(); void largeImage(); +#endif private: QTextDocument *doc; @@ -98,6 +105,7 @@ void tst_QTextDocumentLayout::idealWidth() QVERIFY(doc->idealWidth() > 0); } +#ifndef QT_NO_TEXTHTMLPARSER // none of the QTextLine items in the document should intersect with the margin rect void tst_QTextDocumentLayout::lineSeparatorFollowingTable() { @@ -144,6 +152,7 @@ void tst_QTextDocumentLayout::lineSeparatorFollowingTable() } } } +#endif #ifndef QT_NO_WIDGETS void tst_QTextDocumentLayout::wrapAtWordBoundaryOrAnywhere() @@ -183,6 +192,7 @@ void tst_QTextDocumentLayout::inlineImage() QCOMPARE(doc->pageCount(), 1); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextDocumentLayout::clippedTableCell() { const char *html = @@ -223,6 +233,7 @@ void tst_QTextDocumentLayout::clippedTableCell() expected.save("expected.png"); QCOMPARE(img, expected); } +#endif void tst_QTextDocumentLayout::floatingTablePageBreak() { @@ -322,6 +333,7 @@ void tst_QTextDocumentLayout::blockVisibility() QCOMPARE(doc->size(), halfSize); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextDocumentLayout::largeImage() { auto img = QImage(400, 500, QImage::Format_ARGB32_Premultiplied); @@ -380,5 +392,42 @@ void tst_QTextDocumentLayout::largeImage() } } +void tst_QTextDocumentLayout::testHitTest() +{ + QTextDocument document; + QTextCursor cur(&document); + int topMargin = 20; + + //insert 500 blocks into textedit + for (int i = 0; i < 500; i++) { + cur.insertBlock(); + cur.insertHtml(QString("block %1").arg(i)); + } + + //randomly set half the blocks invisible + QTextBlock blk=document.begin(); + for (int i = 0; i < 500; i++) { + if (i % 7) + blk.setVisible(0); + blk = blk.next(); + } + + //set margin for all blocks (not strictly necessary, but makes easier to click in between blocks) + QTextBlockFormat blkfmt; + blkfmt.setTopMargin(topMargin); + cur.movePosition(QTextCursor::Start); + cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + cur.mergeBlockFormat(blkfmt); + + for (int y = cur.selectionStart(); y < cur.selectionEnd(); y += 10) { + QPoint mousePoint(1, y); + int cursorPos = document.documentLayout()->hitTest(mousePoint, Qt::FuzzyHit); + int positionY = document.findBlock(cursorPos).layout()->position().toPoint().y(); + //mousePoint is in the rect of the current Block + QVERIFY(positionY - topMargin <= y); + } +} +#endif + QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" |