| 123 | } |
| 124 | |
| 125 | static QSizeF documentNaturalSize(QTextDocument* doc) |
| 126 | { |
| 127 | qreal width = 0; |
| 128 | |
| 129 | // Also forces whole layout to complete |
| 130 | QSizeF fullSize = doc->size(); |
| 131 | |
| 132 | for (QTextBlock b = doc->begin(); b != doc->end(); b = b.next()) { |
| 133 | QTextLayout* tl = b.layout(); |
| 134 | for (int i = 0; i < tl->lineCount(); i++) { |
| 135 | QTextLine line = tl->lineAt(i); |
| 136 | // Need to consider line offsets, for e.g. list bullets (as in `color`) |
| 137 | width = qMax(width, line.naturalTextWidth() + tl->position().x() + line.position().x()); |
| 138 | } |
| 139 | } |
| 140 | return QSizeF { width, fullSize.height() }; |
| 141 | } |
| 142 | |
| 143 | static QSize calculateBrowserSize(QTextDocument* doc, bool& needsScrollBar) |
| 144 | { |
no test coverage detected