diff options
-rw-r--r-- | src/gui/text/qtextdocumentlayout.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qtextdocumentlayout/tst_qtextdocumentlayout.cpp | 21 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index a795c1f..7b36b9d 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -1994,9 +1994,12 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur } } - if (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom) { + bool frameSpansIntoNextPage = (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom); + if (frameSpansIntoNextPage && fd->size.height <= layoutStruct->pageHeight) { layoutStruct->newPage(); y = layoutStruct->y; + + frameSpansIntoNextPage = false; } y = findY(y, layoutStruct, fd->size.width); @@ -2017,6 +2020,11 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur // qDebug()<< "float positioned at " << fd->position.x << fd->position.y; fd->layoutDirty = false; + + // If the frame is a table, then positioning it will affect the size if it covers more than + // one page, because of page breaks and repeating the header. + if (qobject_cast<QTextTable *>(frame) != 0) + fd->sizeDirty = frameSpansIntoNextPage; } QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed parentY) @@ -2349,6 +2357,10 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStru positionFloat(c); + // If the size was made dirty when the position was set, layout again + if (cd->sizeDirty) + updateRect = layoutFrame(c, layoutFrom, layoutTo); + QRectF frameRect(cd->position.toPointF(), cd->size.toSizeF()); if (frameRect == oldFrameRect && updateRect.isValid()) diff --git a/tests/auto/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index d8c4f51..dbba9ef 100644 --- a/tests/auto/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -71,6 +71,7 @@ private slots: void wrapAtWordBoundaryOrAnywhere(); void inlineImage(); void clippedTableCell(); + void floatingTablePageBreak(); private: QTextDocument *doc; @@ -250,5 +251,25 @@ void tst_QTextDocumentLayout::clippedTableCell() QCOMPARE(img, expected); } +void tst_QTextDocumentLayout::floatingTablePageBreak() +{ + doc->clear(); + + QTextCursor cursor(doc); + + QTextTableFormat tableFormat; + tableFormat.setPosition(QTextFrameFormat::FloatLeft); + QTextTable *table = cursor.insertTable(50, 1, tableFormat); + + // Make height of document 2/3 of the table, fitting the table into two pages + QSizeF documentSize = doc->size(); + documentSize.rheight() *= 2.0 / 3.0; + + doc->setPageSize(documentSize); + + QCOMPARE(doc->pageCount(), 2); +} + + QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" |