From c87dcd9a5df43abc9ee111b0051233a0fe9dd11a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 23 Sep 2011 12:50:44 +0200 Subject: Add some enablers to QTextDocumentLayout Required to access internals used in the layout process, so that we can present the layout in the scenegraph. For instance, the frameBoundingRect() for tables will be the internal bounding rect of the cells. To avoid regressions, I've added a separate function for the outer bounding rect. For now, this is private API, but if it turns out to be useful, the functions can easily be added as virtual to QAbstractTextDocumentLayout. Task-number: QTBUG-20917 Change-Id: I04e07d3850b21f9f0704bf8c8a3ffe97ee5c3fda Reviewed-on: http://codereview.qt-project.org/5539 Reviewed-by: Qt Sanity Bot Reviewed-by: Jiang Jiang --- src/gui/text/qtextdocumentlayout.cpp | 40 ++++++++++++++++++++++++++++++++++++ src/gui/text/qtextdocumentlayout_p.h | 4 +++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 04bdfa8d30..5138aa3e70 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -3136,6 +3136,46 @@ void QTextDocumentLayout::setFixedColumnWidth(int width) d->fixedColumnWidth = width; } +QRectF QTextDocumentLayout::tableCellBoundingRect(QTextTable *table, const QTextTableCell &cell) const +{ + if (!cell.isValid()) + return QRectF(); + + QTextTableData *td = static_cast(data(table)); + + QRectF tableRect = tableBoundingRect(table); + QRectF cellRect = td->cellRect(cell); + + return cellRect.translated(tableRect.topLeft()); +} + +QRectF QTextDocumentLayout::tableBoundingRect(QTextTable *table) const +{ + Q_D(const QTextDocumentLayout); + if (d->docPrivate->pageSize.isNull()) + return QRectF(); + d->ensureLayoutFinished(); + + QPointF pos; + const int framePos = table->firstPosition(); + QTextFrame *f = table; + while (f) { + QTextFrameData *fd = data(f); + pos += fd->position.toPointF(); + + if (f != table) { + if (QTextTable *table = qobject_cast(f)) { + QTextTableCell cell = table->cellAt(framePos); + if (cell.isValid()) + pos += static_cast(fd)->cellPosition(cell).toPointF(); + } + } + + f = f->parentFrame(); + } + return QRectF(pos, data(table)->size.toSizeF()); +} + QRectF QTextDocumentLayout::frameBoundingRect(QTextFrame *frame) const { Q_D(const QTextDocumentLayout); diff --git a/src/gui/text/qtextdocumentlayout_p.h b/src/gui/text/qtextdocumentlayout_p.h index b103d886be..bef4c844f6 100644 --- a/src/gui/text/qtextdocumentlayout_p.h +++ b/src/gui/text/qtextdocumentlayout_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE class QTextListFormat; - +class QTextTableCell; class QTextDocumentLayoutPrivate; class Q_GUI_EXPORT QTextDocumentLayout : public QAbstractTextDocumentLayout @@ -91,6 +91,8 @@ public: virtual QRectF frameBoundingRect(QTextFrame *frame) const; virtual QRectF blockBoundingRect(const QTextBlock &block) const; + QRectF tableBoundingRect(QTextTable *table) const; + QRectF tableCellBoundingRect(QTextTable *table, const QTextTableCell &cell) const; // #### int layoutStatus() const; -- cgit v1.2.3