summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-08-24 13:55:51 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-08-24 14:01:50 (GMT)
commitbda6a5e7a8a233dc4b4395aa20b41f74f2c0857a (patch)
treeb6a440b2e50d4bc878305859a3bf6534f669e59d /src/gui
parent9e8b3f2e789e24c561d2f583927ee15b38808941 (diff)
downloadQt-bda6a5e7a8a233dc4b4395aa20b41f74f2c0857a.zip
Qt-bda6a5e7a8a233dc4b4395aa20b41f74f2c0857a.tar.gz
Qt-bda6a5e7a8a233dc4b4395aa20b41f74f2c0857a.tar.bz2
Don't float objects into next page unless they can fit in it
If you had a floating table which spanned over several pages, this would always float down to the next page, even when it was the only element in the document. The main reason why this mechanism was added to positionFloat() was to handle floating images, since they can't be broken down into more than one page. Tables, however, have logic to ensure they are broken into several pages if they are too large for the current page. There is however no reason to float an object into the next page if it is larger than that page. Since the size of tables are altered by their position as long as they span more than one page, we need to set the sizeDirty flag for floating tables when positioning and then relayout the frame to make sure the page breaks are set correctly. Task-number: 240086 Reviewed-by: Simon Hausmann
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp14
1 files changed, 13 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())