Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocumentlayout.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | struct QTextLayoutStruct; | - | ||||||||||||||||||
8 | - | |||||||||||||||||||
9 | class QTextFrameData : public QTextFrameLayoutData | - | ||||||||||||||||||
10 | { | - | ||||||||||||||||||
11 | public: | - | ||||||||||||||||||
12 | QTextFrameData(); | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | QFixedPoint position; | - | ||||||||||||||||||
16 | QFixedSize size; | - | ||||||||||||||||||
17 | - | |||||||||||||||||||
18 | - | |||||||||||||||||||
19 | QFixed topMargin; | - | ||||||||||||||||||
20 | QFixed bottomMargin; | - | ||||||||||||||||||
21 | QFixed leftMargin; | - | ||||||||||||||||||
22 | QFixed rightMargin; | - | ||||||||||||||||||
23 | QFixed border; | - | ||||||||||||||||||
24 | QFixed padding; | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | QFixed contentsWidth; | - | ||||||||||||||||||
27 | QFixed contentsHeight; | - | ||||||||||||||||||
28 | QFixed oldContentsWidth; | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | - | |||||||||||||||||||
31 | QFixed effectiveTopMargin; | - | ||||||||||||||||||
32 | QFixed effectiveBottomMargin; | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | QFixed minimumWidth; | - | ||||||||||||||||||
35 | QFixed maximumWidth; | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | QTextLayoutStruct *currentLayoutStruct; | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | bool sizeDirty; | - | ||||||||||||||||||
40 | bool layoutDirty; | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | QVector<QPointer<QTextFrame> > floats; | - | ||||||||||||||||||
43 | }; | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | QTextFrameData::QTextFrameData() | - | ||||||||||||||||||
46 | : maximumWidth((2147483647/256)), | - | ||||||||||||||||||
47 | currentLayoutStruct(0), sizeDirty(true), layoutDirty(true) | - | ||||||||||||||||||
48 | { | - | ||||||||||||||||||
49 | } | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | struct QTextLayoutStruct { | - | ||||||||||||||||||
52 | QTextLayoutStruct() : maximumWidth((2147483647/256)), fullLayout(false) | - | ||||||||||||||||||
53 | {} | - | ||||||||||||||||||
54 | QTextFrame *frame; | - | ||||||||||||||||||
55 | QFixed x_left; | - | ||||||||||||||||||
56 | QFixed x_right; | - | ||||||||||||||||||
57 | QFixed frameY; | - | ||||||||||||||||||
58 | QFixed y; | - | ||||||||||||||||||
59 | QFixed contentsWidth; | - | ||||||||||||||||||
60 | QFixed minimumWidth; | - | ||||||||||||||||||
61 | QFixed maximumWidth; | - | ||||||||||||||||||
62 | bool fullLayout; | - | ||||||||||||||||||
63 | QList<QTextFrame *> pendingFloats; | - | ||||||||||||||||||
64 | QFixed pageHeight; | - | ||||||||||||||||||
65 | QFixed pageBottom; | - | ||||||||||||||||||
66 | QFixed pageTopMargin; | - | ||||||||||||||||||
67 | QFixed pageBottomMargin; | - | ||||||||||||||||||
68 | QRectF updateRect; | - | ||||||||||||||||||
69 | QRectF updateRectForFloats; | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | inline void addUpdateRectForFloat(const QRectF &rect) { | - | ||||||||||||||||||
72 | if (updateRectForFloats.isValid()) | - | ||||||||||||||||||
73 | updateRectForFloats |= rect; | - | ||||||||||||||||||
74 | else | - | ||||||||||||||||||
75 | updateRectForFloats = rect; | - | ||||||||||||||||||
76 | } | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | inline QFixed absoluteY() const | - | ||||||||||||||||||
79 | { return frameY + y; } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | inline int currentPage() const | - | ||||||||||||||||||
82 | { return pageHeight == 0 ? 0 : (absoluteY() / pageHeight).truncate(); } | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | inline void newPage() | - | ||||||||||||||||||
85 | { if (pageHeight == (2147483647/256)) return; pageBottom += pageHeight; y = pageBottom - pageHeight + pageBottomMargin + pageTopMargin - frameY; } | - | ||||||||||||||||||
86 | }; | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | class QTextTableData : public QTextFrameData | - | ||||||||||||||||||
89 | { | - | ||||||||||||||||||
90 | public: | - | ||||||||||||||||||
91 | QFixed cellSpacing, cellPadding; | - | ||||||||||||||||||
92 | qreal deviceScale; | - | ||||||||||||||||||
93 | QVector<QFixed> minWidths; | - | ||||||||||||||||||
94 | QVector<QFixed> maxWidths; | - | ||||||||||||||||||
95 | QVector<QFixed> widths; | - | ||||||||||||||||||
96 | QVector<QFixed> heights; | - | ||||||||||||||||||
97 | QVector<QFixed> columnPositions; | - | ||||||||||||||||||
98 | QVector<QFixed> rowPositions; | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | QVector<QFixed> cellVerticalOffsets; | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | QFixed headerHeight; | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | - | |||||||||||||||||||
105 | - | |||||||||||||||||||
106 | QMultiHash<int, QTextFrame *> childFrameMap; | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | inline QFixed cellWidth(int column, int colspan) const | - | ||||||||||||||||||
109 | { return columnPositions.at(column + colspan - 1) + widths.at(column + colspan - 1) | - | ||||||||||||||||||
110 | - columnPositions.at(column); } | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | inline void calcRowPosition(int row) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | if (row > 0) | - | ||||||||||||||||||
115 | rowPositions[row] = rowPositions.at(row - 1) + heights.at(row - 1) + border + cellSpacing + border; | - | ||||||||||||||||||
116 | } | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | QRectF cellRect(const QTextTableCell &cell) const; | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | inline QFixed paddingProperty(const QTextFormat &format, QTextFormat::Property property) const | - | ||||||||||||||||||
121 | { | - | ||||||||||||||||||
122 | QVariant v = format.property(property); | - | ||||||||||||||||||
123 | if (v.isNull()) { | - | ||||||||||||||||||
124 | return cellPadding; | - | ||||||||||||||||||
125 | } else { | - | ||||||||||||||||||
126 | ((!(v.userType() == QVariant::Double || v.userType() == QMetaType::Float)) ? qt_assert("v.userType() == QVariant::Double || v.userType() == QMetaType::Float",__FILE__,193199) : qt_noop()); | - | ||||||||||||||||||
127 | return QFixed::fromReal(v.toReal() * deviceScale); | - | ||||||||||||||||||
128 | } | - | ||||||||||||||||||
129 | } | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | inline QFixed topPadding(const QTextFormat &format) const | - | ||||||||||||||||||
132 | { | - | ||||||||||||||||||
133 | return paddingProperty(format, QTextFormat::TableCellTopPadding); | - | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | inline QFixed bottomPadding(const QTextFormat &format) const | - | ||||||||||||||||||
137 | { | - | ||||||||||||||||||
138 | return paddingProperty(format, QTextFormat::TableCellBottomPadding); | - | ||||||||||||||||||
139 | } | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | inline QFixed leftPadding(const QTextFormat &format) const | - | ||||||||||||||||||
142 | { | - | ||||||||||||||||||
143 | return paddingProperty(format, QTextFormat::TableCellLeftPadding); | - | ||||||||||||||||||
144 | } | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | inline QFixed rightPadding(const QTextFormat &format) const | - | ||||||||||||||||||
147 | { | - | ||||||||||||||||||
148 | return paddingProperty(format, QTextFormat::TableCellRightPadding); | - | ||||||||||||||||||
149 | } | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | inline QFixedPoint cellPosition(const QTextTableCell &cell) const | - | ||||||||||||||||||
152 | { | - | ||||||||||||||||||
153 | const QTextFormat fmt = cell.format(); | - | ||||||||||||||||||
154 | return cellPosition(cell.row(), cell.column()) + QFixedPoint(leftPadding(fmt), topPadding(fmt)); | - | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | void updateTableSize(); | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | private: | - | ||||||||||||||||||
160 | inline QFixedPoint cellPosition(int row, int col) const | - | ||||||||||||||||||
161 | { return QFixedPoint(columnPositions.at(col), rowPositions.at(row) + cellVerticalOffsets.at(col + row * widths.size())); } | - | ||||||||||||||||||
162 | }; | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | static QTextFrameData *createData(QTextFrame *f) | - | ||||||||||||||||||
165 | { | - | ||||||||||||||||||
166 | QTextFrameData *data; | - | ||||||||||||||||||
167 | if (qobject_cast<QTextTable *>(f)) | - | ||||||||||||||||||
168 | data = new QTextTableData; | - | ||||||||||||||||||
169 | else | - | ||||||||||||||||||
170 | data = new QTextFrameData; | - | ||||||||||||||||||
171 | f->setLayoutData(data); | - | ||||||||||||||||||
172 | return data; | - | ||||||||||||||||||
173 | } | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | static inline QTextFrameData *data(QTextFrame *f) | - | ||||||||||||||||||
176 | { | - | ||||||||||||||||||
177 | QTextFrameData *data = static_cast<QTextFrameData *>(f->layoutData()); | - | ||||||||||||||||||
178 | if (!data) | - | ||||||||||||||||||
179 | data = createData(f); | - | ||||||||||||||||||
180 | return data; | - | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | static bool isFrameFromInlineObject(QTextFrame *f) | - | ||||||||||||||||||
184 | { | - | ||||||||||||||||||
185 | return f->firstPosition() > f->lastPosition(); | - | ||||||||||||||||||
186 | } | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | void QTextTableData::updateTableSize() | - | ||||||||||||||||||
189 | { | - | ||||||||||||||||||
190 | const QFixed effectiveTopMargin = this->topMargin + border + padding; | - | ||||||||||||||||||
191 | const QFixed effectiveBottomMargin = this->bottomMargin + border + padding; | - | ||||||||||||||||||
192 | const QFixed effectiveLeftMargin = this->leftMargin + border + padding; | - | ||||||||||||||||||
193 | const QFixed effectiveRightMargin = this->rightMargin + border + padding; | - | ||||||||||||||||||
194 | size.height = contentsHeight == -1
| 0 | ||||||||||||||||||
195 | ? rowPositions.lastconstLast() + heights.lastconstLast() + padding + border + cellSpacing + effectiveBottomMargin | - | ||||||||||||||||||
196 | : effectiveTopMargin + contentsHeight + effectiveBottomMargin; | - | ||||||||||||||||||
197 | size.width = effectiveLeftMargin + contentsWidth + effectiveRightMargin; | - | ||||||||||||||||||
198 | } never executed: end of block | 0 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | QRectF QTextTableData::cellRect(const QTextTableCell &cell) const | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | const int row = cell.row(); | - | ||||||||||||||||||
203 | const int rowSpan = cell.rowSpan(); | - | ||||||||||||||||||
204 | const int column = cell.column(); | - | ||||||||||||||||||
205 | const int colSpan = cell.columnSpan(); | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | return QRectF(columnPositions.at(column).toReal(), | - | ||||||||||||||||||
208 | rowPositions.at(row).toReal(), | - | ||||||||||||||||||
209 | (columnPositions.at(column + colSpan - 1) + widths.at(column + colSpan - 1) - columnPositions.at(column)).toReal(), | - | ||||||||||||||||||
210 | (rowPositions.at(row + rowSpan - 1) + heights.at(row + rowSpan - 1) - rowPositions.at(row)).toReal()); | - | ||||||||||||||||||
211 | } | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | static inline bool isEmptyBlockBeforeTable(const QTextBlock &block, const QTextBlockFormat &format, const QTextFrame::Iterator &nextIt) | - | ||||||||||||||||||
214 | { | - | ||||||||||||||||||
215 | return !nextIt.atEnd() | - | ||||||||||||||||||
216 | && qobject_cast<QTextTable *>(nextIt.currentFrame()) | - | ||||||||||||||||||
217 | && block.isValid() | - | ||||||||||||||||||
218 | && block.length() == 1 | - | ||||||||||||||||||
219 | && !format.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth) | - | ||||||||||||||||||
220 | && !format.hasProperty(QTextFormat::BackgroundBrush) | - | ||||||||||||||||||
221 | && nextIt.currentFrame()->firstPosition() == block.position() + 1 | - | ||||||||||||||||||
222 | ; | - | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | static inline bool isEmptyBlockBeforeTable(QTextFrame::Iterator it) | - | ||||||||||||||||||
226 | { | - | ||||||||||||||||||
227 | QTextFrame::Iterator next = it; ++next; | - | ||||||||||||||||||
228 | if (it.currentFrame()) | - | ||||||||||||||||||
229 | return false; | - | ||||||||||||||||||
230 | QTextBlock block = it.currentBlock(); | - | ||||||||||||||||||
231 | return isEmptyBlockBeforeTable(block, block.blockFormat(), next); | - | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | static inline bool isEmptyBlockAfterTable(const QTextBlock &block, const QTextFrame *previousFrame) | - | ||||||||||||||||||
235 | { | - | ||||||||||||||||||
236 | return qobject_cast<const QTextTable *>(previousFrame) | - | ||||||||||||||||||
237 | && block.isValid() | - | ||||||||||||||||||
238 | && block.length() == 1 | - | ||||||||||||||||||
239 | && previousFrame->lastPosition() == block.position() - 1 | - | ||||||||||||||||||
240 | ; | - | ||||||||||||||||||
241 | } | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | static inline bool isLineSeparatorBlockAfterTable(const QTextBlock &block, const QTextFrame *previousFrame) | - | ||||||||||||||||||
244 | { | - | ||||||||||||||||||
245 | return qobject_cast<const QTextTable *>(previousFrame) | - | ||||||||||||||||||
246 | && block.isValid() | - | ||||||||||||||||||
247 | && block.length() > 1 | - | ||||||||||||||||||
248 | && block.text().at(0) == QChar::LineSeparator | - | ||||||||||||||||||
249 | && previousFrame->lastPosition() == block.position() - 1 | - | ||||||||||||||||||
250 | ; | - | ||||||||||||||||||
251 | } | - | ||||||||||||||||||
252 | struct QCheckPoint | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | QFixed y; | - | ||||||||||||||||||
255 | QFixed frameY; | - | ||||||||||||||||||
256 | int positionInFrame; | - | ||||||||||||||||||
257 | QFixed minimumWidth; | - | ||||||||||||||||||
258 | QFixed maximumWidth; | - | ||||||||||||||||||
259 | QFixed contentsWidth; | - | ||||||||||||||||||
260 | }; | - | ||||||||||||||||||
261 | template<> class QTypeInfo<QCheckPoint > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QCheckPoint)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QCheckPoint >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QCheckPoint) }; static inline const char *name() { return "QCheckPoint"; } }; | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | static bool operator<(const QCheckPoint &checkPoint, QFixed y) | - | ||||||||||||||||||
264 | { | - | ||||||||||||||||||
265 | return checkPoint.y < y; | - | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | static bool operator<(const QCheckPoint &checkPoint, int pos) | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | return checkPoint.positionInFrame < pos; | - | ||||||||||||||||||
271 | } | - | ||||||||||||||||||
272 | static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const QPointF &origin, QRectF gradientRect = QRectF()) | - | ||||||||||||||||||
273 | { | - | ||||||||||||||||||
274 | p->save(); | - | ||||||||||||||||||
275 | if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) { | - | ||||||||||||||||||
276 | if (!gradientRect.isNull()) { | - | ||||||||||||||||||
277 | QTransform m; | - | ||||||||||||||||||
278 | m.translate(gradientRect.left(), gradientRect.top()); | - | ||||||||||||||||||
279 | m.scale(gradientRect.width(), gradientRect.height()); | - | ||||||||||||||||||
280 | brush.setTransform(m); | - | ||||||||||||||||||
281 | const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode); | - | ||||||||||||||||||
282 | } | - | ||||||||||||||||||
283 | } else { | - | ||||||||||||||||||
284 | p->setBrushOrigin(origin); | - | ||||||||||||||||||
285 | } | - | ||||||||||||||||||
286 | p->fillRect(rect, brush); | - | ||||||||||||||||||
287 | p->restore(); | - | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | class QTextDocumentLayoutPrivate : public QAbstractTextDocumentLayoutPrivate | - | ||||||||||||||||||
291 | { | - | ||||||||||||||||||
292 | inline QTextDocumentLayout* q_func() { return static_cast<QTextDocumentLayout *>(q_ptr); } inline const QTextDocumentLayout* q_func() const { return static_cast<const QTextDocumentLayout *>(q_ptr); } friend class QTextDocumentLayout; | - | ||||||||||||||||||
293 | public: | - | ||||||||||||||||||
294 | QTextDocumentLayoutPrivate(); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | QTextOption::WrapMode wordWrapMode; | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | - | |||||||||||||||||||
299 | - | |||||||||||||||||||
300 | - | |||||||||||||||||||
301 | int fixedColumnWidth; | - | ||||||||||||||||||
302 | int cursorWidth; | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | QSizeF lastReportedSize; | - | ||||||||||||||||||
305 | QRectF viewportRect; | - | ||||||||||||||||||
306 | QRectF clipRect; | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | mutable int currentLazyLayoutPosition; | - | ||||||||||||||||||
309 | mutable int lazyLayoutStepSize; | - | ||||||||||||||||||
310 | QBasicTimer layoutTimer; | - | ||||||||||||||||||
311 | mutable QBasicTimer sizeChangedTimer; | - | ||||||||||||||||||
312 | uint showLayoutProgress : 1; | - | ||||||||||||||||||
313 | uint insideDocumentChange : 1; | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | int lastPageCount; | - | ||||||||||||||||||
316 | qreal idealWidth; | - | ||||||||||||||||||
317 | bool contentHasAlignment; | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | QFixed blockIndent(const QTextBlockFormat &blockFormat) const; | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | void drawFrame(const QPointF &offset, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
322 | QTextFrame *f) const; | - | ||||||||||||||||||
323 | void drawFlow(const QPointF &offset, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
324 | QTextFrame::Iterator it, const QList<QTextFrame *> &floats, QTextBlock *cursorBlockNeedingRepaint) const; | - | ||||||||||||||||||
325 | void drawBlock(const QPointF &offset, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
326 | const QTextBlock &bl, bool inRootFrame) const; | - | ||||||||||||||||||
327 | void drawListItem(const QPointF &offset, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
328 | const QTextBlock &bl, const QTextCharFormat *selectionFormat) const; | - | ||||||||||||||||||
329 | void drawTableCell(const QRectF &cellRect, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &cell_context, | - | ||||||||||||||||||
330 | QTextTable *table, QTextTableData *td, int r, int c, | - | ||||||||||||||||||
331 | QTextBlock *cursorBlockNeedingRepaint, QPointF *cursorBlockOffset) const; | - | ||||||||||||||||||
332 | void drawBorder(QPainter *painter, const QRectF &rect, qreal topMargin, qreal bottomMargin, qreal border, | - | ||||||||||||||||||
333 | const QBrush &brush, QTextFrameFormat::BorderStyle style) const; | - | ||||||||||||||||||
334 | void drawFrameDecoration(QPainter *painter, QTextFrame *frame, QTextFrameData *fd, const QRectF &clip, const QRectF &rect) const; | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | enum HitPoint { | - | ||||||||||||||||||
337 | PointBefore, | - | ||||||||||||||||||
338 | PointAfter, | - | ||||||||||||||||||
339 | PointInside, | - | ||||||||||||||||||
340 | PointExact | - | ||||||||||||||||||
341 | }; | - | ||||||||||||||||||
342 | HitPoint hitTest(QTextFrame *frame, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; | - | ||||||||||||||||||
343 | HitPoint hitTest(QTextFrame::Iterator it, HitPoint hit, const QFixedPoint &p, | - | ||||||||||||||||||
344 | int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; | - | ||||||||||||||||||
345 | HitPoint hitTest(QTextTable *table, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; | - | ||||||||||||||||||
346 | HitPoint hitTest(const QTextBlock &bl, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | QTextLayoutStruct layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, | - | ||||||||||||||||||
349 | int layoutFrom, int layoutTo, QTextTableData *tableData, QFixed absoluteTableY, | - | ||||||||||||||||||
350 | bool withPageBreaks); | - | ||||||||||||||||||
351 | void setCellPosition(QTextTable *t, const QTextTableCell &cell, const QPointF &pos); | - | ||||||||||||||||||
352 | QRectF layoutTable(QTextTable *t, int layoutFrom, int layoutTo, QFixed parentY); | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | void positionFloat(QTextFrame *frame, QTextLine *currentLine = 0); | - | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | - | |||||||||||||||||||
357 | QRectF layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed parentY = 0); | - | ||||||||||||||||||
358 | QRectF layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed frameWidth, QFixed frameHeight, QFixed parentY = 0); | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | void layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, | - | ||||||||||||||||||
361 | QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat); | - | ||||||||||||||||||
362 | void layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width = 0); | - | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | void floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const; | - | ||||||||||||||||||
365 | QFixed findY(QFixed yFrom, const QTextLayoutStruct *layoutStruct, QFixed requiredWidth) const; | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | QVector<QCheckPoint> checkPoints; | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | QTextFrame::Iterator frameIteratorForYPosition(QFixed y) const; | - | ||||||||||||||||||
370 | QTextFrame::Iterator frameIteratorForTextPosition(int position) const; | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | void ensureLayouted(QFixed y) const; | - | ||||||||||||||||||
373 | void ensureLayoutedByPosition(int position) const; | - | ||||||||||||||||||
374 | inline void ensureLayoutFinished() const | - | ||||||||||||||||||
375 | { ensureLayoutedByPosition(2147483647); } | - | ||||||||||||||||||
376 | void layoutStep() const; | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | QRectF frameBoundingRectInternal(QTextFrame *frame) const; | - | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | qreal scaleToDevice(qreal value) const; | - | ||||||||||||||||||
381 | QFixed scaleToDevice(QFixed value) const; | - | ||||||||||||||||||
382 | }; | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | QTextDocumentLayoutPrivate::QTextDocumentLayoutPrivate() | - | ||||||||||||||||||
385 | : fixedColumnWidth(-1), | - | ||||||||||||||||||
386 | cursorWidth(1), | - | ||||||||||||||||||
387 | currentLazyLayoutPosition(-1), | - | ||||||||||||||||||
388 | lazyLayoutStepSize(1000), | - | ||||||||||||||||||
389 | lastPageCount(-1) | - | ||||||||||||||||||
390 | { | - | ||||||||||||||||||
391 | showLayoutProgress = true; | - | ||||||||||||||||||
392 | insideDocumentChange = false; | - | ||||||||||||||||||
393 | idealWidth = 0; | - | ||||||||||||||||||
394 | contentHasAlignment = false; | - | ||||||||||||||||||
395 | } | - | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | QTextFrame::Iterator QTextDocumentLayoutPrivate::frameIteratorForYPosition(QFixed y) const | - | ||||||||||||||||||
398 | { | - | ||||||||||||||||||
399 | QTextFrame *rootFrame = document->rootFrame(); | - | ||||||||||||||||||
400 | - | |||||||||||||||||||
401 | if (checkPoints.isEmpty() | - | ||||||||||||||||||
402 | || y < 0 || y > data(rootFrame)->size.height) | - | ||||||||||||||||||
403 | return rootFrame->begin(); | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | QVector<QCheckPoint>::ConstIterator checkPoint = std::lower_bound(checkPoints.begin(), checkPoints.end(), y); | - | ||||||||||||||||||
406 | if (checkPoint == checkPoints.end()) | - | ||||||||||||||||||
407 | return rootFrame->begin(); | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | if (checkPoint != checkPoints.begin()) | - | ||||||||||||||||||
410 | --checkPoint; | - | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | const int position = rootFrame->firstPosition() + checkPoint->positionInFrame; | - | ||||||||||||||||||
413 | return frameIteratorForTextPosition(position); | - | ||||||||||||||||||
414 | } | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | QTextFrame::Iterator QTextDocumentLayoutPrivate::frameIteratorForTextPosition(int position) const | - | ||||||||||||||||||
417 | { | - | ||||||||||||||||||
418 | QTextFrame *rootFrame = docPrivate->rootFrame(); | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | const QTextDocumentPrivate::BlockMap &map = docPrivate->blockMap(); | - | ||||||||||||||||||
421 | const int begin = map.findNode(rootFrame->firstPosition()); | - | ||||||||||||||||||
422 | const int end = map.findNode(rootFrame->lastPosition()+1); | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | const int block = map.findNode(position); | - | ||||||||||||||||||
425 | const int blockPos = map.position(block); | - | ||||||||||||||||||
426 | - | |||||||||||||||||||
427 | QTextFrame::iterator it(rootFrame, block, begin, end); | - | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | QTextFrame *containingFrame = docPrivate->frameAt(blockPos); | - | ||||||||||||||||||
430 | if (containingFrame != rootFrame) { | - | ||||||||||||||||||
431 | while (containingFrame->parentFrame() != rootFrame) { | - | ||||||||||||||||||
432 | containingFrame = containingFrame->parentFrame(); | - | ||||||||||||||||||
433 | ((!(containingFrame)) ? qt_assert("containingFrame",__FILE__,577583) : qt_noop()); | - | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | it.cf = containingFrame; | - | ||||||||||||||||||
437 | it.cb = 0; | - | ||||||||||||||||||
438 | } | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | return it; | - | ||||||||||||||||||
441 | } | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | QTextDocumentLayoutPrivate::HitPoint | - | ||||||||||||||||||
444 | QTextDocumentLayoutPrivate::hitTest(QTextFrame *frame, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | if (fd->layoutDirty) | - | ||||||||||||||||||
449 | return PointAfter; | - | ||||||||||||||||||
450 | ((!(!fd->layoutDirty)) ? qt_assert("!fd->layoutDirty",__FILE__,594600) : qt_noop()); | - | ||||||||||||||||||
451 | ((!(!fd->sizeDirty)) ? qt_assert("!fd->sizeDirty",__FILE__,595601) : qt_noop()); | - | ||||||||||||||||||
452 | const QFixedPoint relativePoint(point.x - fd->position.x, point.y - fd->position.y); | - | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | QTextFrame *rootFrame = docPrivate->rootFrame(); | - | ||||||||||||||||||
455 | - | |||||||||||||||||||
456 | - | |||||||||||||||||||
457 | - | |||||||||||||||||||
458 | if (frame != rootFrame) { | - | ||||||||||||||||||
459 | if (relativePoint.y < 0 || relativePoint.x < 0) { | - | ||||||||||||||||||
460 | *position = frame->firstPosition() - 1; | - | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | return PointBefore; | - | ||||||||||||||||||
463 | } else if (relativePoint.y > fd->size.height || relativePoint.x > fd->size.width) { | - | ||||||||||||||||||
464 | *position = frame->lastPosition() + 1; | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | return PointAfter; | - | ||||||||||||||||||
467 | } | - | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | if (isFrameFromInlineObject(frame)) { | - | ||||||||||||||||||
471 | *position = frame->firstPosition() - 1; | - | ||||||||||||||||||
472 | return PointExact; | - | ||||||||||||||||||
473 | } | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | if (QTextTable *table = qobject_cast<QTextTable *>(frame)) { | - | ||||||||||||||||||
476 | const int rows = table->rows(); | - | ||||||||||||||||||
477 | const int columns = table->columns(); | - | ||||||||||||||||||
478 | QTextTableData *td = static_cast<QTextTableData *>(data(table)); | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | if (!td->childFrameMap.isEmpty()) { | - | ||||||||||||||||||
481 | for (int r = 0; r < rows; ++r) { | - | ||||||||||||||||||
482 | for (int c = 0; c < columns; ++c) { | - | ||||||||||||||||||
483 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
484 | if (cell.row() != r || cell.column() != c) | - | ||||||||||||||||||
485 | continue; | - | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | QRectF cellRect = td->cellRect(cell); | - | ||||||||||||||||||
488 | const QFixedPoint cellPos = QFixedPoint::fromPointF(cellRect.topLeft()); | - | ||||||||||||||||||
489 | const QFixedPoint pointInCell = relativePoint - cellPos; | - | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | const QList<QTextFrame *> childFrames = td->childFrameMap.values(r + c * rows); | - | ||||||||||||||||||
492 | for (int i = 0; i < childFrames.size(); ++i) { | - | ||||||||||||||||||
493 | QTextFrame *child = childFrames.at(i); | - | ||||||||||||||||||
494 | if (isFrameFromInlineObject(child) | - | ||||||||||||||||||
495 | && child->frameFormat().position() != QTextFrameFormat::InFlow | - | ||||||||||||||||||
496 | && hitTest(child, pointInCell, position, l, accuracy) == PointExact) | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | return PointExact; | - | ||||||||||||||||||
499 | } | - | ||||||||||||||||||
500 | } | - | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | } | - | ||||||||||||||||||
503 | } | - | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | return hitTest(table, relativePoint, position, l, accuracy); | - | ||||||||||||||||||
506 | } | - | ||||||||||||||||||
507 | - | |||||||||||||||||||
508 | const QList<QTextFrame *> childFrames = frame->childFrames(); | - | ||||||||||||||||||
509 | for (int i = 0; i < childFrames.size(); ++i) { | - | ||||||||||||||||||
510 | QTextFrame *child = childFrames.at(i); | - | ||||||||||||||||||
511 | if (isFrameFromInlineObject(child) | - | ||||||||||||||||||
512 | && child->frameFormat().position() != QTextFrameFormat::InFlow | - | ||||||||||||||||||
513 | && hitTest(child, relativePoint, position, l, accuracy) == PointExact) | - | ||||||||||||||||||
514 | { | - | ||||||||||||||||||
515 | return PointExact; | - | ||||||||||||||||||
516 | } | - | ||||||||||||||||||
517 | } | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | QTextFrame::Iterator it = frame->begin(); | - | ||||||||||||||||||
520 | - | |||||||||||||||||||
521 | if (frame == rootFrame) { | - | ||||||||||||||||||
522 | it = frameIteratorForYPosition(relativePoint.y); | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | ((!(it.parentFrame() == frame)) ? qt_assert("it.parentFrame() == frame",__FILE__,668674) : qt_noop()); | - | ||||||||||||||||||
525 | } | - | ||||||||||||||||||
526 | - | |||||||||||||||||||
527 | if (it.currentFrame()) | - | ||||||||||||||||||
528 | *position = it.currentFrame()->firstPosition(); | - | ||||||||||||||||||
529 | else | - | ||||||||||||||||||
530 | *position = it.currentBlock().position(); | - | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | return hitTest(it, PointBefore, relativePoint, position, l, accuracy); | - | ||||||||||||||||||
533 | } | - | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | QTextDocumentLayoutPrivate::HitPoint | - | ||||||||||||||||||
536 | QTextDocumentLayoutPrivate::hitTest(QTextFrame::Iterator it, HitPoint hit, const QFixedPoint &p, | - | ||||||||||||||||||
537 | int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||
538 | { | - | ||||||||||||||||||
539 | do {} while(0); | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | for (; !it.atEnd(); ++it) { | - | ||||||||||||||||||
542 | QTextFrame *c = it.currentFrame(); | - | ||||||||||||||||||
543 | HitPoint hp; | - | ||||||||||||||||||
544 | int pos = -1; | - | ||||||||||||||||||
545 | if (c) { | - | ||||||||||||||||||
546 | hp = hitTest(c, p, &pos, l, accuracy); | - | ||||||||||||||||||
547 | } else { | - | ||||||||||||||||||
548 | hp = hitTest(it.currentBlock(), p, &pos, l, accuracy); | - | ||||||||||||||||||
549 | } | - | ||||||||||||||||||
550 | if (hp >= PointInside) { | - | ||||||||||||||||||
551 | if (isEmptyBlockBeforeTable(it)) | - | ||||||||||||||||||
552 | continue; | - | ||||||||||||||||||
553 | hit = hp; | - | ||||||||||||||||||
554 | *position = pos; | - | ||||||||||||||||||
555 | break; | - | ||||||||||||||||||
556 | } | - | ||||||||||||||||||
557 | if (hp == PointBefore && pos < *position) { | - | ||||||||||||||||||
558 | *position = pos; | - | ||||||||||||||||||
559 | hit = hp; | - | ||||||||||||||||||
560 | } else if (hp == PointAfter && pos > *position) { | - | ||||||||||||||||||
561 | *position = pos; | - | ||||||||||||||||||
562 | hit = hp; | - | ||||||||||||||||||
563 | } | - | ||||||||||||||||||
564 | } | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | do {} while(0); | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | return hit; | - | ||||||||||||||||||
569 | } | - | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | QTextDocumentLayoutPrivate::HitPoint | - | ||||||||||||||||||
572 | QTextDocumentLayoutPrivate::hitTest(QTextTable *table, const QFixedPoint &point, | - | ||||||||||||||||||
573 | int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||
574 | { | - | ||||||||||||||||||
575 | QTextTableData *td = static_cast<QTextTableData *>(data(table)); | - | ||||||||||||||||||
576 | - | |||||||||||||||||||
577 | QVector<QFixed>::ConstIterator rowIt = std::lower_bound(td->rowPositions.constBegin(), td->rowPositions.constEnd(), point.y); | - | ||||||||||||||||||
578 | if (rowIt == td->rowPositions.constEnd()) { | - | ||||||||||||||||||
579 | rowIt = td->rowPositions.constEnd() - 1; | - | ||||||||||||||||||
580 | } else if (rowIt != td->rowPositions.constBegin()) { | - | ||||||||||||||||||
581 | --rowIt; | - | ||||||||||||||||||
582 | } | - | ||||||||||||||||||
583 | - | |||||||||||||||||||
584 | QVector<QFixed>::ConstIterator colIt = std::lower_bound(td->columnPositions.constBegin(), td->columnPositions.constEnd(), point.x); | - | ||||||||||||||||||
585 | if (colIt == td->columnPositions.constEnd()) { | - | ||||||||||||||||||
586 | colIt = td->columnPositions.constEnd() - 1; | - | ||||||||||||||||||
587 | } else if (colIt != td->columnPositions.constBegin()) { | - | ||||||||||||||||||
588 | --colIt; | - | ||||||||||||||||||
589 | } | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | QTextTableCell cell = table->cellAt(rowIt - td->rowPositions.constBegin(), | - | ||||||||||||||||||
592 | colIt - td->columnPositions.constBegin()); | - | ||||||||||||||||||
593 | if (!cell.isValid()) | - | ||||||||||||||||||
594 | return PointBefore; | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | *position = cell.firstPosition(); | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | HitPoint hp = hitTest(cell.begin(), PointInside, point - td->cellPosition(cell), position, l, accuracy); | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | if (hp == PointExact) | - | ||||||||||||||||||
601 | return hp; | - | ||||||||||||||||||
602 | if (hp == PointAfter) | - | ||||||||||||||||||
603 | *position = cell.lastPosition(); | - | ||||||||||||||||||
604 | return PointInside; | - | ||||||||||||||||||
605 | } | - | ||||||||||||||||||
606 | - | |||||||||||||||||||
607 | QTextDocumentLayoutPrivate::HitPoint | - | ||||||||||||||||||
608 | QTextDocumentLayoutPrivate::hitTest(const QTextBlock &bl, const QFixedPoint &point, int *position, QTextLayout **l, | - | ||||||||||||||||||
609 | Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||
610 | { | - | ||||||||||||||||||
611 | QTextLayout *tl = bl.layout(); | - | ||||||||||||||||||
612 | QRectF textrect = tl->boundingRect(); | - | ||||||||||||||||||
613 | textrect.translate(tl->position()); | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | - | |||||||||||||||||||
616 | *position = bl.position(); | - | ||||||||||||||||||
617 | if (point.y.toReal() < textrect.top()) { | - | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | return PointBefore; | - | ||||||||||||||||||
620 | } else if (point.y.toReal() > textrect.bottom()) { | - | ||||||||||||||||||
621 | *position += bl.length(); | - | ||||||||||||||||||
622 | - | |||||||||||||||||||
623 | return PointAfter; | - | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | QPointF pos = point.toPointF() - tl->position(); | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | - | |||||||||||||||||||
629 | - | |||||||||||||||||||
630 | HitPoint hit = PointInside; | - | ||||||||||||||||||
631 | *l = tl; | - | ||||||||||||||||||
632 | int off = 0; | - | ||||||||||||||||||
633 | for (int i = 0; i < tl->lineCount(); ++i) { | - | ||||||||||||||||||
634 | QTextLine line = tl->lineAt(i); | - | ||||||||||||||||||
635 | const QRectF lr = line.naturalTextRect(); | - | ||||||||||||||||||
636 | if (lr.top() > pos.y()) { | - | ||||||||||||||||||
637 | off = qMin(off, line.textStart()); | - | ||||||||||||||||||
638 | } else if (lr.bottom() <= pos.y()) { | - | ||||||||||||||||||
639 | off = qMax(off, line.textStart() + line.textLength()); | - | ||||||||||||||||||
640 | } else { | - | ||||||||||||||||||
641 | if (lr.left() <= pos.x() && lr.right() >= pos.x()) | - | ||||||||||||||||||
642 | hit = PointExact; | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | - | |||||||||||||||||||
645 | if (accuracy == Qt::ExactHit) | - | ||||||||||||||||||
646 | off = line.xToCursor(pos.x(), QTextLine::CursorOnCharacter); | - | ||||||||||||||||||
647 | else | - | ||||||||||||||||||
648 | off = line.xToCursor(pos.x(), QTextLine::CursorBetweenCharacters); | - | ||||||||||||||||||
649 | break; | - | ||||||||||||||||||
650 | } | - | ||||||||||||||||||
651 | } | - | ||||||||||||||||||
652 | *position += off; | - | ||||||||||||||||||
653 | - | |||||||||||||||||||
654 | - | |||||||||||||||||||
655 | return hit; | - | ||||||||||||||||||
656 | } | - | ||||||||||||||||||
657 | - | |||||||||||||||||||
658 | - | |||||||||||||||||||
659 | QFixed QTextDocumentLayoutPrivate::blockIndent(const QTextBlockFormat &blockFormat) const | - | ||||||||||||||||||
660 | { | - | ||||||||||||||||||
661 | qreal indent = blockFormat.indent(); | - | ||||||||||||||||||
662 | - | |||||||||||||||||||
663 | QTextObject *object = document->objectForFormat(blockFormat); | - | ||||||||||||||||||
664 | if (object) | - | ||||||||||||||||||
665 | indent += object->format().toListFormat().indent(); | - | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | if (qIsNull(indent)) | - | ||||||||||||||||||
668 | return 0; | - | ||||||||||||||||||
669 | - | |||||||||||||||||||
670 | qreal scale = 1; | - | ||||||||||||||||||
671 | if (paintDevice) { | - | ||||||||||||||||||
672 | scale = qreal(paintDevice->logicalDpiY()) / qreal(qt_defaultDpi()); | - | ||||||||||||||||||
673 | } | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | return QFixed::fromReal(indent * scale * document->indentWidth()); | - | ||||||||||||||||||
676 | } | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | void QTextDocumentLayoutPrivate::drawBorder(QPainter *painter, const QRectF &rect, qreal topMargin, qreal bottomMargin, | - | ||||||||||||||||||
679 | qreal border, const QBrush &brush, QTextFrameFormat::BorderStyle style) const | - | ||||||||||||||||||
680 | { | - | ||||||||||||||||||
681 | const qreal pageHeight = document->pageSize().height(); | - | ||||||||||||||||||
682 | const int topPage = pageHeight > 0 ? static_cast<int>(rect.top() / pageHeight) : 0; | - | ||||||||||||||||||
683 | const int bottomPage = pageHeight > 0 ? static_cast<int>((rect.bottom() + border) / pageHeight) : 0; | - | ||||||||||||||||||
684 | - | |||||||||||||||||||
685 | - | |||||||||||||||||||
686 | QCss::BorderStyle cssStyle = static_cast<QCss::BorderStyle>(style + 1); | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | - | |||||||||||||||||||
689 | bool turn_off_antialiasing = !(painter->renderHints() & QPainter::Antialiasing); | - | ||||||||||||||||||
690 | painter->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | for (int i = topPage; i <= bottomPage; ++i) { | - | ||||||||||||||||||
693 | QRectF clipped = rect.toRect(); | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | if (topPage != bottomPage) { | - | ||||||||||||||||||
696 | clipped.setTop(qMax(clipped.top(), i * pageHeight + topMargin - border)); | - | ||||||||||||||||||
697 | clipped.setBottom(qMin(clipped.bottom(), (i + 1) * pageHeight - bottomMargin)); | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | if (clipped.bottom() <= clipped.top()) | - | ||||||||||||||||||
700 | continue; | - | ||||||||||||||||||
701 | } | - | ||||||||||||||||||
702 | - | |||||||||||||||||||
703 | qDrawEdge(painter, clipped.left(), clipped.top(), clipped.left() + border, clipped.bottom() + border, 0, 0, QCss::LeftEdge, cssStyle, brush); | - | ||||||||||||||||||
704 | qDrawEdge(painter, clipped.left() + border, clipped.top(), clipped.right() + border, clipped.top() + border, 0, 0, QCss::TopEdge, cssStyle, brush); | - | ||||||||||||||||||
705 | qDrawEdge(painter, clipped.right(), clipped.top() + border, clipped.right() + border, clipped.bottom(), 0, 0, QCss::RightEdge, cssStyle, brush); | - | ||||||||||||||||||
706 | qDrawEdge(painter, clipped.left() + border, clipped.bottom(), clipped.right() + border, clipped.bottom() + border, 0, 0, QCss::BottomEdge, cssStyle, brush); | - | ||||||||||||||||||
707 | } | - | ||||||||||||||||||
708 | if (turn_off_antialiasing) | - | ||||||||||||||||||
709 | painter->setRenderHint(QPainter::Antialiasing, false); | - | ||||||||||||||||||
710 | } | - | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | void QTextDocumentLayoutPrivate::drawFrameDecoration(QPainter *painter, QTextFrame *frame, QTextFrameData *fd, const QRectF &clip, const QRectF &rect) const | - | ||||||||||||||||||
713 | { | - | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | const QBrush bg = frame->frameFormat().background(); | - | ||||||||||||||||||
716 | if (bg != Qt::NoBrush) { | - | ||||||||||||||||||
717 | QRectF bgRect = rect; | - | ||||||||||||||||||
718 | bgRect.adjust((fd->leftMargin + fd->border).toReal(), | - | ||||||||||||||||||
719 | (fd->topMargin + fd->border).toReal(), | - | ||||||||||||||||||
720 | - (fd->rightMargin + fd->border).toReal(), | - | ||||||||||||||||||
721 | - (fd->bottomMargin + fd->border).toReal()); | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | QRectF gradientRect; | - | ||||||||||||||||||
724 | QPointF origin = bgRect.topLeft(); | - | ||||||||||||||||||
725 | if (!frame->parentFrame()) { | - | ||||||||||||||||||
726 | bgRect = clip; | - | ||||||||||||||||||
727 | gradientRect.setWidth(painter->device()->width()); | - | ||||||||||||||||||
728 | gradientRect.setHeight(painter->device()->height()); | - | ||||||||||||||||||
729 | } | - | ||||||||||||||||||
730 | fillBackground(painter, bgRect, bg, origin, gradientRect); | - | ||||||||||||||||||
731 | } | - | ||||||||||||||||||
732 | if (fd->border != 0) { | - | ||||||||||||||||||
733 | painter->save(); | - | ||||||||||||||||||
734 | painter->setBrush(Qt::lightGray); | - | ||||||||||||||||||
735 | painter->setPen(Qt::NoPen); | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | const qreal leftEdge = rect.left() + fd->leftMargin.toReal(); | - | ||||||||||||||||||
738 | const qreal border = fd->border.toReal(); | - | ||||||||||||||||||
739 | const qreal topMargin = fd->topMargin.toReal(); | - | ||||||||||||||||||
740 | const qreal leftMargin = fd->leftMargin.toReal(); | - | ||||||||||||||||||
741 | const qreal bottomMargin = fd->bottomMargin.toReal(); | - | ||||||||||||||||||
742 | const qreal rightMargin = fd->rightMargin.toReal(); | - | ||||||||||||||||||
743 | const qreal w = rect.width() - 2 * border - leftMargin - rightMargin; | - | ||||||||||||||||||
744 | const qreal h = rect.height() - 2 * border - topMargin - bottomMargin; | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | drawBorder(painter, QRectF(leftEdge, rect.top() + topMargin, w + border, h + border), | - | ||||||||||||||||||
747 | fd->effectiveTopMargin.toReal(), fd->effectiveBottomMargin.toReal(), | - | ||||||||||||||||||
748 | border, frame->frameFormat().borderBrush(), frame->frameFormat().borderStyle()); | - | ||||||||||||||||||
749 | - | |||||||||||||||||||
750 | painter->restore(); | - | ||||||||||||||||||
751 | } | - | ||||||||||||||||||
752 | } | - | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | static void adjustContextSelectionsForCell(QAbstractTextDocumentLayout::PaintContext &cell_context, | - | ||||||||||||||||||
755 | const QTextTableCell &cell, | - | ||||||||||||||||||
756 | int r, int c, | - | ||||||||||||||||||
757 | const int *selectedTableCells) | - | ||||||||||||||||||
758 | { | - | ||||||||||||||||||
759 | for (int i = 0; i < cell_context.selections.size(); ++i) { | - | ||||||||||||||||||
760 | int row_start = selectedTableCells[i * 4]; | - | ||||||||||||||||||
761 | int col_start = selectedTableCells[i * 4 + 1]; | - | ||||||||||||||||||
762 | int num_rows = selectedTableCells[i * 4 + 2]; | - | ||||||||||||||||||
763 | int num_cols = selectedTableCells[i * 4 + 3]; | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | if (row_start != -1) { | - | ||||||||||||||||||
766 | if (r >= row_start && r < row_start + num_rows | - | ||||||||||||||||||
767 | && c >= col_start && c < col_start + num_cols) | - | ||||||||||||||||||
768 | { | - | ||||||||||||||||||
769 | int firstPosition = cell.firstPosition(); | - | ||||||||||||||||||
770 | int lastPosition = cell.lastPosition(); | - | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | - | |||||||||||||||||||
773 | if (firstPosition == lastPosition) | - | ||||||||||||||||||
774 | ++lastPosition; | - | ||||||||||||||||||
775 | - | |||||||||||||||||||
776 | cell_context.selections[i].cursor.setPosition(firstPosition); | - | ||||||||||||||||||
777 | cell_context.selections[i].cursor.setPosition(lastPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||
778 | } else { | - | ||||||||||||||||||
779 | cell_context.selections[i].cursor.clearSelection(); | - | ||||||||||||||||||
780 | } | - | ||||||||||||||||||
781 | } | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | - | |||||||||||||||||||
784 | cell_context.selections[i].format.clearProperty(QTextFormat::FullWidthSelection); | - | ||||||||||||||||||
785 | } | - | ||||||||||||||||||
786 | } | - | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | void QTextDocumentLayoutPrivate::drawFrame(const QPointF &offset, QPainter *painter, | - | ||||||||||||||||||
789 | const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
790 | QTextFrame *frame) const | - | ||||||||||||||||||
791 | { | - | ||||||||||||||||||
792 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | if (fd->layoutDirty) | - | ||||||||||||||||||
795 | return; | - | ||||||||||||||||||
796 | ((!(!fd->sizeDirty)) ? qt_assert("!fd->sizeDirty",__FILE__,950956) : qt_noop()); | - | ||||||||||||||||||
797 | ((!(!fd->layoutDirty)) ? qt_assert("!fd->layoutDirty",__FILE__,951957) : qt_noop()); | - | ||||||||||||||||||
798 | - | |||||||||||||||||||
799 | const QPointF off = offset + fd->position.toPointF(); | - | ||||||||||||||||||
800 | if (context.clip.isValid() | - | ||||||||||||||||||
801 | && (off.y() > context.clip.bottom() || off.y() + fd->size.height.toReal() < context.clip.top() | - | ||||||||||||||||||
802 | || off.x() > context.clip.right() || off.x() + fd->size.width.toReal() < context.clip.left())) | - | ||||||||||||||||||
803 | return; | - | ||||||||||||||||||
804 | - | |||||||||||||||||||
805 | - | |||||||||||||||||||
806 | - | |||||||||||||||||||
807 | - | |||||||||||||||||||
808 | - | |||||||||||||||||||
809 | - | |||||||||||||||||||
810 | QTextBlock cursorBlockNeedingRepaint; | - | ||||||||||||||||||
811 | QPointF offsetOfRepaintedCursorBlock = off; | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | QTextTable *table = qobject_cast<QTextTable *>(frame); | - | ||||||||||||||||||
814 | const QRectF frameRect(off, fd->size.toSizeF()); | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | if (table) { | - | ||||||||||||||||||
817 | const int rows = table->rows(); | - | ||||||||||||||||||
818 | const int columns = table->columns(); | - | ||||||||||||||||||
819 | QTextTableData *td = static_cast<QTextTableData *>(data(table)); | - | ||||||||||||||||||
820 | - | |||||||||||||||||||
821 | QVarLengthArray<int> selectedTableCells(context.selections.size() * 4); | - | ||||||||||||||||||
822 | for (int i = 0; i < context.selections.size(); ++i) { | - | ||||||||||||||||||
823 | const QAbstractTextDocumentLayout::Selection &s = context.selections.at(i); | - | ||||||||||||||||||
824 | int row_start = -1, col_start = -1, num_rows = -1, num_cols = -1; | - | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | if (s.cursor.currentTable() == table) | - | ||||||||||||||||||
827 | s.cursor.selectedTableCells(&row_start, &num_rows, &col_start, &num_cols); | - | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | selectedTableCells[i * 4] = row_start; | - | ||||||||||||||||||
830 | selectedTableCells[i * 4 + 1] = col_start; | - | ||||||||||||||||||
831 | selectedTableCells[i * 4 + 2] = num_rows; | - | ||||||||||||||||||
832 | selectedTableCells[i * 4 + 3] = num_cols; | - | ||||||||||||||||||
833 | } | - | ||||||||||||||||||
834 | - | |||||||||||||||||||
835 | QFixed pageHeight = QFixed::fromReal(document->pageSize().height()); | - | ||||||||||||||||||
836 | if (pageHeight <= 0) | - | ||||||||||||||||||
837 | pageHeight = (2147483647/256); | - | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | const int tableStartPage = (td->position.y / pageHeight).truncate(); | - | ||||||||||||||||||
840 | const int tableEndPage = ((td->position.y + td->size.height) / pageHeight).truncate(); | - | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | qreal border = td->border.toReal(); | - | ||||||||||||||||||
843 | drawFrameDecoration(painter, frame, fd, context.clip, frameRect); | - | ||||||||||||||||||
844 | - | |||||||||||||||||||
845 | - | |||||||||||||||||||
846 | const int headerRowCount = qMin(table->format().headerRowCount(), rows - 1); | - | ||||||||||||||||||
847 | int page = tableStartPage + 1; | - | ||||||||||||||||||
848 | while (page <= tableEndPage) { | - | ||||||||||||||||||
849 | const QFixed pageTop = page * pageHeight + td->effectiveTopMargin + td->cellSpacing + td->border; | - | ||||||||||||||||||
850 | const qreal headerOffset = (pageTop - td->rowPositions.at(0)).toReal(); | - | ||||||||||||||||||
851 | for (int r = 0; r < headerRowCount; ++r) { | - | ||||||||||||||||||
852 | for (int c = 0; c < columns; ++c) { | - | ||||||||||||||||||
853 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
854 | QAbstractTextDocumentLayout::PaintContext cell_context = context; | - | ||||||||||||||||||
855 | adjustContextSelectionsForCell(cell_context, cell, r, c, selectedTableCells.data()); | - | ||||||||||||||||||
856 | QRectF cellRect = td->cellRect(cell); | - | ||||||||||||||||||
857 | - | |||||||||||||||||||
858 | cellRect.translate(off.x(), headerOffset); | - | ||||||||||||||||||
859 | - | |||||||||||||||||||
860 | int leftAdjust = qMin(qreal(0), 1 - border); | - | ||||||||||||||||||
861 | if (cell_context.clip.isValid() && !cellRect.adjusted(leftAdjust, leftAdjust, border, border).intersects(cell_context.clip)) | - | ||||||||||||||||||
862 | continue; | - | ||||||||||||||||||
863 | - | |||||||||||||||||||
864 | drawTableCell(cellRect, painter, cell_context, table, td, r, c, &cursorBlockNeedingRepaint, | - | ||||||||||||||||||
865 | &offsetOfRepaintedCursorBlock); | - | ||||||||||||||||||
866 | } | - | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
868 | ++page; | - | ||||||||||||||||||
869 | } | - | ||||||||||||||||||
870 | - | |||||||||||||||||||
871 | int firstRow = 0; | - | ||||||||||||||||||
872 | int lastRow = rows; | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | if (context.clip.isValid()) { | - | ||||||||||||||||||
875 | QVector<QFixed>::ConstIterator rowIt = std::lower_bound(td->rowPositions.constBegin(), td->rowPositions.constEnd(), QFixed::fromReal(context.clip.top() - off.y())); | - | ||||||||||||||||||
876 | if (rowIt != td->rowPositions.constEnd() && rowIt != td->rowPositions.constBegin()) { | - | ||||||||||||||||||
877 | --rowIt; | - | ||||||||||||||||||
878 | firstRow = rowIt - td->rowPositions.constBegin(); | - | ||||||||||||||||||
879 | } | - | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | rowIt = std::upper_bound(td->rowPositions.constBegin(), td->rowPositions.constEnd(), QFixed::fromReal(context.clip.bottom() - off.y())); | - | ||||||||||||||||||
882 | if (rowIt != td->rowPositions.constEnd()) { | - | ||||||||||||||||||
883 | ++rowIt; | - | ||||||||||||||||||
884 | lastRow = rowIt - td->rowPositions.constBegin(); | - | ||||||||||||||||||
885 | } | - | ||||||||||||||||||
886 | } | - | ||||||||||||||||||
887 | - | |||||||||||||||||||
888 | for (int c = 0; c < columns; ++c) { | - | ||||||||||||||||||
889 | QTextTableCell cell = table->cellAt(firstRow, c); | - | ||||||||||||||||||
890 | firstRow = qMin(firstRow, cell.row()); | - | ||||||||||||||||||
891 | } | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | for (int r = firstRow; r < lastRow; ++r) { | - | ||||||||||||||||||
894 | for (int c = 0; c < columns; ++c) { | - | ||||||||||||||||||
895 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
896 | QAbstractTextDocumentLayout::PaintContext cell_context = context; | - | ||||||||||||||||||
897 | adjustContextSelectionsForCell(cell_context, cell, r, c, selectedTableCells.data()); | - | ||||||||||||||||||
898 | QRectF cellRect = td->cellRect(cell); | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | cellRect.translate(off); | - | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | int leftAdjust = qMin(qreal(0), 1 - border); | - | ||||||||||||||||||
903 | if (cell_context.clip.isValid() && !cellRect.adjusted(leftAdjust, leftAdjust, border, border).intersects(cell_context.clip)) | - | ||||||||||||||||||
904 | continue; | - | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | drawTableCell(cellRect, painter, cell_context, table, td, r, c, &cursorBlockNeedingRepaint, | - | ||||||||||||||||||
907 | &offsetOfRepaintedCursorBlock); | - | ||||||||||||||||||
908 | } | - | ||||||||||||||||||
909 | } | - | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | } else { | - | ||||||||||||||||||
912 | drawFrameDecoration(painter, frame, fd, context.clip, frameRect); | - | ||||||||||||||||||
913 | - | |||||||||||||||||||
914 | QTextFrame::Iterator it = frame->begin(); | - | ||||||||||||||||||
915 | - | |||||||||||||||||||
916 | if (frame == docPrivate->rootFrame()) | - | ||||||||||||||||||
917 | it = frameIteratorForYPosition(QFixed::fromReal(context.clip.top())); | - | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | QList<QTextFrame *> floats; | - | ||||||||||||||||||
920 | const int numFloats = fd->floats.count(); | - | ||||||||||||||||||
921 | floats.reserve(numFloats); | - | ||||||||||||||||||
922 | for (int i = 0; i < numFloats; ++i) | - | ||||||||||||||||||
923 | floats.append(fd->floats.at(i)); | - | ||||||||||||||||||
924 | - | |||||||||||||||||||
925 | drawFlow(off, painter, context, it, floats, &cursorBlockNeedingRepaint); | - | ||||||||||||||||||
926 | } | - | ||||||||||||||||||
927 | - | |||||||||||||||||||
928 | if (cursorBlockNeedingRepaint.isValid()) { | - | ||||||||||||||||||
929 | const QPen oldPen = painter->pen(); | - | ||||||||||||||||||
930 | painter->setPen(context.palette.color(QPalette::Text)); | - | ||||||||||||||||||
931 | const int cursorPos = context.cursorPosition - cursorBlockNeedingRepaint.position(); | - | ||||||||||||||||||
932 | cursorBlockNeedingRepaint.layout()->drawCursor(painter, offsetOfRepaintedCursorBlock, | - | ||||||||||||||||||
933 | cursorPos, cursorWidth); | - | ||||||||||||||||||
934 | painter->setPen(oldPen); | - | ||||||||||||||||||
935 | } | - | ||||||||||||||||||
936 | - | |||||||||||||||||||
937 | - | |||||||||||||||||||
938 | - | |||||||||||||||||||
939 | return; | - | ||||||||||||||||||
940 | } | - | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | void QTextDocumentLayoutPrivate::drawTableCell(const QRectF &cellRect, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &cell_context, | - | ||||||||||||||||||
943 | QTextTable *table, QTextTableData *td, int r, int c, | - | ||||||||||||||||||
944 | QTextBlock *cursorBlockNeedingRepaint, QPointF *cursorBlockOffset) const | - | ||||||||||||||||||
945 | { | - | ||||||||||||||||||
946 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
947 | int rspan = cell.rowSpan(); | - | ||||||||||||||||||
948 | int cspan = cell.columnSpan(); | - | ||||||||||||||||||
949 | if (rspan != 1) { | - | ||||||||||||||||||
950 | int cr = cell.row(); | - | ||||||||||||||||||
951 | if (cr != r) | - | ||||||||||||||||||
952 | return; | - | ||||||||||||||||||
953 | } | - | ||||||||||||||||||
954 | if (cspan != 1) { | - | ||||||||||||||||||
955 | int cc = cell.column(); | - | ||||||||||||||||||
956 | if (cc != c) | - | ||||||||||||||||||
957 | return; | - | ||||||||||||||||||
958 | } | - | ||||||||||||||||||
959 | - | |||||||||||||||||||
960 | QTextFormat fmt = cell.format(); | - | ||||||||||||||||||
961 | const QFixed leftPadding = td->leftPadding(fmt); | - | ||||||||||||||||||
962 | const QFixed topPadding = td->topPadding(fmt); | - | ||||||||||||||||||
963 | - | |||||||||||||||||||
964 | qreal topMargin = (td->effectiveTopMargin + td->cellSpacing + td->border).toReal(); | - | ||||||||||||||||||
965 | qreal bottomMargin = (td->effectiveBottomMargin + td->cellSpacing + td->border).toReal(); | - | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | const int headerRowCount = qMin(table->format().headerRowCount(), table->rows() - 1); | - | ||||||||||||||||||
968 | if (r >= headerRowCount) | - | ||||||||||||||||||
969 | topMargin += td->headerHeight.toReal(); | - | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | if (td->border != 0) { | - | ||||||||||||||||||
972 | const QBrush oldBrush = painter->brush(); | - | ||||||||||||||||||
973 | const QPen oldPen = painter->pen(); | - | ||||||||||||||||||
974 | - | |||||||||||||||||||
975 | const qreal border = td->border.toReal(); | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | QRectF borderRect(cellRect.left() - border, cellRect.top() - border, cellRect.width() + border, cellRect.height() + border); | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | - | |||||||||||||||||||
980 | QTextFrameFormat::BorderStyle cellBorder = table->format().borderStyle(); | - | ||||||||||||||||||
981 | switch (cellBorder) { | - | ||||||||||||||||||
982 | case QTextFrameFormat::BorderStyle_Inset: | - | ||||||||||||||||||
983 | cellBorder = QTextFrameFormat::BorderStyle_Outset; | - | ||||||||||||||||||
984 | break; | - | ||||||||||||||||||
985 | case QTextFrameFormat::BorderStyle_Outset: | - | ||||||||||||||||||
986 | cellBorder = QTextFrameFormat::BorderStyle_Inset; | - | ||||||||||||||||||
987 | break; | - | ||||||||||||||||||
988 | case QTextFrameFormat::BorderStyle_Groove: | - | ||||||||||||||||||
989 | cellBorder = QTextFrameFormat::BorderStyle_Ridge; | - | ||||||||||||||||||
990 | break; | - | ||||||||||||||||||
991 | case QTextFrameFormat::BorderStyle_Ridge: | - | ||||||||||||||||||
992 | cellBorder = QTextFrameFormat::BorderStyle_Groove; | - | ||||||||||||||||||
993 | break; | - | ||||||||||||||||||
994 | default: | - | ||||||||||||||||||
995 | break; | - | ||||||||||||||||||
996 | } | - | ||||||||||||||||||
997 | - | |||||||||||||||||||
998 | drawBorder(painter, borderRect, topMargin, bottomMargin, | - | ||||||||||||||||||
999 | border, table->format().borderBrush(), cellBorder); | - | ||||||||||||||||||
1000 | - | |||||||||||||||||||
1001 | painter->setBrush(oldBrush); | - | ||||||||||||||||||
1002 | painter->setPen(oldPen); | - | ||||||||||||||||||
1003 | } | - | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | const QBrush bg = cell.format().background(); | - | ||||||||||||||||||
1006 | const QPointF brushOrigin = painter->brushOrigin(); | - | ||||||||||||||||||
1007 | if (bg.style() != Qt::NoBrush) { | - | ||||||||||||||||||
1008 | const qreal pageHeight = document->pageSize().height(); | - | ||||||||||||||||||
1009 | const int topPage = pageHeight > 0 ? static_cast<int>(cellRect.top() / pageHeight) : 0; | - | ||||||||||||||||||
1010 | const int bottomPage = pageHeight > 0 ? static_cast<int>((cellRect.bottom()) / pageHeight) : 0; | - | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | if (topPage == bottomPage) | - | ||||||||||||||||||
1013 | fillBackground(painter, cellRect, bg, cellRect.topLeft()); | - | ||||||||||||||||||
1014 | else { | - | ||||||||||||||||||
1015 | for (int i = topPage; i <= bottomPage; ++i) { | - | ||||||||||||||||||
1016 | QRectF clipped = cellRect.toRect(); | - | ||||||||||||||||||
1017 | - | |||||||||||||||||||
1018 | if (topPage != bottomPage) { | - | ||||||||||||||||||
1019 | const qreal top = qMax(i * pageHeight + topMargin, cell_context.clip.top()); | - | ||||||||||||||||||
1020 | const qreal bottom = qMin((i + 1) * pageHeight - bottomMargin, cell_context.clip.bottom()); | - | ||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | clipped.setTop(qMax(clipped.top(), top)); | - | ||||||||||||||||||
1023 | clipped.setBottom(qMin(clipped.bottom(), bottom)); | - | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | if (clipped.bottom() <= clipped.top()) | - | ||||||||||||||||||
1026 | continue; | - | ||||||||||||||||||
1027 | - | |||||||||||||||||||
1028 | fillBackground(painter, clipped, bg, cellRect.topLeft()); | - | ||||||||||||||||||
1029 | } | - | ||||||||||||||||||
1030 | } | - | ||||||||||||||||||
1031 | } | - | ||||||||||||||||||
1032 | - | |||||||||||||||||||
1033 | if (bg.style() > Qt::SolidPattern) | - | ||||||||||||||||||
1034 | painter->setBrushOrigin(cellRect.topLeft()); | - | ||||||||||||||||||
1035 | } | - | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | const QFixed verticalOffset = td->cellVerticalOffsets.at(c + r * table->columns()); | - | ||||||||||||||||||
1038 | - | |||||||||||||||||||
1039 | const QPointF cellPos = QPointF(cellRect.left() + leftPadding.toReal(), | - | ||||||||||||||||||
1040 | cellRect.top() + (topPadding + verticalOffset).toReal()); | - | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | QTextBlock repaintBlock; | - | ||||||||||||||||||
1043 | drawFlow(cellPos, painter, cell_context, cell.begin(), | - | ||||||||||||||||||
1044 | td->childFrameMap.values(r + c * table->rows()), | - | ||||||||||||||||||
1045 | &repaintBlock); | - | ||||||||||||||||||
1046 | if (repaintBlock.isValid()) { | - | ||||||||||||||||||
1047 | *cursorBlockNeedingRepaint = repaintBlock; | - | ||||||||||||||||||
1048 | *cursorBlockOffset = cellPos; | - | ||||||||||||||||||
1049 | } | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | if (bg.style() > Qt::SolidPattern) | - | ||||||||||||||||||
1052 | painter->setBrushOrigin(brushOrigin); | - | ||||||||||||||||||
1053 | } | - | ||||||||||||||||||
1054 | - | |||||||||||||||||||
1055 | void QTextDocumentLayoutPrivate::drawFlow(const QPointF &offset, QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
1056 | QTextFrame::Iterator it, const QList<QTextFrame *> &floats, QTextBlock *cursorBlockNeedingRepaint) const | - | ||||||||||||||||||
1057 | { | - | ||||||||||||||||||
1058 | const QTextDocumentLayout * const q = q_func(); | - | ||||||||||||||||||
1059 | const bool inRootFrame = (!it.atEnd()
| 0 | ||||||||||||||||||
1060 | - | |||||||||||||||||||
1061 | QVector<QCheckPoint>::ConstIterator lastVisibleCheckPoint = checkPoints.end(); | - | ||||||||||||||||||
1062 | if (inRootFrame
| 0 | ||||||||||||||||||
1063 | lastVisibleCheckPoint = std::lower_bound(checkPoints.begin(), checkPoints.end(), QFixed::fromReal(context.clip.bottom())); | - | ||||||||||||||||||
1064 | } never executed: end of block | 0 | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | QTextBlock previousBlock; | - | ||||||||||||||||||
1067 | QTextFrame *previousFrame = 0; | - | ||||||||||||||||||
1068 | - | |||||||||||||||||||
1069 | for (; !it.atEnd()
| 0 | ||||||||||||||||||
1070 | QTextFrame *c = it.currentFrame(); | - | ||||||||||||||||||
1071 | - | |||||||||||||||||||
1072 | if (inRootFrame
| 0 | ||||||||||||||||||
1073 | int currentPosInDoc; | - | ||||||||||||||||||
1074 | if (c
| 0 | ||||||||||||||||||
1075 | currentPosInDoc = c->firstPosition(); never executed: currentPosInDoc = c->firstPosition(); | 0 | ||||||||||||||||||
1076 | else | - | ||||||||||||||||||
1077 | currentPosInDoc = it.currentBlock().position(); never executed: currentPosInDoc = it.currentBlock().position(); | 0 | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | - | |||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | if (currentPosInDoc >= checkPoints.lastconstLast().positionInFrame
| 0 | ||||||||||||||||||
1082 | break; never executed: break; | 0 | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | if (lastVisibleCheckPoint != checkPoints.end()
| 0 | ||||||||||||||||||
1085 | && context.clip.isValid()
| 0 | ||||||||||||||||||
1086 | && currentPosInDoc >= lastVisibleCheckPoint->positionInFrame
| 0 | ||||||||||||||||||
1087 | ) | - | ||||||||||||||||||
1088 | break; never executed: break; | 0 | ||||||||||||||||||
1089 | } never executed: end of block | 0 | ||||||||||||||||||
1090 | - | |||||||||||||||||||
1091 | if (c
| 0 | ||||||||||||||||||
1092 | drawFrame(offset, painter, context, c); never executed: drawFrame(offset, painter, context, c); | 0 | ||||||||||||||||||
1093 | else { | - | ||||||||||||||||||
1094 | QAbstractTextDocumentLayout::PaintContext pc = context; | - | ||||||||||||||||||
1095 | if (isEmptyBlockAfterTable(it.currentBlock(), previousFrame)
| 0 | ||||||||||||||||||
1096 | pc.selections.clear(); never executed: pc.selections.clear(); | 0 | ||||||||||||||||||
1097 | drawBlock(offset, painter, pc, it.currentBlock(), inRootFrame); | - | ||||||||||||||||||
1098 | } never executed: end of block | 0 | ||||||||||||||||||
1099 | - | |||||||||||||||||||
1100 | - | |||||||||||||||||||
1101 | - | |||||||||||||||||||
1102 | - | |||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | if (isEmptyBlockBeforeTable(previousBlock, previousBlock.blockFormat(), it)
| 0 | ||||||||||||||||||
1107 | && previousBlock.contains(context.cursorPosition)
| 0 | ||||||||||||||||||
1108 | ) { | - | ||||||||||||||||||
1109 | *cursorBlockNeedingRepaint = previousBlock; | - | ||||||||||||||||||
1110 | } never executed: end of block | 0 | ||||||||||||||||||
1111 | - | |||||||||||||||||||
1112 | previousBlock = it.currentBlock(); | - | ||||||||||||||||||
1113 | previousFrame = c; | - | ||||||||||||||||||
1114 | } never executed: end of block | 0 | ||||||||||||||||||
1115 | - | |||||||||||||||||||
1116 | for (int i = 0; i < floats.count()
| 0 | ||||||||||||||||||
1117 | QTextFrame *frame = floats.at(i); | - | ||||||||||||||||||
1118 | if (!isFrameFromInlineObject(frame)
| 0 | ||||||||||||||||||
1119 | || frame->frameFormat().position() == QTextFrameFormat::InFlow
| 0 | ||||||||||||||||||
1120 | continue; never executed: continue; | 0 | ||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | const int pos = frame->firstPosition() - 1; | - | ||||||||||||||||||
1123 | QTextCharFormat format = const_cast<QTextDocumentLayout *>(q)->format(pos); | - | ||||||||||||||||||
1124 | QTextObjectInterface *handler = q->handlerForObject(format.objectType()); | - | ||||||||||||||||||
1125 | if (handler
| 0 | ||||||||||||||||||
1126 | QRectF rect = frameBoundingRectInternal(frame); | - | ||||||||||||||||||
1127 | handler->drawObject(painter, rect, document, pos, format); | - | ||||||||||||||||||
1128 | } never executed: end of block | 0 | ||||||||||||||||||
1129 | } never executed: end of block | 0 | ||||||||||||||||||
1130 | } never executed: end of block | 0 | ||||||||||||||||||
1131 | - | |||||||||||||||||||
1132 | void QTextDocumentLayoutPrivate::drawBlock(const QPointF &offset, QPainter *painter, | - | ||||||||||||||||||
1133 | const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
1134 | const QTextBlock &bl, bool inRootFrame) const | - | ||||||||||||||||||
1135 | { | - | ||||||||||||||||||
1136 | const QTextLayout *tl = bl.layout(); | - | ||||||||||||||||||
1137 | QRectF r = tl->boundingRect(); | - | ||||||||||||||||||
1138 | r.translate(offset + tl->position()); | - | ||||||||||||||||||
1139 | if (!bl.isVisible() || (context.clip.isValid() && (r.bottom() < context.clip.y() || r.top() > context.clip.bottom()))) | - | ||||||||||||||||||
1140 | return; | - | ||||||||||||||||||
1141 | - | |||||||||||||||||||
1142 | - | |||||||||||||||||||
1143 | QTextBlockFormat blockFormat = bl.blockFormat(); | - | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | QBrush bg = blockFormat.background(); | - | ||||||||||||||||||
1146 | if (bg != Qt::NoBrush) { | - | ||||||||||||||||||
1147 | QRectF rect = r; | - | ||||||||||||||||||
1148 | - | |||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | - | |||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | if (inRootFrame && document->pageSize().width() <= 0) { | - | ||||||||||||||||||
1153 | const QTextFrameData *fd = data(document->rootFrame()); | - | ||||||||||||||||||
1154 | rect.setRight((fd->size.width - fd->rightMargin).toReal()); | - | ||||||||||||||||||
1155 | } | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | fillBackground(painter, rect, bg, r.topLeft()); | - | ||||||||||||||||||
1158 | } | - | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | QVector<QTextLayout::FormatRange> selections; | - | ||||||||||||||||||
1161 | int blpos = bl.position(); | - | ||||||||||||||||||
1162 | int bllen = bl.length(); | - | ||||||||||||||||||
1163 | const QTextCharFormat *selFormat = 0; | - | ||||||||||||||||||
1164 | for (int i = 0; i < context.selections.size(); ++i) { | - | ||||||||||||||||||
1165 | const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i); | - | ||||||||||||||||||
1166 | const int selStart = range.cursor.selectionStart() - blpos; | - | ||||||||||||||||||
1167 | const int selEnd = range.cursor.selectionEnd() - blpos; | - | ||||||||||||||||||
1168 | if (selStart < bllen && selEnd > 0 | - | ||||||||||||||||||
1169 | && selEnd > selStart) { | - | ||||||||||||||||||
1170 | QTextLayout::FormatRange o; | - | ||||||||||||||||||
1171 | o.start = selStart; | - | ||||||||||||||||||
1172 | o.length = selEnd - selStart; | - | ||||||||||||||||||
1173 | o.format = range.format; | - | ||||||||||||||||||
1174 | selections.append(o); | - | ||||||||||||||||||
1175 | } else if (! range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection) | - | ||||||||||||||||||
1176 | && bl.contains(range.cursor.position())) { | - | ||||||||||||||||||
1177 | - | |||||||||||||||||||
1178 | - | |||||||||||||||||||
1179 | QTextLayout::FormatRange o; | - | ||||||||||||||||||
1180 | QTextLine l = tl->lineForTextPosition(range.cursor.position() - blpos); | - | ||||||||||||||||||
1181 | o.start = l.textStart(); | - | ||||||||||||||||||
1182 | o.length = l.textLength(); | - | ||||||||||||||||||
1183 | if (o.start + o.length == bllen - 1) | - | ||||||||||||||||||
1184 | ++o.length; | - | ||||||||||||||||||
1185 | o.format = range.format; | - | ||||||||||||||||||
1186 | selections.append(o); | - | ||||||||||||||||||
1187 | } | - | ||||||||||||||||||
1188 | if (selStart < 0 && selEnd >= 1) | - | ||||||||||||||||||
1189 | selFormat = &range.format; | - | ||||||||||||||||||
1190 | } | - | ||||||||||||||||||
1191 | - | |||||||||||||||||||
1192 | QTextObject *object = document->objectForFormat(bl.blockFormat()); | - | ||||||||||||||||||
1193 | if (object && object->format().toListFormat().style() != QTextListFormat::ListStyleUndefined) | - | ||||||||||||||||||
1194 | drawListItem(offset, painter, context, bl, selFormat); | - | ||||||||||||||||||
1195 | - | |||||||||||||||||||
1196 | QPen oldPen = painter->pen(); | - | ||||||||||||||||||
1197 | painter->setPen(context.palette.color(QPalette::Text)); | - | ||||||||||||||||||
1198 | - | |||||||||||||||||||
1199 | tl->draw(painter, offset, selections, context.clip.isValid() ? (context.clip & clipRect) : clipRect); | - | ||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | if ((context.cursorPosition >= blpos && context.cursorPosition < blpos + bllen) | - | ||||||||||||||||||
1202 | || (context.cursorPosition < -1 && !tl->preeditAreaText().isEmpty())) { | - | ||||||||||||||||||
1203 | int cpos = context.cursorPosition; | - | ||||||||||||||||||
1204 | if (cpos < -1) | - | ||||||||||||||||||
1205 | cpos = tl->preeditAreaPosition() - (cpos + 2); | - | ||||||||||||||||||
1206 | else | - | ||||||||||||||||||
1207 | cpos -= blpos; | - | ||||||||||||||||||
1208 | tl->drawCursor(painter, offset, cpos, cursorWidth); | - | ||||||||||||||||||
1209 | } | - | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | if (blockFormat.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) { | - | ||||||||||||||||||
1212 | const qreal width = blockFormat.lengthProperty(QTextFormat::BlockTrailingHorizontalRulerWidth).value(r.width()); | - | ||||||||||||||||||
1213 | painter->setPen(context.palette.color(QPalette::Dark)); | - | ||||||||||||||||||
1214 | qreal y = r.bottom(); | - | ||||||||||||||||||
1215 | if (bl.length() == 1) | - | ||||||||||||||||||
1216 | y = r.top() + r.height() / 2; | - | ||||||||||||||||||
1217 | - | |||||||||||||||||||
1218 | const qreal middleX = r.left() + r.width() / 2; | - | ||||||||||||||||||
1219 | painter->drawLine(QLineF(middleX - width / 2, y, middleX + width / 2, y)); | - | ||||||||||||||||||
1220 | } | - | ||||||||||||||||||
1221 | - | |||||||||||||||||||
1222 | painter->setPen(oldPen); | - | ||||||||||||||||||
1223 | } | - | ||||||||||||||||||
1224 | - | |||||||||||||||||||
1225 | - | |||||||||||||||||||
1226 | void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *painter, | - | ||||||||||||||||||
1227 | const QAbstractTextDocumentLayout::PaintContext &context, | - | ||||||||||||||||||
1228 | const QTextBlock &bl, const QTextCharFormat *selectionFormat) const | - | ||||||||||||||||||
1229 | { | - | ||||||||||||||||||
1230 | const QTextDocumentLayout * const q = q_func(); | - | ||||||||||||||||||
1231 | const QTextBlockFormat blockFormat = bl.blockFormat(); | - | ||||||||||||||||||
1232 | const QTextCharFormat charFormat = QTextCursor(bl).charFormat(); | - | ||||||||||||||||||
1233 | QFont font(charFormat.font()); | - | ||||||||||||||||||
1234 | if (q->paintDevice()) | - | ||||||||||||||||||
1235 | font = QFont(font, q->paintDevice()); | - | ||||||||||||||||||
1236 | - | |||||||||||||||||||
1237 | const QFontMetrics fontMetrics(font); | - | ||||||||||||||||||
1238 | QTextObject * const object = document->objectForFormat(blockFormat); | - | ||||||||||||||||||
1239 | const QTextListFormat lf = object->format().toListFormat(); | - | ||||||||||||||||||
1240 | int style = lf.style(); | - | ||||||||||||||||||
1241 | QString itemText; | - | ||||||||||||||||||
1242 | QSizeF size; | - | ||||||||||||||||||
1243 | - | |||||||||||||||||||
1244 | if (blockFormat.hasProperty(QTextFormat::ListStyle)) | - | ||||||||||||||||||
1245 | style = QTextListFormat::Style(blockFormat.intProperty(QTextFormat::ListStyle)); | - | ||||||||||||||||||
1246 | - | |||||||||||||||||||
1247 | QTextLayout *layout = bl.layout(); | - | ||||||||||||||||||
1248 | if (layout->lineCount() == 0) | - | ||||||||||||||||||
1249 | return; | - | ||||||||||||||||||
1250 | QTextLine firstLine = layout->lineAt(0); | - | ||||||||||||||||||
1251 | ((!(firstLine.isValid())) ? qt_assert("firstLine.isValid()",__FILE__,14051411) : qt_noop()); | - | ||||||||||||||||||
1252 | QPointF pos = (offset + layout->position()).toPoint(); | - | ||||||||||||||||||
1253 | Qt::LayoutDirection dir = bl.textDirection(); | - | ||||||||||||||||||
1254 | { | - | ||||||||||||||||||
1255 | QRectF textRect = firstLine.naturalTextRect(); | - | ||||||||||||||||||
1256 | pos += textRect.topLeft().toPoint(); | - | ||||||||||||||||||
1257 | if (dir == Qt::RightToLeft) | - | ||||||||||||||||||
1258 | pos.rx() += textRect.width(); | - | ||||||||||||||||||
1259 | } | - | ||||||||||||||||||
1260 | - | |||||||||||||||||||
1261 | switch (style) { | - | ||||||||||||||||||
1262 | case QTextListFormat::ListDecimal: | - | ||||||||||||||||||
1263 | case QTextListFormat::ListLowerAlpha: | - | ||||||||||||||||||
1264 | case QTextListFormat::ListUpperAlpha: | - | ||||||||||||||||||
1265 | case QTextListFormat::ListLowerRoman: | - | ||||||||||||||||||
1266 | case QTextListFormat::ListUpperRoman: | - | ||||||||||||||||||
1267 | itemText = static_cast<QTextList *>(object)->itemText(bl); | - | ||||||||||||||||||
1268 | size.setWidth(fontMetrics.width(itemText)); | - | ||||||||||||||||||
1269 | size.setHeight(fontMetrics.height()); | - | ||||||||||||||||||
1270 | break; | - | ||||||||||||||||||
1271 | - | |||||||||||||||||||
1272 | case QTextListFormat::ListSquare: | - | ||||||||||||||||||
1273 | case QTextListFormat::ListCircle: | - | ||||||||||||||||||
1274 | case QTextListFormat::ListDisc: | - | ||||||||||||||||||
1275 | size.setWidth(fontMetrics.lineSpacing() / 3); | - | ||||||||||||||||||
1276 | size.setHeight(size.width()); | - | ||||||||||||||||||
1277 | break; | - | ||||||||||||||||||
1278 | - | |||||||||||||||||||
1279 | case QTextListFormat::ListStyleUndefined: | - | ||||||||||||||||||
1280 | return; | - | ||||||||||||||||||
1281 | default: return; | - | ||||||||||||||||||
1282 | } | - | ||||||||||||||||||
1283 | - | |||||||||||||||||||
1284 | QRectF r(pos, size); | - | ||||||||||||||||||
1285 | - | |||||||||||||||||||
1286 | qreal xoff = fontMetrics.width(QLatin1Char(' ')); | - | ||||||||||||||||||
1287 | if (dir == Qt::LeftToRight) | - | ||||||||||||||||||
1288 | xoff = -xoff - size.width(); | - | ||||||||||||||||||
1289 | r.translate( xoff, (fontMetrics.height() / 2) - (size.height() / 2)); | - | ||||||||||||||||||
1290 | - | |||||||||||||||||||
1291 | painter->save(); | - | ||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | painter->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||
1294 | - | |||||||||||||||||||
1295 | if (selectionFormat) { | - | ||||||||||||||||||
1296 | painter->setPen(QPen(selectionFormat->foreground(), 0)); | - | ||||||||||||||||||
1297 | painter->fillRect(r, selectionFormat->background()); | - | ||||||||||||||||||
1298 | } else { | - | ||||||||||||||||||
1299 | QBrush fg = charFormat.foreground(); | - | ||||||||||||||||||
1300 | if (fg == Qt::NoBrush) | - | ||||||||||||||||||
1301 | fg = context.palette.text(); | - | ||||||||||||||||||
1302 | painter->setPen(QPen(fg, 0)); | - | ||||||||||||||||||
1303 | } | - | ||||||||||||||||||
1304 | - | |||||||||||||||||||
1305 | QBrush brush = context.palette.brush(QPalette::Text); | - | ||||||||||||||||||
1306 | - | |||||||||||||||||||
1307 | switch (style) { | - | ||||||||||||||||||
1308 | case QTextListFormat::ListDecimal: | - | ||||||||||||||||||
1309 | case QTextListFormat::ListLowerAlpha: | - | ||||||||||||||||||
1310 | case QTextListFormat::ListUpperAlpha: | - | ||||||||||||||||||
1311 | case QTextListFormat::ListLowerRoman: | - | ||||||||||||||||||
1312 | case QTextListFormat::ListUpperRoman: { | - | ||||||||||||||||||
1313 | QTextLayout layout(itemText, font, q->paintDevice()); | - | ||||||||||||||||||
1314 | layout.setCacheEnabled(true); | - | ||||||||||||||||||
1315 | QTextOption option(Qt::AlignLeft | Qt::AlignAbsolute); | - | ||||||||||||||||||
1316 | option.setTextDirection(dir); | - | ||||||||||||||||||
1317 | layout.setTextOption(option); | - | ||||||||||||||||||
1318 | layout.beginLayout(); | - | ||||||||||||||||||
1319 | QTextLine line = layout.createLine(); | - | ||||||||||||||||||
1320 | if (line.isValid()) | - | ||||||||||||||||||
1321 | line.setLeadingIncluded(true); | - | ||||||||||||||||||
1322 | layout.endLayout(); | - | ||||||||||||||||||
1323 | layout.draw(painter, QPointF(r.left(), pos.y())); | - | ||||||||||||||||||
1324 | break; | - | ||||||||||||||||||
1325 | } | - | ||||||||||||||||||
1326 | case QTextListFormat::ListSquare: | - | ||||||||||||||||||
1327 | painter->fillRect(r, brush); | - | ||||||||||||||||||
1328 | break; | - | ||||||||||||||||||
1329 | case QTextListFormat::ListCircle: | - | ||||||||||||||||||
1330 | painter->setPen(QPen(brush, 0)); | - | ||||||||||||||||||
1331 | painter->drawEllipse(r.translated(0.5, 0.5)); | - | ||||||||||||||||||
1332 | break; | - | ||||||||||||||||||
1333 | case QTextListFormat::ListDisc: | - | ||||||||||||||||||
1334 | painter->setBrush(brush); | - | ||||||||||||||||||
1335 | painter->setPen(Qt::NoPen); | - | ||||||||||||||||||
1336 | painter->drawEllipse(r); | - | ||||||||||||||||||
1337 | break; | - | ||||||||||||||||||
1338 | case QTextListFormat::ListStyleUndefined: | - | ||||||||||||||||||
1339 | break; | - | ||||||||||||||||||
1340 | default: | - | ||||||||||||||||||
1341 | break; | - | ||||||||||||||||||
1342 | } | - | ||||||||||||||||||
1343 | - | |||||||||||||||||||
1344 | painter->restore(); | - | ||||||||||||||||||
1345 | } | - | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | static QFixed flowPosition(const QTextFrame::iterator it) | - | ||||||||||||||||||
1348 | { | - | ||||||||||||||||||
1349 | if (it.atEnd()) | - | ||||||||||||||||||
1350 | return 0; | - | ||||||||||||||||||
1351 | - | |||||||||||||||||||
1352 | if (it.currentFrame()) { | - | ||||||||||||||||||
1353 | return data(it.currentFrame())->position.y; | - | ||||||||||||||||||
1354 | } else { | - | ||||||||||||||||||
1355 | QTextBlock block = it.currentBlock(); | - | ||||||||||||||||||
1356 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||
1357 | if (layout->lineCount() == 0) | - | ||||||||||||||||||
1358 | return QFixed::fromReal(layout->position().y()); | - | ||||||||||||||||||
1359 | else | - | ||||||||||||||||||
1360 | return QFixed::fromReal(layout->position().y() + layout->lineAt(0).y()); | - | ||||||||||||||||||
1361 | } | - | ||||||||||||||||||
1362 | } | - | ||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | static QFixed firstChildPos(const QTextFrame *f) | - | ||||||||||||||||||
1365 | { | - | ||||||||||||||||||
1366 | return flowPosition(f->begin()); | - | ||||||||||||||||||
1367 | } | - | ||||||||||||||||||
1368 | - | |||||||||||||||||||
1369 | QTextLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, | - | ||||||||||||||||||
1370 | int layoutFrom, int layoutTo, QTextTableData *td, | - | ||||||||||||||||||
1371 | QFixed absoluteTableY, bool withPageBreaks) | - | ||||||||||||||||||
1372 | { | - | ||||||||||||||||||
1373 | if(0) QMessageLogger(__FILE__, 15271533, __PRETTY_FUNCTION__).debug() << "layoutCell"; dead code: QMessageLogger(__FILE__, 1533, __PRETTY_FUNCTION__).debug() << "layoutCell"; | - | ||||||||||||||||||
1374 | QTextLayoutStruct layoutStruct; | - | ||||||||||||||||||
1375 | layoutStruct.frame = t; | - | ||||||||||||||||||
1376 | layoutStruct.minimumWidth = 0; | - | ||||||||||||||||||
1377 | layoutStruct.maximumWidth = (2147483647/256); | - | ||||||||||||||||||
1378 | layoutStruct.y = 0; | - | ||||||||||||||||||
1379 | - | |||||||||||||||||||
1380 | const QTextFormat fmt = cell.format(); | - | ||||||||||||||||||
1381 | const QFixed topPadding = td->topPadding(fmt); | - | ||||||||||||||||||
1382 | if (withPageBreaks) { | - | ||||||||||||||||||
1383 | layoutStruct.frameY = absoluteTableY + td->rowPositions.at(cell.row()) + topPadding; | - | ||||||||||||||||||
1384 | } | - | ||||||||||||||||||
1385 | layoutStruct.x_left = 0; | - | ||||||||||||||||||
1386 | layoutStruct.x_right = width; | - | ||||||||||||||||||
1387 | layoutStruct.pageHeight = QFixed::fromReal(document->pageSize().height()); | - | ||||||||||||||||||
1388 | if (layoutStruct.pageHeight < 0 || !withPageBreaks) | - | ||||||||||||||||||
1389 | layoutStruct.pageHeight = (2147483647/256); | - | ||||||||||||||||||
1390 | const int currentPage = layoutStruct.currentPage(); | - | ||||||||||||||||||
1391 | layoutStruct.pageTopMargin = td->effectiveTopMargin + td->cellSpacing + td->border + topPadding; | - | ||||||||||||||||||
1392 | layoutStruct.pageBottomMargin = td->effectiveBottomMargin + td->cellSpacing + td->border + td->bottomPadding(fmt); | - | ||||||||||||||||||
1393 | layoutStruct.pageBottom = (currentPage + 1) * layoutStruct.pageHeight - layoutStruct.pageBottomMargin; | - | ||||||||||||||||||
1394 | - | |||||||||||||||||||
1395 | layoutStruct.fullLayout = true; | - | ||||||||||||||||||
1396 | - | |||||||||||||||||||
1397 | QFixed pageTop = currentPage * layoutStruct.pageHeight + layoutStruct.pageTopMargin - layoutStruct.frameY; | - | ||||||||||||||||||
1398 | layoutStruct.y = qMax(layoutStruct.y, pageTop); | - | ||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | const QList<QTextFrame *> childFrames = td->childFrameMap.values(cell.row() + cell.column() * t->rows()); | - | ||||||||||||||||||
1401 | for (int i = 0; i < childFrames.size(); ++i) { | - | ||||||||||||||||||
1402 | QTextFrame *frame = childFrames.at(i); | - | ||||||||||||||||||
1403 | QTextFrameData *cd = data(frame); | - | ||||||||||||||||||
1404 | cd->sizeDirty = true; | - | ||||||||||||||||||
1405 | } | - | ||||||||||||||||||
1406 | - | |||||||||||||||||||
1407 | layoutFlow(cell.begin(), &layoutStruct, layoutFrom, layoutTo, width); | - | ||||||||||||||||||
1408 | - | |||||||||||||||||||
1409 | QFixed floatMinWidth; | - | ||||||||||||||||||
1410 | - | |||||||||||||||||||
1411 | - | |||||||||||||||||||
1412 | - | |||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | for (int i = 0; i < childFrames.size(); ++i) { | - | ||||||||||||||||||
1416 | QTextFrame *frame = childFrames.at(i); | - | ||||||||||||||||||
1417 | QTextFrameData *cd = data(frame); | - | ||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | if (frame->frameFormat().position() != QTextFrameFormat::InFlow) | - | ||||||||||||||||||
1420 | layoutStruct.y = qMax(layoutStruct.y, cd->position.y + cd->size.height); | - | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | floatMinWidth = qMax(floatMinWidth, cd->minimumWidth); | - | ||||||||||||||||||
1423 | } | - | ||||||||||||||||||
1424 | - | |||||||||||||||||||
1425 | - | |||||||||||||||||||
1426 | - | |||||||||||||||||||
1427 | layoutStruct.maximumWidth = qMax(layoutStruct.maximumWidth, floatMinWidth); | - | ||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | - | |||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | data(t)->floats.clear(); | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | - | |||||||||||||||||||
1434 | - | |||||||||||||||||||
1435 | return layoutStruct; | - | ||||||||||||||||||
1436 | } | - | ||||||||||||||||||
1437 | - | |||||||||||||||||||
1438 | QRectF QTextDocumentLayoutPrivate::layoutTable(QTextTable *table, int layoutFrom, int layoutTo, QFixed parentY) | - | ||||||||||||||||||
1439 | { | - | ||||||||||||||||||
1440 | if(0) QMessageLogger(__FILE__, 16021608, __PRETTY_FUNCTION__).debug() << "layoutTable"; dead code: QMessageLogger(__FILE__, 1608, __PRETTY_FUNCTION__).debug() << "layoutTable"; | - | ||||||||||||||||||
1441 | QTextTableData *td = static_cast<QTextTableData *>(data(table)); | - | ||||||||||||||||||
1442 | ((!(td->sizeDirty)) ? qt_assert("td->sizeDirty",__FILE__,16041610) : qt_noop()); | - | ||||||||||||||||||
1443 | const int rows = table->rows(); | - | ||||||||||||||||||
1444 | const int columns = table->columns(); | - | ||||||||||||||||||
1445 | - | |||||||||||||||||||
1446 | const QTextTableFormat fmt = table->format(); | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | td->childFrameMap.clear(); | - | ||||||||||||||||||
1449 | { | - | ||||||||||||||||||
1450 | const QList<QTextFrame *> children = table->childFrames(); | - | ||||||||||||||||||
1451 | for (int i = 0; i < children.count()
| 0 | ||||||||||||||||||
1452 | QTextFrame *frame = children.at(i); | - | ||||||||||||||||||
1453 | QTextTableCell cell = table->cellAt(frame->firstPosition()); | - | ||||||||||||||||||
1454 | td->childFrameMap.insertMulti(cell.row() + cell.column() * rows, frame); | - | ||||||||||||||||||
1455 | } never executed: end of block | 0 | ||||||||||||||||||
1456 | } | - | ||||||||||||||||||
1457 | - | |||||||||||||||||||
1458 | QVector<QTextLength> columnWidthConstraints = fmt.columnWidthConstraints(); | - | ||||||||||||||||||
1459 | if (columnWidthConstraints.size() != columns
| 0 | ||||||||||||||||||
1460 | columnWidthConstraints.resize(columns); never executed: columnWidthConstraints.resize(columns); | 0 | ||||||||||||||||||
1461 | ((!(columnWidthConstraints.count() == columns)) ? qt_assert("columnWidthConstraints.count() == columns",__FILE__,16231629) : qt_noop()); | - | ||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | const QFixed cellSpacing = td->cellSpacing = QFixed::fromReal(scaleToDevice(fmt.cellSpacing())); | - | ||||||||||||||||||
1464 | td->deviceScale = scaleToDevice(qreal(1)); | - | ||||||||||||||||||
1465 | td->cellPadding = QFixed::fromReal(scaleToDevice(fmt.cellPadding())); | - | ||||||||||||||||||
1466 | const QFixed leftMargin = td->leftMargin + td->border + td->padding; | - | ||||||||||||||||||
1467 | const QFixed rightMargin = td->rightMargin + td->border + td->padding; | - | ||||||||||||||||||
1468 | const QFixed topMargin = td->topMargin + td->border + td->padding; | - | ||||||||||||||||||
1469 | - | |||||||||||||||||||
1470 | const QFixed absoluteTableY = parentY + td->position.y; | - | ||||||||||||||||||
1471 | - | |||||||||||||||||||
1472 | const QTextOption::WrapMode oldDefaultWrapMode = docPrivate->defaultTextOption.wrapMode(); | - | ||||||||||||||||||
1473 | - | |||||||||||||||||||
1474 | recalc_minmax_widths: code before this statement never executed: recalc_minmax_widths: | 0 | ||||||||||||||||||
1475 | - | |||||||||||||||||||
1476 | QFixed remainingWidth = td->contentsWidth; | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | remainingWidth -= columns * 2 * td->border; | - | ||||||||||||||||||
1479 | - | |||||||||||||||||||
1480 | remainingWidth -= (columns - 1) * cellSpacing; | - | ||||||||||||||||||
1481 | - | |||||||||||||||||||
1482 | remainingWidth -= 2 * cellSpacing; | - | ||||||||||||||||||
1483 | - | |||||||||||||||||||
1484 | const QFixed initialTotalWidth = remainingWidth; | - | ||||||||||||||||||
1485 | - | |||||||||||||||||||
1486 | td->widths.resize(columns); | - | ||||||||||||||||||
1487 | td->widths.fill(0); | - | ||||||||||||||||||
1488 | - | |||||||||||||||||||
1489 | td->minWidths.resize(columns); | - | ||||||||||||||||||
1490 | - | |||||||||||||||||||
1491 | - | |||||||||||||||||||
1492 | - | |||||||||||||||||||
1493 | td->minWidths.fill(1); | - | ||||||||||||||||||
1494 | - | |||||||||||||||||||
1495 | td->maxWidths.resize(columns); | - | ||||||||||||||||||
1496 | td->maxWidths.fill((2147483647/256)); | - | ||||||||||||||||||
1497 | - | |||||||||||||||||||
1498 | - | |||||||||||||||||||
1499 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1500 | for (int row = 0; row < rows
| 0 | ||||||||||||||||||
1501 | const QTextTableCell cell = table->cellAt(row, i); | - | ||||||||||||||||||
1502 | const int cspan = cell.columnSpan(); | - | ||||||||||||||||||
1503 | - | |||||||||||||||||||
1504 | if (cspan > 1
| 0 | ||||||||||||||||||
1505 | continue; never executed: continue; | 0 | ||||||||||||||||||
1506 | - | |||||||||||||||||||
1507 | const QTextFormat fmt = cell.format(); | - | ||||||||||||||||||
1508 | const QFixed leftPadding = td->leftPadding(fmt); | - | ||||||||||||||||||
1509 | const QFixed rightPadding = td->rightPadding(fmt); | - | ||||||||||||||||||
1510 | const QFixed widthPadding = leftPadding + rightPadding; | - | ||||||||||||||||||
1511 | - | |||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | - | |||||||||||||||||||
1515 | QTextLayoutStruct layoutStruct = layoutCell(table, cell, (2147483647/256), layoutFrom, | - | ||||||||||||||||||
1516 | layoutTo, td, absoluteTableY, | - | ||||||||||||||||||
1517 | false); | - | ||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | QFixed widthToDistribute = layoutStruct.minimumWidth + widthPadding; | - | ||||||||||||||||||
1521 | for (int n = 0; n < cspan
| 0 | ||||||||||||||||||
1522 | const int col = i + n; | - | ||||||||||||||||||
1523 | QFixed w = widthToDistribute / (cspan - n); | - | ||||||||||||||||||
1524 | td->minWidths[col] = qMax(td->minWidths.at(col), w); | - | ||||||||||||||||||
1525 | widthToDistribute -= td->minWidths.at(col); | - | ||||||||||||||||||
1526 | if (widthToDistribute <= 0
| 0 | ||||||||||||||||||
1527 | break; never executed: break; | 0 | ||||||||||||||||||
1528 | } never executed: end of block | 0 | ||||||||||||||||||
1529 | - | |||||||||||||||||||
1530 | QFixed maxW = td->maxWidths.at(i); | - | ||||||||||||||||||
1531 | if (layoutStruct.maximumWidth != (2147483647/256)
| 0 | ||||||||||||||||||
1532 | if (maxW == (2147483647/256)
| 0 | ||||||||||||||||||
1533 | maxW = layoutStruct.maximumWidth + widthPadding; never executed: maxW = layoutStruct.maximumWidth + widthPadding; | 0 | ||||||||||||||||||
1534 | else | - | ||||||||||||||||||
1535 | maxW = qMax(maxW, layoutStruct.maximumWidth + widthPadding); never executed: maxW = qMax(maxW, layoutStruct.maximumWidth + widthPadding); | 0 | ||||||||||||||||||
1536 | } | - | ||||||||||||||||||
1537 | if (maxW == (2147483647/256)
| 0 | ||||||||||||||||||
1538 | continue; never executed: continue; | 0 | ||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | widthToDistribute = maxW; | - | ||||||||||||||||||
1541 | for (int n = 0; n < cspan
| 0 | ||||||||||||||||||
1542 | const int col = i + n; | - | ||||||||||||||||||
1543 | QFixed w = widthToDistribute / (cspan - n); | - | ||||||||||||||||||
1544 | td->maxWidths[col] = qMax(td->minWidths.at(col), w); | - | ||||||||||||||||||
1545 | widthToDistribute -= td->maxWidths.at(col); | - | ||||||||||||||||||
1546 | if (widthToDistribute <= 0
| 0 | ||||||||||||||||||
1547 | break; never executed: break; | 0 | ||||||||||||||||||
1548 | } never executed: end of block | 0 | ||||||||||||||||||
1549 | } never executed: end of block | 0 | ||||||||||||||||||
1550 | } never executed: end of block | 0 | ||||||||||||||||||
1551 | - | |||||||||||||||||||
1552 | - | |||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | QFixed totalPercentage; | - | ||||||||||||||||||
1555 | int variableCols = 0; | - | ||||||||||||||||||
1556 | QFixed totalMinWidth = 0; | - | ||||||||||||||||||
1557 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1558 | const QTextLength &length = columnWidthConstraints.at(i); | - | ||||||||||||||||||
1559 | if (length.type() == QTextLength::FixedLength
| 0 | ||||||||||||||||||
1560 | td->minWidths[i] = td->widths[i] = qMax(scaleToDevice(QFixed::fromReal(length.rawValue())), td->minWidths.at(i)); | - | ||||||||||||||||||
1561 | remainingWidth -= td->widths.at(i); | - | ||||||||||||||||||
1562 | } never executed: else if (length.type() == QTextLength::PercentageLengthend of block
| 0 | ||||||||||||||||||
1563 | totalPercentage += QFixed::fromReal(length.rawValue()); | - | ||||||||||||||||||
1564 | } never executed: else if (length.type() == QTextLength::VariableLengthend of block
| 0 | ||||||||||||||||||
1565 | variableCols++; | - | ||||||||||||||||||
1566 | - | |||||||||||||||||||
1567 | td->widths[i] = td->minWidths.at(i); | - | ||||||||||||||||||
1568 | remainingWidth -= td->minWidths.at(i); | - | ||||||||||||||||||
1569 | } never executed: end of block | 0 | ||||||||||||||||||
1570 | totalMinWidth += td->minWidths.at(i); | - | ||||||||||||||||||
1571 | } never executed: end of block | 0 | ||||||||||||||||||
1572 | - | |||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | { | - | ||||||||||||||||||
1575 | const QFixed totalPercentagedWidth = initialTotalWidth * totalPercentage / 100; | - | ||||||||||||||||||
1576 | QFixed remainingMinWidths = totalMinWidth; | - | ||||||||||||||||||
1577 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1578 | remainingMinWidths -= td->minWidths.at(i); | - | ||||||||||||||||||
1579 | if (columnWidthConstraints.at(i).type() == QTextLength::PercentageLength
| 0 | ||||||||||||||||||
1580 | const QFixed allottedPercentage = QFixed::fromReal(columnWidthConstraints.at(i).rawValue()); | - | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | const QFixed percentWidth = totalPercentagedWidth * allottedPercentage / totalPercentage; | - | ||||||||||||||||||
1583 | if (percentWidth >= td->minWidths.at(i)
| 0 | ||||||||||||||||||
1584 | td->widths[i] = qBound(td->minWidths.at(i), percentWidth, remainingWidth - remainingMinWidths); | - | ||||||||||||||||||
1585 | } never executed: else {end of block | 0 | ||||||||||||||||||
1586 | td->widths[i] = td->minWidths.at(i); | - | ||||||||||||||||||
1587 | } never executed: end of block | 0 | ||||||||||||||||||
1588 | remainingWidth -= td->widths.at(i); | - | ||||||||||||||||||
1589 | } never executed: end of block | 0 | ||||||||||||||||||
1590 | } never executed: end of block | 0 | ||||||||||||||||||
1591 | } | - | ||||||||||||||||||
1592 | - | |||||||||||||||||||
1593 | - | |||||||||||||||||||
1594 | if (variableCols > 0
| 0 | ||||||||||||||||||
1595 | QVarLengthArray<int> columnsWithProperMaxSize; | - | ||||||||||||||||||
1596 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1597 | if (columnWidthConstraints.at(i).type() == QTextLength::VariableLength
| 0 | ||||||||||||||||||
1598 | && td->maxWidths.at(i) != (2147483647/256)
| 0 | ||||||||||||||||||
1599 | columnsWithProperMaxSize.append(i); never executed: columnsWithProperMaxSize.append(i); | 0 | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | QFixed lastRemainingWidth = remainingWidth; | - | ||||||||||||||||||
1602 | while (remainingWidth > 0
| 0 | ||||||||||||||||||
1603 | for (int k = 0; k < columnsWithProperMaxSize.count()
| 0 | ||||||||||||||||||
1604 | const int col = columnsWithProperMaxSize[k]; | - | ||||||||||||||||||
1605 | const int colsLeft = columnsWithProperMaxSize.count() - k; | - | ||||||||||||||||||
1606 | const QFixed w = qMin(td->maxWidths.at(col) - td->widths.at(col), remainingWidth / colsLeft); | - | ||||||||||||||||||
1607 | td->widths[col] += w; | - | ||||||||||||||||||
1608 | remainingWidth -= w; | - | ||||||||||||||||||
1609 | } never executed: end of block | 0 | ||||||||||||||||||
1610 | if (remainingWidth == lastRemainingWidth
| 0 | ||||||||||||||||||
1611 | break; never executed: break; | 0 | ||||||||||||||||||
1612 | lastRemainingWidth = remainingWidth; | - | ||||||||||||||||||
1613 | } never executed: end of block | 0 | ||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | if (remainingWidth > 0
| 0 | ||||||||||||||||||
1616 | - | |||||||||||||||||||
1617 | && fmt.width().type() != QTextLength::VariableLength
| 0 | ||||||||||||||||||
1618 | const QFixed widthPerAnySizedCol = remainingWidth / variableCols; | - | ||||||||||||||||||
1619 | for (int col = 0; col < columns
| 0 | ||||||||||||||||||
1620 | if (columnWidthConstraints.at(col).type() == QTextLength::VariableLength
| 0 | ||||||||||||||||||
1621 | td->widths[col] += widthPerAnySizedCol; never executed: td->widths[col] += widthPerAnySizedCol; | 0 | ||||||||||||||||||
1622 | } never executed: end of block | 0 | ||||||||||||||||||
1623 | } never executed: end of block | 0 | ||||||||||||||||||
1624 | } never executed: end of block | 0 | ||||||||||||||||||
1625 | - | |||||||||||||||||||
1626 | td->columnPositions.resize(columns); | - | ||||||||||||||||||
1627 | td->columnPositions[0] = leftMargin + cellSpacing + td->border; | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | for (int i = 1; i < columns
| 0 | ||||||||||||||||||
1630 | td->columnPositions[i] = td->columnPositions.at(i-1) + td->widths.at(i-1) + 2 * td->border + cellSpacing; never executed: td->columnPositions[i] = td->columnPositions.at(i-1) + td->widths.at(i-1) + 2 * td->border + cellSpacing; | 0 | ||||||||||||||||||
1631 | - | |||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | const QFixed contentsWidth = td->columnPositions.lastconstLast() + td->widths.lastconstLast() + td->padding + td->border + cellSpacing - leftMargin; | - | ||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | - | |||||||||||||||||||
1636 | - | |||||||||||||||||||
1637 | if (docPrivate->defaultTextOption.wrapMode() == QTextOption::WrapAtWordBoundaryOrAnywhere
| 0 | ||||||||||||||||||
1638 | && contentsWidth > td->contentsWidth
| 0 | ||||||||||||||||||
1639 | docPrivate->defaultTextOption.setWrapMode(QTextOption::WrapAnywhere); | - | ||||||||||||||||||
1640 | - | |||||||||||||||||||
1641 | goto never executed: recalc_minmax_widths;goto recalc_minmax_widths; never executed: goto recalc_minmax_widths; | 0 | ||||||||||||||||||
1642 | } | - | ||||||||||||||||||
1643 | - | |||||||||||||||||||
1644 | td->contentsWidth = contentsWidth; | - | ||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | docPrivate->defaultTextOption.setWrapMode(oldDefaultWrapMode); | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | td->heights.resize(rows); | - | ||||||||||||||||||
1649 | td->heights.fill(0); | - | ||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | td->rowPositions.resize(rows); | - | ||||||||||||||||||
1652 | td->rowPositions[0] = topMargin + cellSpacing + td->border; | - | ||||||||||||||||||
1653 | - | |||||||||||||||||||
1654 | bool haveRowSpannedCells = false; | - | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | - | |||||||||||||||||||
1657 | QVector<QFixed> cellHeights; | - | ||||||||||||||||||
1658 | cellHeights.reserve(rows * columns); | - | ||||||||||||||||||
1659 | - | |||||||||||||||||||
1660 | QFixed pageHeight = QFixed::fromReal(document->pageSize().height()); | - | ||||||||||||||||||
1661 | if (pageHeight <= 0
| 0 | ||||||||||||||||||
1662 | pageHeight = (2147483647/256); never executed: pageHeight = (2147483647/256); | 0 | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | QVector<QFixed> heightToDistribute; | - | ||||||||||||||||||
1665 | heightToDistribute.resize(columns); | - | ||||||||||||||||||
1666 | - | |||||||||||||||||||
1667 | td->headerHeight = 0; | - | ||||||||||||||||||
1668 | const int headerRowCount = qMin(table->format().headerRowCount(), rows - 1); | - | ||||||||||||||||||
1669 | const QFixed originalTopMargin = td->effectiveTopMargin; | - | ||||||||||||||||||
1670 | bool hasDroppedTable = false; | - | ||||||||||||||||||
1671 | - | |||||||||||||||||||
1672 | - | |||||||||||||||||||
1673 | - | |||||||||||||||||||
1674 | - | |||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | for (int r = 0; r < rows
| 0 | ||||||||||||||||||
1677 | td->calcRowPosition(r); | - | ||||||||||||||||||
1678 | - | |||||||||||||||||||
1679 | const int tableStartPage = (absoluteTableY / pageHeight).truncate(); | - | ||||||||||||||||||
1680 | const int currentPage = ((td->rowPositions[.at(r]) + absoluteTableY) / pageHeight).truncate(); | - | ||||||||||||||||||
1681 | const QFixed pageBottom = (currentPage + 1) * pageHeight - td->effectiveBottomMargin - absoluteTableY - cellSpacing - td->border; | - | ||||||||||||||||||
1682 | const QFixed pageTop = currentPage * pageHeight + td->effectiveTopMargin - absoluteTableY + cellSpacing + td->border; | - | ||||||||||||||||||
1683 | const QFixed nextPageTop = pageTop + pageHeight; | - | ||||||||||||||||||
1684 | - | |||||||||||||||||||
1685 | if (td->rowPositions[.at(r]) > pageBottom
| 0 | ||||||||||||||||||
1686 | td->rowPositions[r] = nextPageTop; never executed: td->rowPositions[r] = nextPageTop; | 0 | ||||||||||||||||||
1687 | else if (td->rowPositions[.at(r]) < pageTop
| 0 | ||||||||||||||||||
1688 | td->rowPositions[r] = pageTop; never executed: td->rowPositions[r] = pageTop; | 0 | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | bool dropRowToNextPage = true; | - | ||||||||||||||||||
1691 | int cellCountBeforeRow = cellHeights.size(); | - | ||||||||||||||||||
1692 | - | |||||||||||||||||||
1693 | - | |||||||||||||||||||
1694 | - | |||||||||||||||||||
1695 | QFixed dropDistance = 0; | - | ||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | relayout: code before this statement never executed: relayout: | 0 | ||||||||||||||||||
1698 | const int rowStartPage = ((td->rowPositions[.at(r]) + absoluteTableY) / pageHeight).truncate(); | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | - | |||||||||||||||||||
1701 | if (r <= headerRowCount
| 0 | ||||||||||||||||||
1702 | td->rowPositions[0] = nextPageTop; | - | ||||||||||||||||||
1703 | cellHeights.clear(); | - | ||||||||||||||||||
1704 | td->effectiveTopMargin = originalTopMargin; | - | ||||||||||||||||||
1705 | hasDroppedTable = true; | - | ||||||||||||||||||
1706 | r = -1; | - | ||||||||||||||||||
1707 | continue; never executed: continue; | 0 | ||||||||||||||||||
1708 | } | - | ||||||||||||||||||
1709 | - | |||||||||||||||||||
1710 | int rowCellCount = 0; | - | ||||||||||||||||||
1711 | for (int c = 0; c < columns
| 0 | ||||||||||||||||||
1712 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
1713 | const int rspan = cell.rowSpan(); | - | ||||||||||||||||||
1714 | const int cspan = cell.columnSpan(); | - | ||||||||||||||||||
1715 | - | |||||||||||||||||||
1716 | if (cspan > 1
| 0 | ||||||||||||||||||
1717 | continue; never executed: continue; | 0 | ||||||||||||||||||
1718 | - | |||||||||||||||||||
1719 | if (rspan > 1
| 0 | ||||||||||||||||||
1720 | haveRowSpannedCells = true; | - | ||||||||||||||||||
1721 | - | |||||||||||||||||||
1722 | const int cellRow = cell.row(); | - | ||||||||||||||||||
1723 | if (cellRow != r
| 0 | ||||||||||||||||||
1724 | - | |||||||||||||||||||
1725 | if (cellRow + rspan - 1 == r
| 0 | ||||||||||||||||||
1726 | td->heights[r] = qMax(td->heights.at(r), heightToDistribute.at(c) - dropDistance); never executed: td->heights[r] = qMax(td->heights.at(r), heightToDistribute.at(c) - dropDistance); | 0 | ||||||||||||||||||
1727 | continue; never executed: continue; | 0 | ||||||||||||||||||
1728 | } | - | ||||||||||||||||||
1729 | } never executed: end of block | 0 | ||||||||||||||||||
1730 | - | |||||||||||||||||||
1731 | const QTextFormat fmt = cell.format(); | - | ||||||||||||||||||
1732 | - | |||||||||||||||||||
1733 | const QFixed topPadding = td->topPadding(fmt); | - | ||||||||||||||||||
1734 | const QFixed bottomPadding = td->bottomPadding(fmt); | - | ||||||||||||||||||
1735 | const QFixed leftPadding = td->leftPadding(fmt); | - | ||||||||||||||||||
1736 | const QFixed rightPadding = td->rightPadding(fmt); | - | ||||||||||||||||||
1737 | const QFixed widthPadding = leftPadding + rightPadding; | - | ||||||||||||||||||
1738 | - | |||||||||||||||||||
1739 | ++rowCellCount; | - | ||||||||||||||||||
1740 | - | |||||||||||||||||||
1741 | const QFixed width = td->cellWidth(c, cspan) - widthPadding; | - | ||||||||||||||||||
1742 | QTextLayoutStruct layoutStruct = layoutCell(table, cell, width, | - | ||||||||||||||||||
1743 | layoutFrom, layoutTo, | - | ||||||||||||||||||
1744 | td, absoluteTableY, | - | ||||||||||||||||||
1745 | true); | - | ||||||||||||||||||
1746 | - | |||||||||||||||||||
1747 | const QFixed height = layoutStruct.y + bottomPadding + topPadding; | - | ||||||||||||||||||
1748 | - | |||||||||||||||||||
1749 | if (rspan > 1
| 0 | ||||||||||||||||||
1750 | heightToDistribute[c] = height + dropDistance; never executed: heightToDistribute[c] = height + dropDistance; | 0 | ||||||||||||||||||
1751 | else | - | ||||||||||||||||||
1752 | td->heights[r] = qMax(td->heights.at(r), height); never executed: td->heights[r] = qMax(td->heights.at(r), height); | 0 | ||||||||||||||||||
1753 | - | |||||||||||||||||||
1754 | cellHeights.append(layoutStruct.y); | - | ||||||||||||||||||
1755 | - | |||||||||||||||||||
1756 | QFixed childPos = td->rowPositions.at(r) + topPadding + flowPosition(cell.begin()); | - | ||||||||||||||||||
1757 | if (childPos < pageBottom
| 0 | ||||||||||||||||||
1758 | dropRowToNextPage = false; never executed: dropRowToNextPage = false; | 0 | ||||||||||||||||||
1759 | } never executed: end of block | 0 | ||||||||||||||||||
1760 | - | |||||||||||||||||||
1761 | if (rowCellCount > 0
| 0 | ||||||||||||||||||
1762 | dropDistance = nextPageTop - td->rowPositions[.at(r];); | - | ||||||||||||||||||
1763 | td->rowPositions[r] = nextPageTop; | - | ||||||||||||||||||
1764 | td->heights[r] = 0; | - | ||||||||||||||||||
1765 | dropRowToNextPage = false; | - | ||||||||||||||||||
1766 | cellHeights.resize(cellCountBeforeRow); | - | ||||||||||||||||||
1767 | if (r > headerRowCount
| 0 | ||||||||||||||||||
1768 | td->heights[r - 1] = pageBottom - td->rowPositions[.at(r - 1];); never executed: td->heights[r - 1] = pageBottom - td->rowPositions.at(r - 1); | 0 | ||||||||||||||||||
1769 | goto never executed: relayout;goto relayout; never executed: goto relayout; | 0 | ||||||||||||||||||
1770 | } | - | ||||||||||||||||||
1771 | - | |||||||||||||||||||
1772 | if (haveRowSpannedCells
| 0 | ||||||||||||||||||
1773 | const QFixed effectiveHeight = td->heights.at(r) + td->border + cellSpacing + td->border; | - | ||||||||||||||||||
1774 | for (int c = 0; c < columns
| 0 | ||||||||||||||||||
1775 | heightToDistribute[c] = qMax(heightToDistribute.at(c) - effectiveHeight - dropDistance, QFixed(0)); never executed: heightToDistribute[c] = qMax(heightToDistribute.at(c) - effectiveHeight - dropDistance, QFixed(0)); | 0 | ||||||||||||||||||
1776 | } never executed: end of block | 0 | ||||||||||||||||||
1777 | - | |||||||||||||||||||
1778 | if (r == headerRowCount - 1
| 0 | ||||||||||||||||||
1779 | td->headerHeight = td->rowPositions[.at(r]) + td->heights[.at(r]) - td->rowPositions[.at(0]) + td->cellSpacing + 2 * td->border; | - | ||||||||||||||||||
1780 | td->headerHeight -= td->headerHeight * (td->headerHeight / pageHeight).truncate(); | - | ||||||||||||||||||
1781 | td->effectiveTopMargin += td->headerHeight; | - | ||||||||||||||||||
1782 | } never executed: end of block | 0 | ||||||||||||||||||
1783 | } never executed: end of block | 0 | ||||||||||||||||||
1784 | - | |||||||||||||||||||
1785 | td->effectiveTopMargin = originalTopMargin; | - | ||||||||||||||||||
1786 | - | |||||||||||||||||||
1787 | - | |||||||||||||||||||
1788 | - | |||||||||||||||||||
1789 | td->cellVerticalOffsets.resize(rows * columns); | - | ||||||||||||||||||
1790 | int cellIndex = 0; | - | ||||||||||||||||||
1791 | for (int r = 0; r < rows
| 0 | ||||||||||||||||||
1792 | for (int c = 0; c < columns
| 0 | ||||||||||||||||||
1793 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
1794 | if (cell.row() != r
| 0 | ||||||||||||||||||
1795 | continue; never executed: continue; | 0 | ||||||||||||||||||
1796 | - | |||||||||||||||||||
1797 | const int rowSpan = cell.rowSpan(); | - | ||||||||||||||||||
1798 | const QFixed availableHeight = td->rowPositions.at(r + rowSpan - 1) + td->heights.at(r + rowSpan - 1) - td->rowPositions.at(r); | - | ||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | const QTextCharFormat cellFormat = cell.format(); | - | ||||||||||||||||||
1801 | const QFixed cellHeight = cellHeights.at(cellIndex++) + td->topPadding(cellFormat) + td->bottomPadding(cellFormat); | - | ||||||||||||||||||
1802 | - | |||||||||||||||||||
1803 | QFixed offset = 0; | - | ||||||||||||||||||
1804 | switch (cellFormat.verticalAlignment()) { | - | ||||||||||||||||||
1805 | case never executed: QTextCharFormat::AlignMiddle:case QTextCharFormat::AlignMiddle: never executed: case QTextCharFormat::AlignMiddle: | 0 | ||||||||||||||||||
1806 | offset = (availableHeight - cellHeight) / 2; | - | ||||||||||||||||||
1807 | break; never executed: break; | 0 | ||||||||||||||||||
1808 | case never executed: QTextCharFormat::AlignBottom:case QTextCharFormat::AlignBottom: never executed: case QTextCharFormat::AlignBottom: | 0 | ||||||||||||||||||
1809 | offset = availableHeight - cellHeight; | - | ||||||||||||||||||
1810 | break; never executed: break; | 0 | ||||||||||||||||||
1811 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
1812 | break; never executed: break; | 0 | ||||||||||||||||||
1813 | }; | - | ||||||||||||||||||
1814 | - | |||||||||||||||||||
1815 | for (int rd = 0; rd < cell.rowSpan()
| 0 | ||||||||||||||||||
1816 | for (int cd = 0; cd < cell.columnSpan()
| 0 | ||||||||||||||||||
1817 | const int index = (c + cd) + (r + rd) * columns; | - | ||||||||||||||||||
1818 | td->cellVerticalOffsets[index] = offset; | - | ||||||||||||||||||
1819 | } never executed: end of block | 0 | ||||||||||||||||||
1820 | } never executed: end of block | 0 | ||||||||||||||||||
1821 | } never executed: end of block | 0 | ||||||||||||||||||
1822 | } never executed: end of block | 0 | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | td->minimumWidth = td->columnPositions.at(0); | - | ||||||||||||||||||
1825 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1826 | td->minimumWidth += td->minWidths.at(i) + 2 * td->border + cellSpacing; | - | ||||||||||||||||||
1827 | } never executed: end of block | 0 | ||||||||||||||||||
1828 | td->minimumWidth += rightMargin - td->border; | - | ||||||||||||||||||
1829 | - | |||||||||||||||||||
1830 | td->maximumWidth = td->columnPositions.at(0); | - | ||||||||||||||||||
1831 | for (int i = 0; i < columns
| 0 | ||||||||||||||||||
1832 | if (td->maxWidths.at(i) != (2147483647/256)
| 0 | ||||||||||||||||||
1833 | td->maximumWidth += td->maxWidths.at(i) + 2 * td->border + cellSpacing; never executed: td->maximumWidth += td->maxWidths.at(i) + 2 * td->border + cellSpacing; | 0 | ||||||||||||||||||
1834 | td->maximumWidth += rightMargin - td->border; | - | ||||||||||||||||||
1835 | - | |||||||||||||||||||
1836 | td->updateTableSize(); | - | ||||||||||||||||||
1837 | td->sizeDirty = false; | - | ||||||||||||||||||
1838 | return never executed: QRectF();return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||
1839 | } | - | ||||||||||||||||||
1840 | - | |||||||||||||||||||
1841 | void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *currentLine) | - | ||||||||||||||||||
1842 | { | - | ||||||||||||||||||
1843 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
1844 | - | |||||||||||||||||||
1845 | QTextFrame *parent = frame->parentFrame(); | - | ||||||||||||||||||
1846 | ((!(parent)) ? qt_assert("parent",__FILE__,20082014) : qt_noop()); | - | ||||||||||||||||||
1847 | QTextFrameData *pd = data(parent); | - | ||||||||||||||||||
1848 | ((!(pd && pd->currentLayoutStruct)) ? qt_assert("pd && pd->currentLayoutStruct",__FILE__,20102016) : qt_noop()); | - | ||||||||||||||||||
1849 | - | |||||||||||||||||||
1850 | QTextLayoutStruct *layoutStruct = pd->currentLayoutStruct; | - | ||||||||||||||||||
1851 | - | |||||||||||||||||||
1852 | if (!pd->floats.contains(frame)) | - | ||||||||||||||||||
1853 | pd->floats.append(frame); | - | ||||||||||||||||||
1854 | fd->layoutDirty = true; | - | ||||||||||||||||||
1855 | ((!(!fd->sizeDirty)) ? qt_assert("!fd->sizeDirty",__FILE__,20172023) : qt_noop()); | - | ||||||||||||||||||
1856 | - | |||||||||||||||||||
1857 | - | |||||||||||||||||||
1858 | QFixed y = layoutStruct->y; | - | ||||||||||||||||||
1859 | if (currentLine) { | - | ||||||||||||||||||
1860 | QFixed left, right; | - | ||||||||||||||||||
1861 | floatMargins(y, layoutStruct, &left, &right); | - | ||||||||||||||||||
1862 | - | |||||||||||||||||||
1863 | if (right - left < QFixed::fromReal(currentLine->naturalTextWidth()) + fd->size.width) { | - | ||||||||||||||||||
1864 | layoutStruct->pendingFloats.append(frame); | - | ||||||||||||||||||
1865 | - | |||||||||||||||||||
1866 | return; | - | ||||||||||||||||||
1867 | } | - | ||||||||||||||||||
1868 | } | - | ||||||||||||||||||
1869 | - | |||||||||||||||||||
1870 | bool frameSpansIntoNextPage = (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom); | - | ||||||||||||||||||
1871 | if (frameSpansIntoNextPage && fd->size.height <= layoutStruct->pageHeight) { | - | ||||||||||||||||||
1872 | layoutStruct->newPage(); | - | ||||||||||||||||||
1873 | y = layoutStruct->y; | - | ||||||||||||||||||
1874 | - | |||||||||||||||||||
1875 | frameSpansIntoNextPage = false; | - | ||||||||||||||||||
1876 | } | - | ||||||||||||||||||
1877 | - | |||||||||||||||||||
1878 | y = findY(y, layoutStruct, fd->size.width); | - | ||||||||||||||||||
1879 | - | |||||||||||||||||||
1880 | QFixed left, right; | - | ||||||||||||||||||
1881 | floatMargins(y, layoutStruct, &left, &right); | - | ||||||||||||||||||
1882 | - | |||||||||||||||||||
1883 | if (frame->frameFormat().position() == QTextFrameFormat::FloatLeft) { | - | ||||||||||||||||||
1884 | fd->position.x = left; | - | ||||||||||||||||||
1885 | fd->position.y = y; | - | ||||||||||||||||||
1886 | } else { | - | ||||||||||||||||||
1887 | fd->position.x = right - fd->size.width; | - | ||||||||||||||||||
1888 | fd->position.y = y; | - | ||||||||||||||||||
1889 | } | - | ||||||||||||||||||
1890 | - | |||||||||||||||||||
1891 | layoutStruct->minimumWidth = qMax(layoutStruct->minimumWidth, fd->minimumWidth); | - | ||||||||||||||||||
1892 | layoutStruct->maximumWidth = qMin(layoutStruct->maximumWidth, fd->maximumWidth); | - | ||||||||||||||||||
1893 | - | |||||||||||||||||||
1894 | - | |||||||||||||||||||
1895 | fd->layoutDirty = false; | - | ||||||||||||||||||
1896 | - | |||||||||||||||||||
1897 | - | |||||||||||||||||||
1898 | - | |||||||||||||||||||
1899 | if (qobject_cast<QTextTable *>(frame) != 0) | - | ||||||||||||||||||
1900 | fd->sizeDirty = frameSpansIntoNextPage; | - | ||||||||||||||||||
1901 | } | - | ||||||||||||||||||
1902 | - | |||||||||||||||||||
1903 | QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed parentY) | - | ||||||||||||||||||
1904 | { | - | ||||||||||||||||||
1905 | if(0) QMessageLogger(__FILE__, 20672073, __PRETTY_FUNCTION__).debug() << "layoutFrame (pre)"; dead code: QMessageLogger(__FILE__, 2073, __PRETTY_FUNCTION__).debug() << "layoutFrame (pre)"; | - | ||||||||||||||||||
1906 | ((!(data(f)->sizeDirty)) ? qt_assert("data(f)->sizeDirty",__FILE__,20682074) : qt_noop()); | - | ||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | QTextFrameFormat fformat = f->frameFormat(); | - | ||||||||||||||||||
1910 | - | |||||||||||||||||||
1911 | QTextFrame *parent = f->parentFrame(); | - | ||||||||||||||||||
1912 | const QTextFrameData *pd = parent ? data(parent) : 0; | - | ||||||||||||||||||
1913 | - | |||||||||||||||||||
1914 | const qreal maximumWidth = qMax(qreal(0), pd ? pd->contentsWidth.toReal() : document->pageSize().width()); | - | ||||||||||||||||||
1915 | QFixed width = QFixed::fromReal(fformat.width().value(maximumWidth)); | - | ||||||||||||||||||
1916 | if (fformat.width().type() == QTextLength::FixedLength) | - | ||||||||||||||||||
1917 | width = scaleToDevice(width); | - | ||||||||||||||||||
1918 | - | |||||||||||||||||||
1919 | const QFixed maximumHeight = pd ? pd->contentsHeight : -1; | - | ||||||||||||||||||
1920 | const QFixed height = (maximumHeight != -1 || fformat.height().type() != QTextLength::PercentageLength) | - | ||||||||||||||||||
1921 | ? QFixed::fromReal(fformat.height().value(maximumHeight.toReal())) | - | ||||||||||||||||||
1922 | : -1; | - | ||||||||||||||||||
1923 | - | |||||||||||||||||||
1924 | return layoutFrame(f, layoutFrom, layoutTo, width, height, parentY); | - | ||||||||||||||||||
1925 | } | - | ||||||||||||||||||
1926 | - | |||||||||||||||||||
1927 | QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed frameWidth, QFixed frameHeight, QFixed parentY) | - | ||||||||||||||||||
1928 | { | - | ||||||||||||||||||
1929 | if(0) QMessageLogger(__FILE__, 20912097, __PRETTY_FUNCTION__).debug() << "layoutFrame from=" << layoutFrom << "to=" << layoutTo; dead code: QMessageLogger(__FILE__, 2097, __PRETTY_FUNCTION__).debug() << "layoutFrame from=" << layoutFrom << "to=" << layoutTo; | - | ||||||||||||||||||
1930 | ((!(data(f)->sizeDirty)) ? qt_assert("data(f)->sizeDirty",__FILE__,20922098) : qt_noop()); | - | ||||||||||||||||||
1931 | - | |||||||||||||||||||
1932 | - | |||||||||||||||||||
1933 | QTextFrameData *fd = data(f); | - | ||||||||||||||||||
1934 | QFixed newContentsWidth; | - | ||||||||||||||||||
1935 | - | |||||||||||||||||||
1936 | bool fullLayout = false; | - | ||||||||||||||||||
1937 | { | - | ||||||||||||||||||
1938 | QTextFrameFormat fformat = f->frameFormat(); | - | ||||||||||||||||||
1939 | - | |||||||||||||||||||
1940 | QFixed tm = QFixed::fromReal(fformat.topMargin()); | - | ||||||||||||||||||
1941 | if (tm != fd->topMargin) { | - | ||||||||||||||||||
1942 | fd->topMargin = tm; | - | ||||||||||||||||||
1943 | fullLayout = true; | - | ||||||||||||||||||
1944 | } | - | ||||||||||||||||||
1945 | QFixed bm = QFixed::fromReal(fformat.bottomMargin()); | - | ||||||||||||||||||
1946 | if (bm != fd->bottomMargin) { | - | ||||||||||||||||||
1947 | fd->bottomMargin = bm; | - | ||||||||||||||||||
1948 | fullLayout = true; | - | ||||||||||||||||||
1949 | } | - | ||||||||||||||||||
1950 | fd->leftMargin = QFixed::fromReal(fformat.leftMargin()); | - | ||||||||||||||||||
1951 | fd->rightMargin = QFixed::fromReal(fformat.rightMargin()); | - | ||||||||||||||||||
1952 | QFixed b = QFixed::fromReal(fformat.border()); | - | ||||||||||||||||||
1953 | if (b != fd->border) { | - | ||||||||||||||||||
1954 | fd->border = b; | - | ||||||||||||||||||
1955 | fullLayout = true; | - | ||||||||||||||||||
1956 | } | - | ||||||||||||||||||
1957 | QFixed p = QFixed::fromReal(fformat.padding()); | - | ||||||||||||||||||
1958 | if (p != fd->padding) { | - | ||||||||||||||||||
1959 | fd->padding = p; | - | ||||||||||||||||||
1960 | fullLayout = true; | - | ||||||||||||||||||
1961 | } | - | ||||||||||||||||||
1962 | - | |||||||||||||||||||
1963 | QTextFrame *parent = f->parentFrame(); | - | ||||||||||||||||||
1964 | const QTextFrameData *pd = parent ? data(parent) : 0; | - | ||||||||||||||||||
1965 | - | |||||||||||||||||||
1966 | - | |||||||||||||||||||
1967 | if (parent) { | - | ||||||||||||||||||
1968 | fd->effectiveTopMargin = pd->effectiveTopMargin + fd->topMargin + fd->border + fd->padding; | - | ||||||||||||||||||
1969 | fd->effectiveBottomMargin = pd->effectiveBottomMargin + fd->topMargin + fd->border + fd->padding; | - | ||||||||||||||||||
1970 | - | |||||||||||||||||||
1971 | if (qobject_cast<QTextTable *>(parent)) { | - | ||||||||||||||||||
1972 | const QTextTableData *td = static_cast<const QTextTableData *>(pd); | - | ||||||||||||||||||
1973 | fd->effectiveTopMargin += td->cellSpacing + td->border + td->cellPadding; | - | ||||||||||||||||||
1974 | fd->effectiveBottomMargin += td->cellSpacing + td->border + td->cellPadding; | - | ||||||||||||||||||
1975 | } | - | ||||||||||||||||||
1976 | } else { | - | ||||||||||||||||||
1977 | fd->effectiveTopMargin = fd->topMargin + fd->border + fd->padding; | - | ||||||||||||||||||
1978 | fd->effectiveBottomMargin = fd->bottomMargin + fd->border + fd->padding; | - | ||||||||||||||||||
1979 | } | - | ||||||||||||||||||
1980 | - | |||||||||||||||||||
1981 | newContentsWidth = frameWidth - 2*(fd->border + fd->padding) | - | ||||||||||||||||||
1982 | - fd->leftMargin - fd->rightMargin; | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | if (frameHeight != -1) { | - | ||||||||||||||||||
1985 | fd->contentsHeight = frameHeight - 2*(fd->border + fd->padding) | - | ||||||||||||||||||
1986 | - fd->topMargin - fd->bottomMargin; | - | ||||||||||||||||||
1987 | } else { | - | ||||||||||||||||||
1988 | fd->contentsHeight = frameHeight; | - | ||||||||||||||||||
1989 | } | - | ||||||||||||||||||
1990 | } | - | ||||||||||||||||||
1991 | - | |||||||||||||||||||
1992 | if (isFrameFromInlineObject(f)) { | - | ||||||||||||||||||
1993 | - | |||||||||||||||||||
1994 | return QRectF(); | - | ||||||||||||||||||
1995 | } | - | ||||||||||||||||||
1996 | - | |||||||||||||||||||
1997 | if (QTextTable *table = qobject_cast<QTextTable *>(f)) { | - | ||||||||||||||||||
1998 | fd->contentsWidth = newContentsWidth; | - | ||||||||||||||||||
1999 | return layoutTable(table, layoutFrom, layoutTo, parentY); | - | ||||||||||||||||||
2000 | } | - | ||||||||||||||||||
2001 | - | |||||||||||||||||||
2002 | - | |||||||||||||||||||
2003 | - | |||||||||||||||||||
2004 | - | |||||||||||||||||||
2005 | fd->contentsWidth = newContentsWidth; | - | ||||||||||||||||||
2006 | - | |||||||||||||||||||
2007 | QTextLayoutStruct layoutStruct; | - | ||||||||||||||||||
2008 | layoutStruct.frame = f; | - | ||||||||||||||||||
2009 | layoutStruct.x_left = fd->leftMargin + fd->border + fd->padding; | - | ||||||||||||||||||
2010 | layoutStruct.x_right = layoutStruct.x_left + newContentsWidth; | - | ||||||||||||||||||
2011 | layoutStruct.y = fd->topMargin + fd->border + fd->padding; | - | ||||||||||||||||||
2012 | layoutStruct.frameY = parentY + fd->position.y; | - | ||||||||||||||||||
2013 | layoutStruct.contentsWidth = 0; | - | ||||||||||||||||||
2014 | layoutStruct.minimumWidth = 0; | - | ||||||||||||||||||
2015 | layoutStruct.maximumWidth = (2147483647/256); | - | ||||||||||||||||||
2016 | layoutStruct.fullLayout = fullLayout || (fd->oldContentsWidth != newContentsWidth); | - | ||||||||||||||||||
2017 | layoutStruct.updateRect = QRectF(QPointF(0, 0), QSizeF(qreal(2147483647), qreal(2147483647))); | - | ||||||||||||||||||
2018 | if(0) QMessageLogger(__FILE__, 21802186, __PRETTY_FUNCTION__).debug() << "layoutStruct: x_left" << layoutStruct.x_left << "x_right" << layoutStruct.x_right dead code: QMessageLogger(__FILE__, 2186, __PRETTY_FUNCTION__).debug() << "layoutStruct: x_left" << layoutStruct.x_left << "x_right" << layoutStruct.x_right << "fullLayout" << layoutStruct.fullLayout; | - | ||||||||||||||||||
2019 | << "fullLayout" << layoutStruct.fullLayout; dead code: QMessageLogger(__FILE__, 2186, __PRETTY_FUNCTION__).debug() << "layoutStruct: x_left" << layoutStruct.x_left << "x_right" << layoutStruct.x_right << "fullLayout" << layoutStruct.fullLayout; | - | ||||||||||||||||||
2020 | fd->oldContentsWidth = newContentsWidth; | - | ||||||||||||||||||
2021 | - | |||||||||||||||||||
2022 | layoutStruct.pageHeight = QFixed::fromReal(document->pageSize().height()); | - | ||||||||||||||||||
2023 | if (layoutStruct.pageHeight < 0) | - | ||||||||||||||||||
2024 | layoutStruct.pageHeight = (2147483647/256); | - | ||||||||||||||||||
2025 | - | |||||||||||||||||||
2026 | const int currentPage = layoutStruct.pageHeight == 0 ? 0 : (layoutStruct.frameY / layoutStruct.pageHeight).truncate(); | - | ||||||||||||||||||
2027 | layoutStruct.pageTopMargin = fd->effectiveTopMargin; | - | ||||||||||||||||||
2028 | layoutStruct.pageBottomMargin = fd->effectiveBottomMargin; | - | ||||||||||||||||||
2029 | layoutStruct.pageBottom = (currentPage + 1) * layoutStruct.pageHeight - layoutStruct.pageBottomMargin; | - | ||||||||||||||||||
2030 | - | |||||||||||||||||||
2031 | if (!f->parentFrame()) | - | ||||||||||||||||||
2032 | idealWidth = 0; | - | ||||||||||||||||||
2033 | - | |||||||||||||||||||
2034 | QTextFrame::Iterator it = f->begin(); | - | ||||||||||||||||||
2035 | layoutFlow(it, &layoutStruct, layoutFrom, layoutTo); | - | ||||||||||||||||||
2036 | - | |||||||||||||||||||
2037 | QFixed maxChildFrameWidth = 0; | - | ||||||||||||||||||
2038 | QList<QTextFrame *> children = f->childFrames(); | - | ||||||||||||||||||
2039 | for (int i = 0; i < children.size(); ++i) { | - | ||||||||||||||||||
2040 | QTextFrame *c = children.at(i); | - | ||||||||||||||||||
2041 | QTextFrameData *cd = data(c); | - | ||||||||||||||||||
2042 | maxChildFrameWidth = qMax(maxChildFrameWidth, cd->size.width); | - | ||||||||||||||||||
2043 | } | - | ||||||||||||||||||
2044 | - | |||||||||||||||||||
2045 | const QFixed marginWidth = 2*(fd->border + fd->padding) + fd->leftMargin + fd->rightMargin; | - | ||||||||||||||||||
2046 | if (!f->parentFrame()) { | - | ||||||||||||||||||
2047 | idealWidth = qMax(maxChildFrameWidth, layoutStruct.contentsWidth).toReal(); | - | ||||||||||||||||||
2048 | idealWidth += marginWidth.toReal(); | - | ||||||||||||||||||
2049 | } | - | ||||||||||||||||||
2050 | - | |||||||||||||||||||
2051 | QFixed actualWidth = qMax(newContentsWidth, qMax(maxChildFrameWidth, layoutStruct.contentsWidth)); | - | ||||||||||||||||||
2052 | fd->contentsWidth = actualWidth; | - | ||||||||||||||||||
2053 | if (newContentsWidth <= 0) { | - | ||||||||||||||||||
2054 | fd->contentsWidth = newContentsWidth; | - | ||||||||||||||||||
2055 | } | - | ||||||||||||||||||
2056 | - | |||||||||||||||||||
2057 | fd->minimumWidth = layoutStruct.minimumWidth; | - | ||||||||||||||||||
2058 | fd->maximumWidth = layoutStruct.maximumWidth; | - | ||||||||||||||||||
2059 | - | |||||||||||||||||||
2060 | fd->size.height = fd->contentsHeight == -1 | - | ||||||||||||||||||
2061 | ? layoutStruct.y + fd->border + fd->padding + fd->bottomMargin | - | ||||||||||||||||||
2062 | : fd->contentsHeight + 2*(fd->border + fd->padding) + fd->topMargin + fd->bottomMargin; | - | ||||||||||||||||||
2063 | fd->size.width = actualWidth + marginWidth; | - | ||||||||||||||||||
2064 | fd->sizeDirty = false; | - | ||||||||||||||||||
2065 | if (layoutStruct.updateRectForFloats.isValid()) | - | ||||||||||||||||||
2066 | layoutStruct.updateRect |= layoutStruct.updateRectForFloats; | - | ||||||||||||||||||
2067 | return layoutStruct.updateRect; | - | ||||||||||||||||||
2068 | } | - | ||||||||||||||||||
2069 | - | |||||||||||||||||||
2070 | void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, | - | ||||||||||||||||||
2071 | int layoutFrom, int layoutTo, QFixed width) | - | ||||||||||||||||||
2072 | { | - | ||||||||||||||||||
2073 | if(0) QMessageLogger(__FILE__, 22352241, __PRETTY_FUNCTION__).debug() << "layoutFlow from=" << layoutFrom << "to=" << layoutTo; dead code: QMessageLogger(__FILE__, 2241, __PRETTY_FUNCTION__).debug() << "layoutFlow from=" << layoutFrom << "to=" << layoutTo; | - | ||||||||||||||||||
2074 | QTextFrameData *fd = data(layoutStruct->frame); | - | ||||||||||||||||||
2075 | - | |||||||||||||||||||
2076 | fd->currentLayoutStruct = layoutStruct; | - | ||||||||||||||||||
2077 | - | |||||||||||||||||||
2078 | QTextFrame::Iterator previousIt; | - | ||||||||||||||||||
2079 | - | |||||||||||||||||||
2080 | const bool inRootFrame = (it.parentFrame() == document->rootFrame()); | - | ||||||||||||||||||
2081 | if (inRootFrame
| 0 | ||||||||||||||||||
2082 | bool redoCheckPoints = layoutStruct->fullLayout
| 0 | ||||||||||||||||||
2083 | - | |||||||||||||||||||
2084 | if (!redoCheckPoints
| 0 | ||||||||||||||||||
2085 | QVector<QCheckPoint>::Iterator checkPoint = std::lower_bound(checkPoints.begin(), checkPoints.end(), layoutFrom); | - | ||||||||||||||||||
2086 | if (checkPoint != checkPoints.end()
| 0 | ||||||||||||||||||
2087 | if (checkPoint != checkPoints.begin()
| 0 | ||||||||||||||||||
2088 | -- never executed: checkPoint;--checkPoint; never executed: --checkPoint; | 0 | ||||||||||||||||||
2089 | - | |||||||||||||||||||
2090 | layoutStruct->y = checkPoint->y; | - | ||||||||||||||||||
2091 | layoutStruct->frameY = checkPoint->frameY; | - | ||||||||||||||||||
2092 | layoutStruct->minimumWidth = checkPoint->minimumWidth; | - | ||||||||||||||||||
2093 | layoutStruct->maximumWidth = checkPoint->maximumWidth; | - | ||||||||||||||||||
2094 | layoutStruct->contentsWidth = checkPoint->contentsWidth; | - | ||||||||||||||||||
2095 | - | |||||||||||||||||||
2096 | if (layoutStruct->pageHeight > 0
| 0 | ||||||||||||||||||
2097 | int page = layoutStruct->currentPage(); | - | ||||||||||||||||||
2098 | layoutStruct->pageBottom = (page + 1) * layoutStruct->pageHeight - layoutStruct->pageBottomMargin; | - | ||||||||||||||||||
2099 | } never executed: end of block | 0 | ||||||||||||||||||
2100 | - | |||||||||||||||||||
2101 | it = frameIteratorForTextPosition(checkPoint->positionInFrame); | - | ||||||||||||||||||
2102 | checkPoints.resize(checkPoint - checkPoints.begin() + 1); | - | ||||||||||||||||||
2103 | - | |||||||||||||||||||
2104 | if (checkPoint != checkPoints.begin()
| 0 | ||||||||||||||||||
2105 | previousIt = it; | - | ||||||||||||||||||
2106 | --previousIt; | - | ||||||||||||||||||
2107 | } never executed: end of block | 0 | ||||||||||||||||||
2108 | } never executed: else {end of block | 0 | ||||||||||||||||||
2109 | redoCheckPoints = true; | - | ||||||||||||||||||
2110 | } never executed: end of block | 0 | ||||||||||||||||||
2111 | } | - | ||||||||||||||||||
2112 | - | |||||||||||||||||||
2113 | if (redoCheckPoints
| 0 | ||||||||||||||||||
2114 | checkPoints.clear(); | - | ||||||||||||||||||
2115 | QCheckPoint cp; | - | ||||||||||||||||||
2116 | cp.y = layoutStruct->y; | - | ||||||||||||||||||
2117 | cp.frameY = layoutStruct->frameY; | - | ||||||||||||||||||
2118 | cp.positionInFrame = 0; | - | ||||||||||||||||||
2119 | cp.minimumWidth = layoutStruct->minimumWidth; | - | ||||||||||||||||||
2120 | cp.maximumWidth = layoutStruct->maximumWidth; | - | ||||||||||||||||||
2121 | cp.contentsWidth = layoutStruct->contentsWidth; | - | ||||||||||||||||||
2122 | checkPoints.append(cp); | - | ||||||||||||||||||
2123 | } never executed: end of block | 0 | ||||||||||||||||||
2124 | } never executed: end of block | 0 | ||||||||||||||||||
2125 | - | |||||||||||||||||||
2126 | QTextBlockFormat previousBlockFormat = previousIt.currentBlock().blockFormat(); | - | ||||||||||||||||||
2127 | - | |||||||||||||||||||
2128 | QFixed maximumBlockWidth = 0; | - | ||||||||||||||||||
2129 | while (!it.atEnd()
| 0 | ||||||||||||||||||
2130 | QTextFrame *c = it.currentFrame(); | - | ||||||||||||||||||
2131 | - | |||||||||||||||||||
2132 | int docPos; | - | ||||||||||||||||||
2133 | if (it.currentFrame()
| 0 | ||||||||||||||||||
2134 | docPos = it.currentFrame()->firstPosition(); never executed: docPos = it.currentFrame()->firstPosition(); | 0 | ||||||||||||||||||
2135 | else | - | ||||||||||||||||||
2136 | docPos = it.currentBlock().position(); never executed: docPos = it.currentBlock().position(); | 0 | ||||||||||||||||||
2137 | - | |||||||||||||||||||
2138 | if (inRootFrame
| 0 | ||||||||||||||||||
2139 | if (qAbs(layoutStruct->y - checkPoints.lastconstLast().y) > 2000
| 0 | ||||||||||||||||||
2140 | QFixed left, right; | - | ||||||||||||||||||
2141 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2142 | if (left == layoutStruct->x_left
| 0 | ||||||||||||||||||
2143 | QCheckPoint p; | - | ||||||||||||||||||
2144 | p.y = layoutStruct->y; | - | ||||||||||||||||||
2145 | p.frameY = layoutStruct->frameY; | - | ||||||||||||||||||
2146 | p.positionInFrame = docPos; | - | ||||||||||||||||||
2147 | p.minimumWidth = layoutStruct->minimumWidth; | - | ||||||||||||||||||
2148 | p.maximumWidth = layoutStruct->maximumWidth; | - | ||||||||||||||||||
2149 | p.contentsWidth = layoutStruct->contentsWidth; | - | ||||||||||||||||||
2150 | checkPoints.append(p); | - | ||||||||||||||||||
2151 | - | |||||||||||||||||||
2152 | if (currentLazyLayoutPosition != -1
| 0 | ||||||||||||||||||
2153 | && docPos > currentLazyLayoutPosition + lazyLayoutStepSize
| 0 | ||||||||||||||||||
2154 | break; never executed: break; | 0 | ||||||||||||||||||
2155 | - | |||||||||||||||||||
2156 | } never executed: end of block | 0 | ||||||||||||||||||
2157 | } never executed: end of block | 0 | ||||||||||||||||||
2158 | } never executed: end of block | 0 | ||||||||||||||||||
2159 | - | |||||||||||||||||||
2160 | if (c
| 0 | ||||||||||||||||||
2161 | - | |||||||||||||||||||
2162 | QTextFrameData *cd = data(c); | - | ||||||||||||||||||
2163 | - | |||||||||||||||||||
2164 | QTextFrameFormat fformat = c->frameFormat(); | - | ||||||||||||||||||
2165 | - | |||||||||||||||||||
2166 | if (fformat.position() == QTextFrameFormat::InFlow
| 0 | ||||||||||||||||||
2167 | if (fformat.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysBefore
| 0 | ||||||||||||||||||
2168 | layoutStruct->newPage(); never executed: layoutStruct->newPage(); | 0 | ||||||||||||||||||
2169 | - | |||||||||||||||||||
2170 | QFixed left, right; | - | ||||||||||||||||||
2171 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2172 | left = qMax(left, layoutStruct->x_left); | - | ||||||||||||||||||
2173 | right = qMin(right, layoutStruct->x_right); | - | ||||||||||||||||||
2174 | - | |||||||||||||||||||
2175 | if (right - left < cd->size.width
| 0 | ||||||||||||||||||
2176 | layoutStruct->y = findY(layoutStruct->y, layoutStruct, cd->size.width); | - | ||||||||||||||||||
2177 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2178 | } never executed: end of block | 0 | ||||||||||||||||||
2179 | - | |||||||||||||||||||
2180 | QFixedPoint pos(left, layoutStruct->y); | - | ||||||||||||||||||
2181 | - | |||||||||||||||||||
2182 | Qt::Alignment align = Qt::AlignLeft; | - | ||||||||||||||||||
2183 | - | |||||||||||||||||||
2184 | QTextTable *table = qobject_cast<QTextTable *>(c); | - | ||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | if (table
| 0 | ||||||||||||||||||
2187 | align = table->format().alignment() & Qt::AlignHorizontal_Mask; never executed: align = table->format().alignment() & Qt::AlignHorizontal_Mask; | 0 | ||||||||||||||||||
2188 | - | |||||||||||||||||||
2189 | - | |||||||||||||||||||
2190 | - | |||||||||||||||||||
2191 | if (inRootFrame
| 0 | ||||||||||||||||||
2192 | contentHasAlignment = true; never executed: contentHasAlignment = true; | 0 | ||||||||||||||||||
2193 | - | |||||||||||||||||||
2194 | cd->position = pos; | - | ||||||||||||||||||
2195 | - | |||||||||||||||||||
2196 | if (document->pageSize().height() > 0.0f
| 0 | ||||||||||||||||||
2197 | cd->sizeDirty = true; never executed: cd->sizeDirty = true; | 0 | ||||||||||||||||||
2198 | - | |||||||||||||||||||
2199 | if (cd->sizeDirty
| 0 | ||||||||||||||||||
2200 | if (width != 0
| 0 | ||||||||||||||||||
2201 | layoutFrame(c, layoutFrom, layoutTo, width, -1, layoutStruct->frameY); never executed: layoutFrame(c, layoutFrom, layoutTo, width, -1, layoutStruct->frameY); | 0 | ||||||||||||||||||
2202 | else | - | ||||||||||||||||||
2203 | layoutFrame(c, layoutFrom, layoutTo, layoutStruct->frameY); never executed: layoutFrame(c, layoutFrom, layoutTo, layoutStruct->frameY); | 0 | ||||||||||||||||||
2204 | - | |||||||||||||||||||
2205 | QFixed absoluteChildPos = table
| 0 | ||||||||||||||||||
2206 | absoluteChildPos += layoutStruct->frameY; | - | ||||||||||||||||||
2207 | - | |||||||||||||||||||
2208 | - | |||||||||||||||||||
2209 | if (absoluteChildPos > layoutStruct->pageBottom
| 0 | ||||||||||||||||||
2210 | layoutStruct->newPage(); | - | ||||||||||||||||||
2211 | pos.y = layoutStruct->y; | - | ||||||||||||||||||
2212 | - | |||||||||||||||||||
2213 | cd->position = pos; | - | ||||||||||||||||||
2214 | cd->sizeDirty = true; | - | ||||||||||||||||||
2215 | - | |||||||||||||||||||
2216 | if (width != 0
| 0 | ||||||||||||||||||
2217 | layoutFrame(c, layoutFrom, layoutTo, width, -1, layoutStruct->frameY); never executed: layoutFrame(c, layoutFrom, layoutTo, width, -1, layoutStruct->frameY); | 0 | ||||||||||||||||||
2218 | else | - | ||||||||||||||||||
2219 | layoutFrame(c, layoutFrom, layoutTo, layoutStruct->frameY); never executed: layoutFrame(c, layoutFrom, layoutTo, layoutStruct->frameY); | 0 | ||||||||||||||||||
2220 | } | - | ||||||||||||||||||
2221 | } never executed: end of block | 0 | ||||||||||||||||||
2222 | - | |||||||||||||||||||
2223 | - | |||||||||||||||||||
2224 | if (right - left > cd->size.width
| 0 | ||||||||||||||||||
2225 | if (align & Qt::AlignRight
| 0 | ||||||||||||||||||
2226 | pos.x += layoutStruct->x_right - cd->size.width; never executed: pos.x += layoutStruct->x_right - cd->size.width; | 0 | ||||||||||||||||||
2227 | else if (align & Qt::AlignHCenter
| 0 | ||||||||||||||||||
2228 | pos.x += (layoutStruct->x_right - cd->size.width) / 2; never executed: pos.x += (layoutStruct->x_right - cd->size.width) / 2; | 0 | ||||||||||||||||||
2229 | } never executed: end of block | 0 | ||||||||||||||||||
2230 | - | |||||||||||||||||||
2231 | cd->position = pos; | - | ||||||||||||||||||
2232 | - | |||||||||||||||||||
2233 | layoutStruct->y += cd->size.height; | - | ||||||||||||||||||
2234 | const int page = layoutStruct->currentPage(); | - | ||||||||||||||||||
2235 | layoutStruct->pageBottom = (page + 1) * layoutStruct->pageHeight - layoutStruct->pageBottomMargin; | - | ||||||||||||||||||
2236 | - | |||||||||||||||||||
2237 | cd->layoutDirty = false; | - | ||||||||||||||||||
2238 | - | |||||||||||||||||||
2239 | if (c->frameFormat().pageBreakPolicy() & QTextFormat::PageBreak_AlwaysAfter
| 0 | ||||||||||||||||||
2240 | layoutStruct->newPage(); never executed: layoutStruct->newPage(); | 0 | ||||||||||||||||||
2241 | } never executed: else {end of block | 0 | ||||||||||||||||||
2242 | QRectF oldFrameRect(cd->position.toPointF(), cd->size.toSizeF()); | - | ||||||||||||||||||
2243 | QRectF updateRect; | - | ||||||||||||||||||
2244 | - | |||||||||||||||||||
2245 | if (cd->sizeDirty
| 0 | ||||||||||||||||||
2246 | updateRect = layoutFrame(c, layoutFrom, layoutTo); never executed: updateRect = layoutFrame(c, layoutFrom, layoutTo); | 0 | ||||||||||||||||||
2247 | - | |||||||||||||||||||
2248 | positionFloat(c); | - | ||||||||||||||||||
2249 | - | |||||||||||||||||||
2250 | - | |||||||||||||||||||
2251 | if (cd->sizeDirty
| 0 | ||||||||||||||||||
2252 | updateRect = layoutFrame(c, layoutFrom, layoutTo); never executed: updateRect = layoutFrame(c, layoutFrom, layoutTo); | 0 | ||||||||||||||||||
2253 | - | |||||||||||||||||||
2254 | QRectF frameRect(cd->position.toPointF(), cd->size.toSizeF()); | - | ||||||||||||||||||
2255 | - | |||||||||||||||||||
2256 | if (frameRect == oldFrameRect
| 0 | ||||||||||||||||||
2257 | updateRect.translate(cd->position.toPointF()); never executed: updateRect.translate(cd->position.toPointF()); | 0 | ||||||||||||||||||
2258 | else | - | ||||||||||||||||||
2259 | updateRect = frameRect; never executed: updateRect = frameRect; | 0 | ||||||||||||||||||
2260 | - | |||||||||||||||||||
2261 | layoutStruct->addUpdateRectForFloat(updateRect); | - | ||||||||||||||||||
2262 | if (oldFrameRect.isValid()
| 0 | ||||||||||||||||||
2263 | layoutStruct->addUpdateRectForFloat(oldFrameRect); never executed: layoutStruct->addUpdateRectForFloat(oldFrameRect); | 0 | ||||||||||||||||||
2264 | } never executed: end of block | 0 | ||||||||||||||||||
2265 | - | |||||||||||||||||||
2266 | layoutStruct->minimumWidth = qMax(layoutStruct->minimumWidth, cd->minimumWidth); | - | ||||||||||||||||||
2267 | layoutStruct->maximumWidth = qMin(layoutStruct->maximumWidth, cd->maximumWidth); | - | ||||||||||||||||||
2268 | - | |||||||||||||||||||
2269 | previousIt = it; | - | ||||||||||||||||||
2270 | ++it; | - | ||||||||||||||||||
2271 | } never executed: else {end of block | 0 | ||||||||||||||||||
2272 | QTextFrame::Iterator lastIt; | - | ||||||||||||||||||
2273 | if (!previousIt.atEnd()
| 0 | ||||||||||||||||||
2274 | lastIt = previousIt; never executed: lastIt = previousIt; | 0 | ||||||||||||||||||
2275 | previousIt = it; | - | ||||||||||||||||||
2276 | QTextBlock block = it.currentBlock(); | - | ||||||||||||||||||
2277 | ++it; | - | ||||||||||||||||||
2278 | - | |||||||||||||||||||
2279 | const QTextBlockFormat blockFormat = block.blockFormat(); | - | ||||||||||||||||||
2280 | - | |||||||||||||||||||
2281 | if (blockFormat.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysBefore
| 0 | ||||||||||||||||||
2282 | layoutStruct->newPage(); never executed: layoutStruct->newPage(); | 0 | ||||||||||||||||||
2283 | - | |||||||||||||||||||
2284 | const QFixed origY = layoutStruct->y; | - | ||||||||||||||||||
2285 | const QFixed origPageBottom = layoutStruct->pageBottom; | - | ||||||||||||||||||
2286 | const QFixed origMaximumWidth = layoutStruct->maximumWidth; | - | ||||||||||||||||||
2287 | layoutStruct->maximumWidth = 0; | - | ||||||||||||||||||
2288 | - | |||||||||||||||||||
2289 | const QTextBlockFormat *previousBlockFormatPtr = 0; | - | ||||||||||||||||||
2290 | if (lastIt.currentBlock().isValid()
| 0 | ||||||||||||||||||
2291 | previousBlockFormatPtr = &previousBlockFormat; never executed: previousBlockFormatPtr = &previousBlockFormat; | 0 | ||||||||||||||||||
2292 | - | |||||||||||||||||||
2293 | - | |||||||||||||||||||
2294 | layoutBlock(block, docPos, blockFormat, layoutStruct, layoutFrom, layoutTo, previousBlockFormatPtr); | - | ||||||||||||||||||
2295 | - | |||||||||||||||||||
2296 | - | |||||||||||||||||||
2297 | - | |||||||||||||||||||
2298 | if (inRootFrame
| 0 | ||||||||||||||||||
2299 | contentHasAlignment = true; never executed: contentHasAlignment = true; | 0 | ||||||||||||||||||
2300 | - | |||||||||||||||||||
2301 | - | |||||||||||||||||||
2302 | - | |||||||||||||||||||
2303 | if (isEmptyBlockBeforeTable(block, blockFormat, it)
| 0 | ||||||||||||||||||
2304 | const QTextBlock lastBlock = lastIt.currentBlock(); | - | ||||||||||||||||||
2305 | const qreal lastBlockBottomMargin = lastBlock.isValid()
| 0 | ||||||||||||||||||
2306 | layoutStruct->y = origY + QFixed::fromReal(qMax(lastBlockBottomMargin, block.blockFormat().topMargin())); | - | ||||||||||||||||||
2307 | layoutStruct->pageBottom = origPageBottom; | - | ||||||||||||||||||
2308 | } never executed: else {end of block | 0 | ||||||||||||||||||
2309 | - | |||||||||||||||||||
2310 | if (isEmptyBlockAfterTable(block, lastIt.currentFrame())
| 0 | ||||||||||||||||||
2311 | QTextTableData *td = static_cast<QTextTableData *>(data(lastIt.currentFrame())); | - | ||||||||||||||||||
2312 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||
2313 | - | |||||||||||||||||||
2314 | QPointF pos((td->position.x + td->size.width).toReal(), | - | ||||||||||||||||||
2315 | (td->position.y + td->size.height).toReal() - layout->boundingRect().height()); | - | ||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | layout->setPosition(pos); | - | ||||||||||||||||||
2318 | layoutStruct->y = origY; | - | ||||||||||||||||||
2319 | layoutStruct->pageBottom = origPageBottom; | - | ||||||||||||||||||
2320 | } never executed: end of block | 0 | ||||||||||||||||||
2321 | - | |||||||||||||||||||
2322 | - | |||||||||||||||||||
2323 | if (isLineSeparatorBlockAfterTable(block, lastIt.currentFrame())
| 0 | ||||||||||||||||||
2324 | QTextTableData *td = static_cast<QTextTableData *>(data(lastIt.currentFrame())); | - | ||||||||||||||||||
2325 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||
2326 | - | |||||||||||||||||||
2327 | QFixed height = QFixed::fromReal(layout->lineAt(0).height()); | - | ||||||||||||||||||
2328 | - | |||||||||||||||||||
2329 | if (layoutStruct->pageBottom == origPageBottom
| 0 | ||||||||||||||||||
2330 | layoutStruct->y -= height; | - | ||||||||||||||||||
2331 | layout->setPosition(layout->position() - QPointF(0, height.toReal())); | - | ||||||||||||||||||
2332 | } never executed: else {end of block | 0 | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | layoutStruct->y = origY - height; | - | ||||||||||||||||||
2335 | layoutStruct->pageBottom = origPageBottom; | - | ||||||||||||||||||
2336 | layoutBlock(block, docPos, blockFormat, layoutStruct, layoutFrom, layoutTo, previousBlockFormatPtr); | - | ||||||||||||||||||
2337 | } never executed: end of block | 0 | ||||||||||||||||||
2338 | - | |||||||||||||||||||
2339 | QPointF linePos((td->position.x + td->size.width).toReal(), | - | ||||||||||||||||||
2340 | (td->position.y + td->size.height - height).toReal()); | - | ||||||||||||||||||
2341 | - | |||||||||||||||||||
2342 | layout->lineAt(0).setPosition(linePos - layout->position()); | - | ||||||||||||||||||
2343 | } never executed: end of block | 0 | ||||||||||||||||||
2344 | - | |||||||||||||||||||
2345 | if (blockFormat.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysAfter
| 0 | ||||||||||||||||||
2346 | layoutStruct->newPage(); never executed: layoutStruct->newPage(); | 0 | ||||||||||||||||||
2347 | } never executed: end of block | 0 | ||||||||||||||||||
2348 | - | |||||||||||||||||||
2349 | maximumBlockWidth = qMax(maximumBlockWidth, layoutStruct->maximumWidth); | - | ||||||||||||||||||
2350 | layoutStruct->maximumWidth = origMaximumWidth; | - | ||||||||||||||||||
2351 | previousBlockFormat = blockFormat; | - | ||||||||||||||||||
2352 | } never executed: end of block | 0 | ||||||||||||||||||
2353 | } | - | ||||||||||||||||||
2354 | if (layoutStruct->maximumWidth == (2147483647/256)
| 0 | ||||||||||||||||||
2355 | layoutStruct->maximumWidth = maximumBlockWidth; never executed: layoutStruct->maximumWidth = maximumBlockWidth; | 0 | ||||||||||||||||||
2356 | else | - | ||||||||||||||||||
2357 | layoutStruct->maximumWidth = qMax(layoutStruct->maximumWidth, maximumBlockWidth); never executed: layoutStruct->maximumWidth = qMax(layoutStruct->maximumWidth, maximumBlockWidth); | 0 | ||||||||||||||||||
2358 | - | |||||||||||||||||||
2359 | - | |||||||||||||||||||
2360 | - | |||||||||||||||||||
2361 | - | |||||||||||||||||||
2362 | if (!qobject_cast<QTextTable *>(layoutStruct->frame)
| 0 | ||||||||||||||||||
2363 | QList<QTextFrame *> children = layoutStruct->frame->childFrames(); | - | ||||||||||||||||||
2364 | for (int i = 0; i < children.count()
| 0 | ||||||||||||||||||
2365 | QTextFrameData *fd = data(children.at(i)); | - | ||||||||||||||||||
2366 | if (!fd->layoutDirty
| 0 | ||||||||||||||||||
2367 | layoutStruct->y = qMax(layoutStruct->y, fd->position.y + fd->size.height); never executed: layoutStruct->y = qMax(layoutStruct->y, fd->position.y + fd->size.height); | 0 | ||||||||||||||||||
2368 | } never executed: end of block | 0 | ||||||||||||||||||
2369 | } never executed: end of block | 0 | ||||||||||||||||||
2370 | - | |||||||||||||||||||
2371 | if (inRootFrame
| 0 | ||||||||||||||||||
2372 | - | |||||||||||||||||||
2373 | - | |||||||||||||||||||
2374 | if (!fd->floats.isEmpty()
| 0 | ||||||||||||||||||
2375 | contentHasAlignment = true; never executed: contentHasAlignment = true; | 0 | ||||||||||||||||||
2376 | - | |||||||||||||||||||
2377 | if (it.atEnd()
| 0 | ||||||||||||||||||
2378 | - | |||||||||||||||||||
2379 | currentLazyLayoutPosition = -1; | - | ||||||||||||||||||
2380 | QCheckPoint cp; | - | ||||||||||||||||||
2381 | cp.y = layoutStruct->y; | - | ||||||||||||||||||
2382 | cp.positionInFrame = docPrivate->length(); | - | ||||||||||||||||||
2383 | cp.minimumWidth = layoutStruct->minimumWidth; | - | ||||||||||||||||||
2384 | cp.maximumWidth = layoutStruct->maximumWidth; | - | ||||||||||||||||||
2385 | cp.contentsWidth = layoutStruct->contentsWidth; | - | ||||||||||||||||||
2386 | checkPoints.append(cp); | - | ||||||||||||||||||
2387 | checkPoints.reserve(checkPoints.size()); | - | ||||||||||||||||||
2388 | } never executed: else {end of block | 0 | ||||||||||||||||||
2389 | currentLazyLayoutPosition = checkPoints.lastconstLast().positionInFrame; | - | ||||||||||||||||||
2390 | - | |||||||||||||||||||
2391 | - | |||||||||||||||||||
2392 | } never executed: end of block | 0 | ||||||||||||||||||
2393 | } | - | ||||||||||||||||||
2394 | - | |||||||||||||||||||
2395 | - | |||||||||||||||||||
2396 | fd->currentLayoutStruct = 0; | - | ||||||||||||||||||
2397 | } never executed: end of block | 0 | ||||||||||||||||||
2398 | - | |||||||||||||||||||
2399 | static inline void getLineHeightParams(const QTextBlockFormat &blockFormat, const QTextLine &line, qreal scaling, | - | ||||||||||||||||||
2400 | QFixed *lineAdjustment, QFixed *lineBreakHeight, QFixed *lineHeight) | - | ||||||||||||||||||
2401 | { | - | ||||||||||||||||||
2402 | *lineHeight = QFixed::fromReal(blockFormat.lineHeight(line.height(), scaling)); | - | ||||||||||||||||||
2403 | - | |||||||||||||||||||
2404 | if (blockFormat.lineHeightType() == QTextBlockFormat::FixedHeight || blockFormat.lineHeightType() == QTextBlockFormat::MinimumHeight) { | - | ||||||||||||||||||
2405 | *lineBreakHeight = *lineHeight; | - | ||||||||||||||||||
2406 | if (blockFormat.lineHeightType() == QTextBlockFormat::FixedHeight) | - | ||||||||||||||||||
2407 | *lineAdjustment = QFixed::fromReal(line.ascent() + qMax(line.leading(), qreal(0.0))) - ((*lineHeight * 4) / 5); | - | ||||||||||||||||||
2408 | else | - | ||||||||||||||||||
2409 | *lineAdjustment = QFixed::fromReal(line.height()) - *lineHeight; | - | ||||||||||||||||||
2410 | } | - | ||||||||||||||||||
2411 | else { | - | ||||||||||||||||||
2412 | *lineBreakHeight = QFixed::fromReal(line.height()); | - | ||||||||||||||||||
2413 | *lineAdjustment = 0; | - | ||||||||||||||||||
2414 | } | - | ||||||||||||||||||
2415 | } | - | ||||||||||||||||||
2416 | - | |||||||||||||||||||
2417 | void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, | - | ||||||||||||||||||
2418 | QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat) | - | ||||||||||||||||||
2419 | { | - | ||||||||||||||||||
2420 | QTextDocumentLayout * const q = q_func(); | - | ||||||||||||||||||
2421 | if (!bl.isVisible()) | - | ||||||||||||||||||
2422 | return; | - | ||||||||||||||||||
2423 | - | |||||||||||||||||||
2424 | QTextLayout *tl = bl.layout(); | - | ||||||||||||||||||
2425 | const int blockLength = bl.length(); | - | ||||||||||||||||||
2426 | - | |||||||||||||||||||
2427 | if(0) QMessageLogger(__FILE__, 25892595, __PRETTY_FUNCTION__).debug() << "layoutBlock from=" << layoutFrom << "to=" << layoutTo; dead code: QMessageLogger(__FILE__, 2595, __PRETTY_FUNCTION__).debug() << "layoutBlock from=" << layoutFrom << "to=" << layoutTo; | - | ||||||||||||||||||
2428 | - | |||||||||||||||||||
2429 | - | |||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | if (previousBlockFormat) { | - | ||||||||||||||||||
2432 | qreal margin = qMax(blockFormat.topMargin(), previousBlockFormat->bottomMargin()); | - | ||||||||||||||||||
2433 | if (margin > 0 && q->paintDevice()) { | - | ||||||||||||||||||
2434 | margin *= qreal(q->paintDevice()->logicalDpiY()) / qreal(qt_defaultDpi()); | - | ||||||||||||||||||
2435 | } | - | ||||||||||||||||||
2436 | layoutStruct->y += QFixed::fromReal(margin); | - | ||||||||||||||||||
2437 | } | - | ||||||||||||||||||
2438 | - | |||||||||||||||||||
2439 | - | |||||||||||||||||||
2440 | - | |||||||||||||||||||
2441 | Qt::LayoutDirection dir = bl.textDirection(); | - | ||||||||||||||||||
2442 | - | |||||||||||||||||||
2443 | QFixed extraMargin; | - | ||||||||||||||||||
2444 | if (docPrivate->defaultTextOption.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) { | - | ||||||||||||||||||
2445 | QFontMetricsF fm(bl.charFormat().font()); | - | ||||||||||||||||||
2446 | extraMargin = QFixed::fromReal(fm.width(QChar(QChar(0x21B5)))); | - | ||||||||||||||||||
2447 | } | - | ||||||||||||||||||
2448 | - | |||||||||||||||||||
2449 | const QFixed indent = this->blockIndent(blockFormat); | - | ||||||||||||||||||
2450 | const QFixed totalLeftMargin = QFixed::fromReal(blockFormat.leftMargin()) + (dir == Qt::RightToLeft ? extraMargin : indent); | - | ||||||||||||||||||
2451 | const QFixed totalRightMargin = QFixed::fromReal(blockFormat.rightMargin()) + (dir == Qt::RightToLeft ? indent : extraMargin); | - | ||||||||||||||||||
2452 | - | |||||||||||||||||||
2453 | const QPointF oldPosition = tl->position(); | - | ||||||||||||||||||
2454 | tl->setPosition(QPointF(layoutStruct->x_left.toReal(), layoutStruct->y.toReal())); | - | ||||||||||||||||||
2455 | - | |||||||||||||||||||
2456 | if (layoutStruct->fullLayout | - | ||||||||||||||||||
2457 | || (blockPosition + blockLength > layoutFrom && blockPosition <= layoutTo) | - | ||||||||||||||||||
2458 | - | |||||||||||||||||||
2459 | || (layoutStruct->pageHeight != (2147483647/256) && layoutStruct->absoluteY() + QFixed::fromReal(tl->boundingRect().height()) > layoutStruct->pageBottom)) { | - | ||||||||||||||||||
2460 | - | |||||||||||||||||||
2461 | if(0) QMessageLogger(__FILE__, 26232629, __PRETTY_FUNCTION__).debug() << " do layout"; dead code: QMessageLogger(__FILE__, 2629, __PRETTY_FUNCTION__).debug() << " do layout"; | - | ||||||||||||||||||
2462 | QTextOption option = docPrivate->defaultTextOption; | - | ||||||||||||||||||
2463 | option.setTextDirection(dir); | - | ||||||||||||||||||
2464 | option.setTabs( blockFormat.tabPositions() ); | - | ||||||||||||||||||
2465 | - | |||||||||||||||||||
2466 | Qt::Alignment align = docPrivate->defaultTextOption.alignment(); | - | ||||||||||||||||||
2467 | if (blockFormat.hasProperty(QTextFormat::BlockAlignment)) | - | ||||||||||||||||||
2468 | align = blockFormat.alignment(); | - | ||||||||||||||||||
2469 | option.setAlignment(QGuiApplicationPrivate::visualAlignment(dir, align)); | - | ||||||||||||||||||
2470 | - | |||||||||||||||||||
2471 | if (blockFormat.nonBreakableLines() || document->pageSize().width() < 0) { | - | ||||||||||||||||||
2472 | option.setWrapMode(QTextOption::ManualWrap); | - | ||||||||||||||||||
2473 | } | - | ||||||||||||||||||
2474 | - | |||||||||||||||||||
2475 | tl->setTextOption(option); | - | ||||||||||||||||||
2476 | - | |||||||||||||||||||
2477 | const bool haveWordOrAnyWrapMode = (option.wrapMode() == QTextOption::WrapAtWordBoundaryOrAnywhere); | - | ||||||||||||||||||
2478 | - | |||||||||||||||||||
2479 | - | |||||||||||||||||||
2480 | const QFixed cy = layoutStruct->y; | - | ||||||||||||||||||
2481 | const QFixed l = layoutStruct->x_left + totalLeftMargin; | - | ||||||||||||||||||
2482 | const QFixed r = layoutStruct->x_right - totalRightMargin; | - | ||||||||||||||||||
2483 | - | |||||||||||||||||||
2484 | tl->beginLayout(); | - | ||||||||||||||||||
2485 | bool firstLine = true; | - | ||||||||||||||||||
2486 | while (1) { | - | ||||||||||||||||||
2487 | QTextLine line = tl->createLine(); | - | ||||||||||||||||||
2488 | if (!line.isValid()) | - | ||||||||||||||||||
2489 | break; | - | ||||||||||||||||||
2490 | line.setLeadingIncluded(true); | - | ||||||||||||||||||
2491 | - | |||||||||||||||||||
2492 | QFixed left, right; | - | ||||||||||||||||||
2493 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2494 | left = qMax(left, l); | - | ||||||||||||||||||
2495 | right = qMin(right, r); | - | ||||||||||||||||||
2496 | QFixed text_indent; | - | ||||||||||||||||||
2497 | if (firstLine) { | - | ||||||||||||||||||
2498 | text_indent = QFixed::fromReal(blockFormat.textIndent()); | - | ||||||||||||||||||
2499 | if (dir == Qt::LeftToRight) | - | ||||||||||||||||||
2500 | left += text_indent; | - | ||||||||||||||||||
2501 | else | - | ||||||||||||||||||
2502 | right -= text_indent; | - | ||||||||||||||||||
2503 | firstLine = false; | - | ||||||||||||||||||
2504 | } | - | ||||||||||||||||||
2505 | - | |||||||||||||||||||
2506 | - | |||||||||||||||||||
2507 | if (fixedColumnWidth != -1) | - | ||||||||||||||||||
2508 | line.setNumColumns(fixedColumnWidth, (right - left).toReal()); | - | ||||||||||||||||||
2509 | else | - | ||||||||||||||||||
2510 | line.setLineWidth((right - left).toReal()); | - | ||||||||||||||||||
2511 | - | |||||||||||||||||||
2512 | - | |||||||||||||||||||
2513 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2514 | left = qMax(left, l); | - | ||||||||||||||||||
2515 | right = qMin(right, r); | - | ||||||||||||||||||
2516 | if (dir == Qt::LeftToRight) | - | ||||||||||||||||||
2517 | left += text_indent; | - | ||||||||||||||||||
2518 | else | - | ||||||||||||||||||
2519 | right -= text_indent; | - | ||||||||||||||||||
2520 | - | |||||||||||||||||||
2521 | if (fixedColumnWidth == -1 && QFixed::fromReal(line.naturalTextWidth()) > right-left) { | - | ||||||||||||||||||
2522 | - | |||||||||||||||||||
2523 | layoutStruct->pendingFloats.clear(); | - | ||||||||||||||||||
2524 | - | |||||||||||||||||||
2525 | line.setLineWidth((right-left).toReal()); | - | ||||||||||||||||||
2526 | if (QFixed::fromReal(line.naturalTextWidth()) > right-left) { | - | ||||||||||||||||||
2527 | if (haveWordOrAnyWrapMode) { | - | ||||||||||||||||||
2528 | option.setWrapMode(QTextOption::WrapAnywhere); | - | ||||||||||||||||||
2529 | tl->setTextOption(option); | - | ||||||||||||||||||
2530 | } | - | ||||||||||||||||||
2531 | - | |||||||||||||||||||
2532 | layoutStruct->pendingFloats.clear(); | - | ||||||||||||||||||
2533 | - | |||||||||||||||||||
2534 | layoutStruct->y = findY(layoutStruct->y, layoutStruct, QFixed::fromReal(line.naturalTextWidth())); | - | ||||||||||||||||||
2535 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2536 | left = qMax(left, l); | - | ||||||||||||||||||
2537 | right = qMin(right, r); | - | ||||||||||||||||||
2538 | if (dir == Qt::LeftToRight) | - | ||||||||||||||||||
2539 | left += text_indent; | - | ||||||||||||||||||
2540 | else | - | ||||||||||||||||||
2541 | right -= text_indent; | - | ||||||||||||||||||
2542 | line.setLineWidth(qMax<qreal>(line.naturalTextWidth(), (right-left).toReal())); | - | ||||||||||||||||||
2543 | - | |||||||||||||||||||
2544 | if (haveWordOrAnyWrapMode) { | - | ||||||||||||||||||
2545 | option.setWrapMode(QTextOption::WordWrap); | - | ||||||||||||||||||
2546 | tl->setTextOption(option); | - | ||||||||||||||||||
2547 | } | - | ||||||||||||||||||
2548 | } | - | ||||||||||||||||||
2549 | - | |||||||||||||||||||
2550 | } | - | ||||||||||||||||||
2551 | - | |||||||||||||||||||
2552 | QFixed lineBreakHeight, lineHeight, lineAdjustment; | - | ||||||||||||||||||
2553 | qreal scaling = (q->paintDevice() && q->paintDevice()->logicalDpiY() != qt_defaultDpi()) ? | - | ||||||||||||||||||
2554 | qreal(q->paintDevice()->logicalDpiY()) / qreal(qt_defaultDpi()) : 1; | - | ||||||||||||||||||
2555 | getLineHeightParams(blockFormat, line, scaling, &lineAdjustment, &lineBreakHeight, &lineHeight); | - | ||||||||||||||||||
2556 | - | |||||||||||||||||||
2557 | if (layoutStruct->pageHeight > 0 && layoutStruct->absoluteY() + lineBreakHeight > layoutStruct->pageBottom) { | - | ||||||||||||||||||
2558 | layoutStruct->newPage(); | - | ||||||||||||||||||
2559 | - | |||||||||||||||||||
2560 | floatMargins(layoutStruct->y, layoutStruct, &left, &right); | - | ||||||||||||||||||
2561 | left = qMax(left, l); | - | ||||||||||||||||||
2562 | right = qMin(right, r); | - | ||||||||||||||||||
2563 | if (dir == Qt::LeftToRight) | - | ||||||||||||||||||
2564 | left += text_indent; | - | ||||||||||||||||||
2565 | else | - | ||||||||||||||||||
2566 | right -= text_indent; | - | ||||||||||||||||||
2567 | } | - | ||||||||||||||||||
2568 | - | |||||||||||||||||||
2569 | line.setPosition(QPointF((left - layoutStruct->x_left).toReal(), (layoutStruct->y - cy - lineAdjustment).toReal())); | - | ||||||||||||||||||
2570 | layoutStruct->y += lineHeight; | - | ||||||||||||||||||
2571 | layoutStruct->contentsWidth | - | ||||||||||||||||||
2572 | = qMax<QFixed>(layoutStruct->contentsWidth, QFixed::fromReal(line.x() + line.naturalTextWidth()) + totalRightMargin); | - | ||||||||||||||||||
2573 | - | |||||||||||||||||||
2574 | - | |||||||||||||||||||
2575 | for (int i = 0; i < layoutStruct->pendingFloats.size(); ++i) { | - | ||||||||||||||||||
2576 | QTextFrame *f = layoutStruct->pendingFloats.at(i); | - | ||||||||||||||||||
2577 | positionFloat(f); | - | ||||||||||||||||||
2578 | } | - | ||||||||||||||||||
2579 | layoutStruct->pendingFloats.clear(); | - | ||||||||||||||||||
2580 | } | - | ||||||||||||||||||
2581 | tl->endLayout(); | - | ||||||||||||||||||
2582 | } else { | - | ||||||||||||||||||
2583 | const int cnt = tl->lineCount(); | - | ||||||||||||||||||
2584 | for (int i = 0; i < cnt; ++i) { | - | ||||||||||||||||||
2585 | if(0) QMessageLogger(__FILE__, 27472753, __PRETTY_FUNCTION__).debug() << "going to move text line" << i; dead code: QMessageLogger(__FILE__, 2753, __PRETTY_FUNCTION__).debug() << "going to move text line" << i; | - | ||||||||||||||||||
2586 | QTextLine line = tl->lineAt(i); | - | ||||||||||||||||||
2587 | layoutStruct->contentsWidth | - | ||||||||||||||||||
2588 | = qMax(layoutStruct->contentsWidth, QFixed::fromReal(line.x() + tl->lineAt(i).naturalTextWidth()) + totalRightMargin); | - | ||||||||||||||||||
2589 | - | |||||||||||||||||||
2590 | QFixed lineBreakHeight, lineHeight, lineAdjustment; | - | ||||||||||||||||||
2591 | qreal scaling = (q->paintDevice() && q->paintDevice()->logicalDpiY() != qt_defaultDpi()) ? | - | ||||||||||||||||||
2592 | qreal(q->paintDevice()->logicalDpiY()) / qreal(qt_defaultDpi()) : 1; | - | ||||||||||||||||||
2593 | getLineHeightParams(blockFormat, line, scaling, &lineAdjustment, &lineBreakHeight, &lineHeight); | - | ||||||||||||||||||
2594 | - | |||||||||||||||||||
2595 | if (layoutStruct->pageHeight != (2147483647/256)) { | - | ||||||||||||||||||
2596 | if (layoutStruct->absoluteY() + lineBreakHeight > layoutStruct->pageBottom) | - | ||||||||||||||||||
2597 | layoutStruct->newPage(); | - | ||||||||||||||||||
2598 | line.setPosition(QPointF(line.position().x(), (layoutStruct->y - lineAdjustment).toReal() - tl->position().y())); | - | ||||||||||||||||||
2599 | } | - | ||||||||||||||||||
2600 | layoutStruct->y += lineHeight; | - | ||||||||||||||||||
2601 | } | - | ||||||||||||||||||
2602 | if (layoutStruct->updateRect.isValid() | - | ||||||||||||||||||
2603 | && blockLength > 1) { | - | ||||||||||||||||||
2604 | if (layoutFrom >= blockPosition + blockLength) { | - | ||||||||||||||||||
2605 | - | |||||||||||||||||||
2606 | - | |||||||||||||||||||
2607 | - | |||||||||||||||||||
2608 | layoutStruct->updateRect.setTop(qMax(layoutStruct->updateRect.top(), layoutStruct->y.toReal())); | - | ||||||||||||||||||
2609 | } else if (layoutTo < blockPosition) { | - | ||||||||||||||||||
2610 | if (oldPosition == tl->position()) | - | ||||||||||||||||||
2611 | - | |||||||||||||||||||
2612 | - | |||||||||||||||||||
2613 | - | |||||||||||||||||||
2614 | - | |||||||||||||||||||
2615 | layoutStruct->updateRect.setBottom(qMin(layoutStruct->updateRect.bottom(), tl->position().y())); | - | ||||||||||||||||||
2616 | else | - | ||||||||||||||||||
2617 | layoutStruct->updateRect.setBottom(qreal(2147483647)); | - | ||||||||||||||||||
2618 | } | - | ||||||||||||||||||
2619 | } | - | ||||||||||||||||||
2620 | } | - | ||||||||||||||||||
2621 | - | |||||||||||||||||||
2622 | - | |||||||||||||||||||
2623 | const QFixed margins = totalLeftMargin + totalRightMargin; | - | ||||||||||||||||||
2624 | layoutStruct->minimumWidth = qMax(layoutStruct->minimumWidth, QFixed::fromReal(tl->minimumWidth()) + margins); | - | ||||||||||||||||||
2625 | - | |||||||||||||||||||
2626 | const QFixed maxW = QFixed::fromReal(tl->maximumWidth()) + margins; | - | ||||||||||||||||||
2627 | - | |||||||||||||||||||
2628 | if (maxW > 0) { | - | ||||||||||||||||||
2629 | if (layoutStruct->maximumWidth == (2147483647/256)) | - | ||||||||||||||||||
2630 | layoutStruct->maximumWidth = maxW; | - | ||||||||||||||||||
2631 | else | - | ||||||||||||||||||
2632 | layoutStruct->maximumWidth = qMax(layoutStruct->maximumWidth, maxW); | - | ||||||||||||||||||
2633 | } | - | ||||||||||||||||||
2634 | } | - | ||||||||||||||||||
2635 | - | |||||||||||||||||||
2636 | void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, | - | ||||||||||||||||||
2637 | QFixed *left, QFixed *right) const | - | ||||||||||||||||||
2638 | { | - | ||||||||||||||||||
2639 | - | |||||||||||||||||||
2640 | *left = layoutStruct->x_left; | - | ||||||||||||||||||
2641 | *right = layoutStruct->x_right; | - | ||||||||||||||||||
2642 | QTextFrameData *lfd = data(layoutStruct->frame); | - | ||||||||||||||||||
2643 | for (int i = 0; i < lfd->floats.size(); ++i) { | - | ||||||||||||||||||
2644 | QTextFrameData *fd = data(lfd->floats.at(i)); | - | ||||||||||||||||||
2645 | if (!fd->layoutDirty) { | - | ||||||||||||||||||
2646 | if (fd->position.y <= y && fd->position.y + fd->size.height > y) { | - | ||||||||||||||||||
2647 | - | |||||||||||||||||||
2648 | if (lfd->floats.at(i)->frameFormat().position() == QTextFrameFormat::FloatLeft) | - | ||||||||||||||||||
2649 | *left = qMax(*left, fd->position.x + fd->size.width); | - | ||||||||||||||||||
2650 | else | - | ||||||||||||||||||
2651 | *right = qMin(*right, fd->position.x); | - | ||||||||||||||||||
2652 | } | - | ||||||||||||||||||
2653 | } | - | ||||||||||||||||||
2654 | } | - | ||||||||||||||||||
2655 | - | |||||||||||||||||||
2656 | } | - | ||||||||||||||||||
2657 | - | |||||||||||||||||||
2658 | QFixed QTextDocumentLayoutPrivate::findY(QFixed yFrom, const QTextLayoutStruct *layoutStruct, QFixed requiredWidth) const | - | ||||||||||||||||||
2659 | { | - | ||||||||||||||||||
2660 | QFixed right, left; | - | ||||||||||||||||||
2661 | requiredWidth = qMin(requiredWidth, layoutStruct->x_right - layoutStruct->x_left); | - | ||||||||||||||||||
2662 | - | |||||||||||||||||||
2663 | - | |||||||||||||||||||
2664 | while (1) { | - | ||||||||||||||||||
2665 | floatMargins(yFrom, layoutStruct, &left, &right); | - | ||||||||||||||||||
2666 | - | |||||||||||||||||||
2667 | if (right-left >= requiredWidth) | - | ||||||||||||||||||
2668 | break; | - | ||||||||||||||||||
2669 | - | |||||||||||||||||||
2670 | - | |||||||||||||||||||
2671 | QFixed newY = (2147483647/256); | - | ||||||||||||||||||
2672 | QTextFrameData *lfd = data(layoutStruct->frame); | - | ||||||||||||||||||
2673 | for (int i = 0; i < lfd->floats.size(); ++i) { | - | ||||||||||||||||||
2674 | QTextFrameData *fd = data(lfd->floats.at(i)); | - | ||||||||||||||||||
2675 | if (!fd->layoutDirty) { | - | ||||||||||||||||||
2676 | if (fd->position.y <= yFrom && fd->position.y + fd->size.height > yFrom) | - | ||||||||||||||||||
2677 | newY = qMin(newY, fd->position.y + fd->size.height); | - | ||||||||||||||||||
2678 | } | - | ||||||||||||||||||
2679 | } | - | ||||||||||||||||||
2680 | if (newY == (2147483647/256)) | - | ||||||||||||||||||
2681 | break; | - | ||||||||||||||||||
2682 | yFrom = newY; | - | ||||||||||||||||||
2683 | } | - | ||||||||||||||||||
2684 | return yFrom; | - | ||||||||||||||||||
2685 | } | - | ||||||||||||||||||
2686 | - | |||||||||||||||||||
2687 | QTextDocumentLayout::QTextDocumentLayout(QTextDocument *doc) | - | ||||||||||||||||||
2688 | : QAbstractTextDocumentLayout(*new QTextDocumentLayoutPrivate, doc) | - | ||||||||||||||||||
2689 | { | - | ||||||||||||||||||
2690 | registerHandler(QTextFormat::ImageObject, new QTextImageHandler(this)); | - | ||||||||||||||||||
2691 | } | - | ||||||||||||||||||
2692 | - | |||||||||||||||||||
2693 | - | |||||||||||||||||||
2694 | void QTextDocumentLayout::draw(QPainter *painter, const PaintContext &context) | - | ||||||||||||||||||
2695 | { | - | ||||||||||||||||||
2696 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2697 | QTextFrame *frame = d->document->rootFrame(); | - | ||||||||||||||||||
2698 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
2699 | - | |||||||||||||||||||
2700 | if(fd->sizeDirty) | - | ||||||||||||||||||
2701 | return; | - | ||||||||||||||||||
2702 | - | |||||||||||||||||||
2703 | if (context.clip.isValid()) { | - | ||||||||||||||||||
2704 | d->ensureLayouted(QFixed::fromReal(context.clip.bottom())); | - | ||||||||||||||||||
2705 | } else { | - | ||||||||||||||||||
2706 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
2707 | } | - | ||||||||||||||||||
2708 | - | |||||||||||||||||||
2709 | QFixed width = fd->size.width; | - | ||||||||||||||||||
2710 | if (d->document->pageSize().width() == 0 && d->viewportRect.isValid()) { | - | ||||||||||||||||||
2711 | - | |||||||||||||||||||
2712 | - | |||||||||||||||||||
2713 | fd->size.width = qMax(width, QFixed::fromReal(d->viewportRect.right())); | - | ||||||||||||||||||
2714 | } | - | ||||||||||||||||||
2715 | - | |||||||||||||||||||
2716 | - | |||||||||||||||||||
2717 | d->clipRect = QRectF(fd->position.toPointF(), fd->size.toSizeF()).adjusted(fd->leftMargin.toReal(), 0, -fd->rightMargin.toReal(), 0); | - | ||||||||||||||||||
2718 | d->drawFrame(QPointF(), painter, context, frame); | - | ||||||||||||||||||
2719 | fd->size.width = width; | - | ||||||||||||||||||
2720 | } | - | ||||||||||||||||||
2721 | - | |||||||||||||||||||
2722 | void QTextDocumentLayout::setViewport(const QRectF &viewport) | - | ||||||||||||||||||
2723 | { | - | ||||||||||||||||||
2724 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2725 | d->viewportRect = viewport; | - | ||||||||||||||||||
2726 | } | - | ||||||||||||||||||
2727 | - | |||||||||||||||||||
2728 | static void markFrames(QTextFrame *current, int from, int oldLength, int length) | - | ||||||||||||||||||
2729 | { | - | ||||||||||||||||||
2730 | int end = qMax(oldLength, length) + from; | - | ||||||||||||||||||
2731 | - | |||||||||||||||||||
2732 | if (current->firstPosition() >= end
| 0 | ||||||||||||||||||
2733 | return; never executed: return; | 0 | ||||||||||||||||||
2734 | - | |||||||||||||||||||
2735 | QTextFrameData *fd = data(current); | - | ||||||||||||||||||
2736 | - | |||||||||||||||||||
2737 | for (int iQTextFrame *null = 0nullptr; | - | ||||||||||||||||||
2738 | - | |||||||||||||||||||
2739 | - | |||||||||||||||||||
2740 | i <fd->floats.size(); ++i) { | - | ||||||||||||||||||
QTextFrame *f =erase(std::remove(fd->floats[i]; | ||||||||||||||||||||
if (!f) {.begin(), fd->floats.removeAt(i); | ||||||||||||||||||||
--i; | ||||||||||||||||||||
} | ||||||||||||||||||||
}end(), null), | ||||||||||||||||||||
2741 | fd->floats.end()); | - | ||||||||||||||||||
2742 | - | |||||||||||||||||||
2743 | fd->layoutDirty = true; | - | ||||||||||||||||||
2744 | fd->sizeDirty = true; | - | ||||||||||||||||||
2745 | - | |||||||||||||||||||
2746 | - | |||||||||||||||||||
2747 | QList<QTextFrame *> children = current->childFrames(); | - | ||||||||||||||||||
2748 | for (int i = 0; i < children.size()
| 0 | ||||||||||||||||||
2749 | markFrames(children.at(i), from, oldLength, length); never executed: markFrames(children.at(i), from, oldLength, length); | 0 | ||||||||||||||||||
2750 | } never executed: end of block | 0 | ||||||||||||||||||
2751 | - | |||||||||||||||||||
2752 | void QTextDocumentLayout::documentChanged(int from, int oldLength, int length) | - | ||||||||||||||||||
2753 | { | - | ||||||||||||||||||
2754 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2755 | - | |||||||||||||||||||
2756 | QTextBlock startIt = document()->findBlock(from); | - | ||||||||||||||||||
2757 | QTextBlock endIt = document()->findBlock(qMax(0, from + length - 1)); | - | ||||||||||||||||||
2758 | if (endIt.isValid()) | - | ||||||||||||||||||
2759 | endIt = endIt.next(); | - | ||||||||||||||||||
2760 | for (QTextBlock blockIt = startIt; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next()) | - | ||||||||||||||||||
2761 | blockIt.clearLayout(); | - | ||||||||||||||||||
2762 | - | |||||||||||||||||||
2763 | if (d->docPrivate->pageSize.isNull()) | - | ||||||||||||||||||
2764 | return; | - | ||||||||||||||||||
2765 | - | |||||||||||||||||||
2766 | QRectF updateRect; | - | ||||||||||||||||||
2767 | - | |||||||||||||||||||
2768 | d->lazyLayoutStepSize = 1000; | - | ||||||||||||||||||
2769 | d->sizeChangedTimer.stop(); | - | ||||||||||||||||||
2770 | d->insideDocumentChange = true; | - | ||||||||||||||||||
2771 | - | |||||||||||||||||||
2772 | const int documentLength = d->docPrivate->length(); | - | ||||||||||||||||||
2773 | const bool fullLayout = (oldLength == 0 && length == documentLength); | - | ||||||||||||||||||
2774 | const bool smallChange = documentLength > 0 | - | ||||||||||||||||||
2775 | && (qMax(length, oldLength) * 100 / documentLength) < 5; | - | ||||||||||||||||||
2776 | - | |||||||||||||||||||
2777 | - | |||||||||||||||||||
2778 | - | |||||||||||||||||||
2779 | - | |||||||||||||||||||
2780 | - | |||||||||||||||||||
2781 | if (smallChange | - | ||||||||||||||||||
2782 | && (d->currentLazyLayoutPosition == -1 || d->showLayoutProgress == false)) | - | ||||||||||||||||||
2783 | d->showLayoutProgress = false; | - | ||||||||||||||||||
2784 | else | - | ||||||||||||||||||
2785 | d->showLayoutProgress = true; | - | ||||||||||||||||||
2786 | - | |||||||||||||||||||
2787 | if (fullLayout) { | - | ||||||||||||||||||
2788 | d->contentHasAlignment = false; | - | ||||||||||||||||||
2789 | d->currentLazyLayoutPosition = 0; | - | ||||||||||||||||||
2790 | d->checkPoints.clear(); | - | ||||||||||||||||||
2791 | d->layoutStep(); | - | ||||||||||||||||||
2792 | } else { | - | ||||||||||||||||||
2793 | d->ensureLayoutedByPosition(from); | - | ||||||||||||||||||
2794 | updateRect = doLayout(from, oldLength, length); | - | ||||||||||||||||||
2795 | } | - | ||||||||||||||||||
2796 | - | |||||||||||||||||||
2797 | if (!d->layoutTimer.isActive() && d->currentLazyLayoutPosition != -1) | - | ||||||||||||||||||
2798 | d->layoutTimer.start(10, this); | - | ||||||||||||||||||
2799 | - | |||||||||||||||||||
2800 | d->insideDocumentChange = false; | - | ||||||||||||||||||
2801 | - | |||||||||||||||||||
2802 | for (QTextBlock blockIt = startIt; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next()) | - | ||||||||||||||||||
2803 | updateBlock(blockIt); | - | ||||||||||||||||||
2804 | - | |||||||||||||||||||
2805 | if (d->showLayoutProgress) { | - | ||||||||||||||||||
2806 | const QSizeF newSize = dynamicDocumentSize(); | - | ||||||||||||||||||
2807 | if (newSize != d->lastReportedSize) { | - | ||||||||||||||||||
2808 | d->lastReportedSize = newSize; | - | ||||||||||||||||||
2809 | documentSizeChanged(newSize); | - | ||||||||||||||||||
2810 | } | - | ||||||||||||||||||
2811 | } | - | ||||||||||||||||||
2812 | - | |||||||||||||||||||
2813 | if (!updateRect.isValid()) { | - | ||||||||||||||||||
2814 | - | |||||||||||||||||||
2815 | updateRect = QRectF(QPointF(0, 0), QSizeF(qreal(2147483647), qreal(2147483647))); | - | ||||||||||||||||||
2816 | } | - | ||||||||||||||||||
2817 | - | |||||||||||||||||||
2818 | update(updateRect); | - | ||||||||||||||||||
2819 | } | - | ||||||||||||||||||
2820 | - | |||||||||||||||||||
2821 | QRectF QTextDocumentLayout::doLayout(int from, int oldLength, int length) | - | ||||||||||||||||||
2822 | { | - | ||||||||||||||||||
2823 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2824 | - | |||||||||||||||||||
2825 | - | |||||||||||||||||||
2826 | - | |||||||||||||||||||
2827 | - | |||||||||||||||||||
2828 | markFrames(d->docPrivate->rootFrame(), from, oldLength, length); | - | ||||||||||||||||||
2829 | - | |||||||||||||||||||
2830 | QRectF updateRect; | - | ||||||||||||||||||
2831 | - | |||||||||||||||||||
2832 | QTextFrame *root = d->docPrivate->rootFrame(); | - | ||||||||||||||||||
2833 | if(data(root)->sizeDirty) | - | ||||||||||||||||||
2834 | updateRect = d->layoutFrame(root, from, from + length); | - | ||||||||||||||||||
2835 | data(root)->layoutDirty = false; | - | ||||||||||||||||||
2836 | - | |||||||||||||||||||
2837 | if (d->currentLazyLayoutPosition == -1) | - | ||||||||||||||||||
2838 | layoutFinished(); | - | ||||||||||||||||||
2839 | else if (d->showLayoutProgress) | - | ||||||||||||||||||
2840 | d->sizeChangedTimer.start(0, this); | - | ||||||||||||||||||
2841 | - | |||||||||||||||||||
2842 | return updateRect; | - | ||||||||||||||||||
2843 | } | - | ||||||||||||||||||
2844 | - | |||||||||||||||||||
2845 | int QTextDocumentLayout::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||
2846 | { | - | ||||||||||||||||||
2847 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2848 | d->ensureLayouted(QFixed::fromReal(point.y())); | - | ||||||||||||||||||
2849 | QTextFrame *f = d->docPrivate->rootFrame(); | - | ||||||||||||||||||
2850 | int position = 0; | - | ||||||||||||||||||
2851 | QTextLayout *l = 0; | - | ||||||||||||||||||
2852 | QFixedPoint pointf; | - | ||||||||||||||||||
2853 | pointf.x = QFixed::fromReal(point.x()); | - | ||||||||||||||||||
2854 | pointf.y = QFixed::fromReal(point.y()); | - | ||||||||||||||||||
2855 | QTextDocumentLayoutPrivate::HitPoint p = d->hitTest(f, pointf, &position, &l, accuracy); | - | ||||||||||||||||||
2856 | if (accuracy == Qt::ExactHit && p < QTextDocumentLayoutPrivate::PointExact) | - | ||||||||||||||||||
2857 | return -1; | - | ||||||||||||||||||
2858 | - | |||||||||||||||||||
2859 | - | |||||||||||||||||||
2860 | int lastPos = f->lastPosition(); | - | ||||||||||||||||||
2861 | if (l && !l->preeditAreaText().isEmpty()) | - | ||||||||||||||||||
2862 | lastPos += l->preeditAreaText().length(); | - | ||||||||||||||||||
2863 | if (position > lastPos) | - | ||||||||||||||||||
2864 | position = lastPos; | - | ||||||||||||||||||
2865 | else if (position < 0) | - | ||||||||||||||||||
2866 | position = 0; | - | ||||||||||||||||||
2867 | - | |||||||||||||||||||
2868 | return position; | - | ||||||||||||||||||
2869 | } | - | ||||||||||||||||||
2870 | - | |||||||||||||||||||
2871 | void QTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) | - | ||||||||||||||||||
2872 | { | - | ||||||||||||||||||
2873 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2874 | QTextCharFormat f = format.toCharFormat(); | - | ||||||||||||||||||
2875 | ((!(f.isValid())) ? qt_assert("f.isValid()",__FILE__,30393043) : qt_noop()); | - | ||||||||||||||||||
2876 | QTextObjectHandler handler = d->handlers.value(f.objectType()); | - | ||||||||||||||||||
2877 | if (!handler.component) | - | ||||||||||||||||||
2878 | return; | - | ||||||||||||||||||
2879 | - | |||||||||||||||||||
2880 | QSizeF intrinsic = handler.iface->intrinsicSize(d->document, posInDocument, format); | - | ||||||||||||||||||
2881 | - | |||||||||||||||||||
2882 | QTextFrameFormat::Position pos = QTextFrameFormat::InFlow; | - | ||||||||||||||||||
2883 | QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f)); | - | ||||||||||||||||||
2884 | if (frame) { | - | ||||||||||||||||||
2885 | pos = frame->frameFormat().position(); | - | ||||||||||||||||||
2886 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
2887 | fd->sizeDirty = false; | - | ||||||||||||||||||
2888 | fd->size = QFixedSize::fromSizeF(intrinsic); | - | ||||||||||||||||||
2889 | fd->minimumWidth = fd->maximumWidth = fd->size.width; | - | ||||||||||||||||||
2890 | } | - | ||||||||||||||||||
2891 | - | |||||||||||||||||||
2892 | QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0)); | - | ||||||||||||||||||
2893 | item.setWidth(inlineSize.width()); | - | ||||||||||||||||||
2894 | - | |||||||||||||||||||
2895 | QFontMetrics m(f.font()); | - | ||||||||||||||||||
2896 | switch (f.verticalAlignment()) | - | ||||||||||||||||||
2897 | { | - | ||||||||||||||||||
2898 | case QTextCharFormat::AlignMiddle: | - | ||||||||||||||||||
2899 | item.setDescent(inlineSize.height() / 2); | - | ||||||||||||||||||
2900 | item.setAscent(inlineSize.height() / 2); | - | ||||||||||||||||||
2901 | break; | - | ||||||||||||||||||
2902 | case QTextCharFormat::AlignBaseline: | - | ||||||||||||||||||
2903 | item.setDescent(m.descent()); | - | ||||||||||||||||||
2904 | item.setAscent(inlineSize.height() - m.descent()); | - | ||||||||||||||||||
2905 | break; | - | ||||||||||||||||||
2906 | default: | - | ||||||||||||||||||
2907 | item.setDescent(0); | - | ||||||||||||||||||
2908 | item.setAscent(inlineSize.height()); | - | ||||||||||||||||||
2909 | } | - | ||||||||||||||||||
2910 | } | - | ||||||||||||||||||
2911 | - | |||||||||||||||||||
2912 | void QTextDocumentLayout::positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) | - | ||||||||||||||||||
2913 | { | - | ||||||||||||||||||
2914 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2915 | (void)posInDocument;; | - | ||||||||||||||||||
2916 | if (item.width() != 0) | - | ||||||||||||||||||
2917 | - | |||||||||||||||||||
2918 | return; | - | ||||||||||||||||||
2919 | - | |||||||||||||||||||
2920 | QTextCharFormat f = format.toCharFormat(); | - | ||||||||||||||||||
2921 | ((!(f.isValid())) ? qt_assert("f.isValid()",__FILE__,30853089) : qt_noop()); | - | ||||||||||||||||||
2922 | QTextObjectHandler handler = d->handlers.value(f.objectType()); | - | ||||||||||||||||||
2923 | if (!handler.component) | - | ||||||||||||||||||
2924 | return; | - | ||||||||||||||||||
2925 | - | |||||||||||||||||||
2926 | QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f)); | - | ||||||||||||||||||
2927 | if (!frame) | - | ||||||||||||||||||
2928 | return; | - | ||||||||||||||||||
2929 | - | |||||||||||||||||||
2930 | QTextBlock b = d->document->findBlock(frame->firstPosition()); | - | ||||||||||||||||||
2931 | QTextLine line; | - | ||||||||||||||||||
2932 | if (b.position() <= frame->firstPosition() && b.position() + b.length() > frame->lastPosition()) | - | ||||||||||||||||||
2933 | line = b.layout()->lineAt(b.layout()->lineCount()-1); | - | ||||||||||||||||||
2934 | - | |||||||||||||||||||
2935 | - | |||||||||||||||||||
2936 | d->positionFloat(frame, line.isValid() ? &line : 0); | - | ||||||||||||||||||
2937 | } | - | ||||||||||||||||||
2938 | - | |||||||||||||||||||
2939 | void QTextDocumentLayout::drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item, | - | ||||||||||||||||||
2940 | int posInDocument, const QTextFormat &format) | - | ||||||||||||||||||
2941 | { | - | ||||||||||||||||||
2942 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2943 | QTextCharFormat f = format.toCharFormat(); | - | ||||||||||||||||||
2944 | ((!(f.isValid())) ? qt_assert("f.isValid()",__FILE__,31083112) : qt_noop()); | - | ||||||||||||||||||
2945 | QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f)); | - | ||||||||||||||||||
2946 | if (frame && frame->frameFormat().position() != QTextFrameFormat::InFlow) | - | ||||||||||||||||||
2947 | return; | - | ||||||||||||||||||
2948 | - | |||||||||||||||||||
2949 | - | |||||||||||||||||||
2950 | QAbstractTextDocumentLayout::drawInlineObject(p, rect, item, posInDocument, format); | - | ||||||||||||||||||
2951 | } | - | ||||||||||||||||||
2952 | - | |||||||||||||||||||
2953 | int QTextDocumentLayout::dynamicPageCount() const | - | ||||||||||||||||||
2954 | { | - | ||||||||||||||||||
2955 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2956 | const QSizeF pgSize = d->document->pageSize(); | - | ||||||||||||||||||
2957 | if (pgSize.height() < 0) | - | ||||||||||||||||||
2958 | return 1; | - | ||||||||||||||||||
2959 | return qCeil(dynamicDocumentSize().height() / pgSize.height()); | - | ||||||||||||||||||
2960 | } | - | ||||||||||||||||||
2961 | - | |||||||||||||||||||
2962 | QSizeF QTextDocumentLayout::dynamicDocumentSize() const | - | ||||||||||||||||||
2963 | { | - | ||||||||||||||||||
2964 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2965 | return data(d->docPrivate->rootFrame())->size.toSizeF(); | - | ||||||||||||||||||
2966 | } | - | ||||||||||||||||||
2967 | - | |||||||||||||||||||
2968 | int QTextDocumentLayout::pageCount() const | - | ||||||||||||||||||
2969 | { | - | ||||||||||||||||||
2970 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2971 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
2972 | return dynamicPageCount(); | - | ||||||||||||||||||
2973 | } | - | ||||||||||||||||||
2974 | - | |||||||||||||||||||
2975 | QSizeF QTextDocumentLayout::documentSize() const | - | ||||||||||||||||||
2976 | { | - | ||||||||||||||||||
2977 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
2978 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
2979 | return dynamicDocumentSize(); | - | ||||||||||||||||||
2980 | } | - | ||||||||||||||||||
2981 | - | |||||||||||||||||||
2982 | void QTextDocumentLayoutPrivate::ensureLayouted(QFixed y) const | - | ||||||||||||||||||
2983 | { | - | ||||||||||||||||||
2984 | const QTextDocumentLayout * const q = q_func(); | - | ||||||||||||||||||
2985 | if (currentLazyLayoutPosition == -1) | - | ||||||||||||||||||
2986 | return; | - | ||||||||||||||||||
2987 | const QSizeF oldSize = q->dynamicDocumentSize(); | - | ||||||||||||||||||
2988 | (void)oldSize;; | - | ||||||||||||||||||
2989 | - | |||||||||||||||||||
2990 | if (checkPoints.isEmpty()) | - | ||||||||||||||||||
2991 | layoutStep(); | - | ||||||||||||||||||
2992 | - | |||||||||||||||||||
2993 | while (currentLazyLayoutPosition != -1 | - | ||||||||||||||||||
2994 | && checkPoints.last().y < y) | - | ||||||||||||||||||
2995 | layoutStep(); | - | ||||||||||||||||||
2996 | } | - | ||||||||||||||||||
2997 | - | |||||||||||||||||||
2998 | void QTextDocumentLayoutPrivate::ensureLayoutedByPosition(int position) const | - | ||||||||||||||||||
2999 | { | - | ||||||||||||||||||
3000 | if (currentLazyLayoutPosition == -1) | - | ||||||||||||||||||
3001 | return; | - | ||||||||||||||||||
3002 | if (position < currentLazyLayoutPosition) | - | ||||||||||||||||||
3003 | return; | - | ||||||||||||||||||
3004 | while (currentLazyLayoutPosition != -1 | - | ||||||||||||||||||
3005 | && currentLazyLayoutPosition < position) { | - | ||||||||||||||||||
3006 | const_cast<QTextDocumentLayout *>(q_func())->doLayout(currentLazyLayoutPosition, 0, 2147483647 - currentLazyLayoutPosition); | - | ||||||||||||||||||
3007 | } | - | ||||||||||||||||||
3008 | } | - | ||||||||||||||||||
3009 | - | |||||||||||||||||||
3010 | void QTextDocumentLayoutPrivate::layoutStep() const | - | ||||||||||||||||||
3011 | { | - | ||||||||||||||||||
3012 | ensureLayoutedByPosition(currentLazyLayoutPosition + lazyLayoutStepSize); | - | ||||||||||||||||||
3013 | lazyLayoutStepSize = qMin(200000, lazyLayoutStepSize * 2); | - | ||||||||||||||||||
3014 | } | - | ||||||||||||||||||
3015 | - | |||||||||||||||||||
3016 | void QTextDocumentLayout::setCursorWidth(int width) | - | ||||||||||||||||||
3017 | { | - | ||||||||||||||||||
3018 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3019 | d->cursorWidth = width; | - | ||||||||||||||||||
3020 | } | - | ||||||||||||||||||
3021 | - | |||||||||||||||||||
3022 | int QTextDocumentLayout::cursorWidth() const | - | ||||||||||||||||||
3023 | { | - | ||||||||||||||||||
3024 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3025 | return d->cursorWidth; | - | ||||||||||||||||||
3026 | } | - | ||||||||||||||||||
3027 | - | |||||||||||||||||||
3028 | void QTextDocumentLayout::setFixedColumnWidth(int width) | - | ||||||||||||||||||
3029 | { | - | ||||||||||||||||||
3030 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3031 | d->fixedColumnWidth = width; | - | ||||||||||||||||||
3032 | } | - | ||||||||||||||||||
3033 | - | |||||||||||||||||||
3034 | QRectF QTextDocumentLayout::tableCellBoundingRect(QTextTable *table, const QTextTableCell &cell) const | - | ||||||||||||||||||
3035 | { | - | ||||||||||||||||||
3036 | if (!cell.isValid()) | - | ||||||||||||||||||
3037 | return QRectF(); | - | ||||||||||||||||||
3038 | - | |||||||||||||||||||
3039 | QTextTableData *td = static_cast<QTextTableData *>(data(table)); | - | ||||||||||||||||||
3040 | - | |||||||||||||||||||
3041 | QRectF tableRect = tableBoundingRect(table); | - | ||||||||||||||||||
3042 | QRectF cellRect = td->cellRect(cell); | - | ||||||||||||||||||
3043 | - | |||||||||||||||||||
3044 | return cellRect.translated(tableRect.topLeft()); | - | ||||||||||||||||||
3045 | } | - | ||||||||||||||||||
3046 | - | |||||||||||||||||||
3047 | QRectF QTextDocumentLayout::tableBoundingRect(QTextTable *table) const | - | ||||||||||||||||||
3048 | { | - | ||||||||||||||||||
3049 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3050 | if (d->docPrivate->pageSize.isNull()) | - | ||||||||||||||||||
3051 | return QRectF(); | - | ||||||||||||||||||
3052 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
3053 | - | |||||||||||||||||||
3054 | QPointF pos; | - | ||||||||||||||||||
3055 | const int framePos = table->firstPosition(); | - | ||||||||||||||||||
3056 | QTextFrame *f = table; | - | ||||||||||||||||||
3057 | while (f) { | - | ||||||||||||||||||
3058 | QTextFrameData *fd = data(f); | - | ||||||||||||||||||
3059 | pos += fd->position.toPointF(); | - | ||||||||||||||||||
3060 | - | |||||||||||||||||||
3061 | if (f != table) { | - | ||||||||||||||||||
3062 | if (QTextTable *table = qobject_cast<QTextTable *>(f)) { | - | ||||||||||||||||||
3063 | QTextTableCell cell = table->cellAt(framePos); | - | ||||||||||||||||||
3064 | if (cell.isValid()) | - | ||||||||||||||||||
3065 | pos += static_cast<QTextTableData *>(fd)->cellPosition(cell).toPointF(); | - | ||||||||||||||||||
3066 | } | - | ||||||||||||||||||
3067 | } | - | ||||||||||||||||||
3068 | - | |||||||||||||||||||
3069 | f = f->parentFrame(); | - | ||||||||||||||||||
3070 | } | - | ||||||||||||||||||
3071 | return QRectF(pos, data(table)->size.toSizeF()); | - | ||||||||||||||||||
3072 | } | - | ||||||||||||||||||
3073 | - | |||||||||||||||||||
3074 | QRectF QTextDocumentLayout::frameBoundingRect(QTextFrame *frame) const | - | ||||||||||||||||||
3075 | { | - | ||||||||||||||||||
3076 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3077 | if (d->docPrivate->pageSize.isNull()) | - | ||||||||||||||||||
3078 | return QRectF(); | - | ||||||||||||||||||
3079 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
3080 | return d->frameBoundingRectInternal(frame); | - | ||||||||||||||||||
3081 | } | - | ||||||||||||||||||
3082 | - | |||||||||||||||||||
3083 | QRectF QTextDocumentLayoutPrivate::frameBoundingRectInternal(QTextFrame *frame) const | - | ||||||||||||||||||
3084 | { | - | ||||||||||||||||||
3085 | QPointF pos; | - | ||||||||||||||||||
3086 | const int framePos = frame->firstPosition(); | - | ||||||||||||||||||
3087 | QTextFrame *f = frame; | - | ||||||||||||||||||
3088 | while (f) { | - | ||||||||||||||||||
3089 | QTextFrameData *fd = data(f); | - | ||||||||||||||||||
3090 | pos += fd->position.toPointF(); | - | ||||||||||||||||||
3091 | - | |||||||||||||||||||
3092 | if (QTextTable *table = qobject_cast<QTextTable *>(f)) { | - | ||||||||||||||||||
3093 | QTextTableCell cell = table->cellAt(framePos); | - | ||||||||||||||||||
3094 | if (cell.isValid()) | - | ||||||||||||||||||
3095 | pos += static_cast<QTextTableData *>(fd)->cellPosition(cell).toPointF(); | - | ||||||||||||||||||
3096 | } | - | ||||||||||||||||||
3097 | - | |||||||||||||||||||
3098 | f = f->parentFrame(); | - | ||||||||||||||||||
3099 | } | - | ||||||||||||||||||
3100 | return QRectF(pos, data(frame)->size.toSizeF()); | - | ||||||||||||||||||
3101 | } | - | ||||||||||||||||||
3102 | - | |||||||||||||||||||
3103 | QRectF QTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const | - | ||||||||||||||||||
3104 | { | - | ||||||||||||||||||
3105 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3106 | if (d->docPrivate->pageSize.isNull() || !block.isValid() || !block.isVisible()) | - | ||||||||||||||||||
3107 | return QRectF(); | - | ||||||||||||||||||
3108 | d->ensureLayoutedByPosition(block.position() + block.length()); | - | ||||||||||||||||||
3109 | QTextFrame *frame = d->document->frameAt(block.position()); | - | ||||||||||||||||||
3110 | QPointF offset; | - | ||||||||||||||||||
3111 | const int blockPos = block.position(); | - | ||||||||||||||||||
3112 | - | |||||||||||||||||||
3113 | while (frame) { | - | ||||||||||||||||||
3114 | QTextFrameData *fd = data(frame); | - | ||||||||||||||||||
3115 | offset += fd->position.toPointF(); | - | ||||||||||||||||||
3116 | - | |||||||||||||||||||
3117 | if (QTextTable *table = qobject_cast<QTextTable *>(frame)) { | - | ||||||||||||||||||
3118 | QTextTableCell cell = table->cellAt(blockPos); | - | ||||||||||||||||||
3119 | if (cell.isValid()) | - | ||||||||||||||||||
3120 | offset += static_cast<QTextTableData *>(fd)->cellPosition(cell).toPointF(); | - | ||||||||||||||||||
3121 | } | - | ||||||||||||||||||
3122 | - | |||||||||||||||||||
3123 | frame = frame->parentFrame(); | - | ||||||||||||||||||
3124 | } | - | ||||||||||||||||||
3125 | - | |||||||||||||||||||
3126 | const QTextLayout *layout = block.layout(); | - | ||||||||||||||||||
3127 | QRectF rect = layout->boundingRect(); | - | ||||||||||||||||||
3128 | rect.moveTopLeft(layout->position() + offset); | - | ||||||||||||||||||
3129 | return rect; | - | ||||||||||||||||||
3130 | } | - | ||||||||||||||||||
3131 | - | |||||||||||||||||||
3132 | int QTextDocumentLayout::layoutStatus() const | - | ||||||||||||||||||
3133 | { | - | ||||||||||||||||||
3134 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3135 | int pos = d->currentLazyLayoutPosition; | - | ||||||||||||||||||
3136 | if (pos == -1) | - | ||||||||||||||||||
3137 | return 100; | - | ||||||||||||||||||
3138 | return pos * 100 / d->document->docHandle()->length(); | - | ||||||||||||||||||
3139 | } | - | ||||||||||||||||||
3140 | - | |||||||||||||||||||
3141 | void QTextDocumentLayout::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||
3142 | { | - | ||||||||||||||||||
3143 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3144 | if (e->timerId() == d->layoutTimer.timerId()) { | - | ||||||||||||||||||
3145 | if (d->currentLazyLayoutPosition != -1) | - | ||||||||||||||||||
3146 | d->layoutStep(); | - | ||||||||||||||||||
3147 | } else if (e->timerId() == d->sizeChangedTimer.timerId()) { | - | ||||||||||||||||||
3148 | d->lastReportedSize = dynamicDocumentSize(); | - | ||||||||||||||||||
3149 | documentSizeChanged(d->lastReportedSize); | - | ||||||||||||||||||
3150 | d->sizeChangedTimer.stop(); | - | ||||||||||||||||||
3151 | - | |||||||||||||||||||
3152 | if (d->currentLazyLayoutPosition == -1) { | - | ||||||||||||||||||
3153 | const int newCount = dynamicPageCount(); | - | ||||||||||||||||||
3154 | if (newCount != d->lastPageCount) { | - | ||||||||||||||||||
3155 | d->lastPageCount = newCount; | - | ||||||||||||||||||
3156 | pageCountChanged(newCount); | - | ||||||||||||||||||
3157 | } | - | ||||||||||||||||||
3158 | } | - | ||||||||||||||||||
3159 | } else { | - | ||||||||||||||||||
3160 | QAbstractTextDocumentLayout::timerEvent(e); | - | ||||||||||||||||||
3161 | } | - | ||||||||||||||||||
3162 | } | - | ||||||||||||||||||
3163 | - | |||||||||||||||||||
3164 | void QTextDocumentLayout::layoutFinished() | - | ||||||||||||||||||
3165 | { | - | ||||||||||||||||||
3166 | QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3167 | d->layoutTimer.stop(); | - | ||||||||||||||||||
3168 | if (!d->insideDocumentChange) | - | ||||||||||||||||||
3169 | d->sizeChangedTimer.start(0, this); | - | ||||||||||||||||||
3170 | - | |||||||||||||||||||
3171 | d->showLayoutProgress = true; | - | ||||||||||||||||||
3172 | } | - | ||||||||||||||||||
3173 | - | |||||||||||||||||||
3174 | void QTextDocumentLayout::ensureLayouted(qreal y) | - | ||||||||||||||||||
3175 | { | - | ||||||||||||||||||
3176 | d_func()->ensureLayouted(QFixed::fromReal(y)); | - | ||||||||||||||||||
3177 | } | - | ||||||||||||||||||
3178 | - | |||||||||||||||||||
3179 | qreal QTextDocumentLayout::idealWidth() const | - | ||||||||||||||||||
3180 | { | - | ||||||||||||||||||
3181 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3182 | d->ensureLayoutFinished(); | - | ||||||||||||||||||
3183 | return d->idealWidth; | - | ||||||||||||||||||
3184 | } | - | ||||||||||||||||||
3185 | - | |||||||||||||||||||
3186 | bool QTextDocumentLayout::contentHasAlignment() const | - | ||||||||||||||||||
3187 | { | - | ||||||||||||||||||
3188 | const QTextDocumentLayoutPrivate * const d = d_func(); | - | ||||||||||||||||||
3189 | return d->contentHasAlignment; | - | ||||||||||||||||||
3190 | } | - | ||||||||||||||||||
3191 | - | |||||||||||||||||||
3192 | qreal QTextDocumentLayoutPrivate::scaleToDevice(qreal value) const | - | ||||||||||||||||||
3193 | { | - | ||||||||||||||||||
3194 | if (!paintDevice) | - | ||||||||||||||||||
3195 | return value; | - | ||||||||||||||||||
3196 | return value * paintDevice->logicalDpiY() / qreal(qt_defaultDpi()); | - | ||||||||||||||||||
3197 | } | - | ||||||||||||||||||
3198 | - | |||||||||||||||||||
3199 | QFixed QTextDocumentLayoutPrivate::scaleToDevice(QFixed value) const | - | ||||||||||||||||||
3200 | { | - | ||||||||||||||||||
3201 | if (!paintDevice) | - | ||||||||||||||||||
3202 | return value; | - | ||||||||||||||||||
3203 | return value * QFixed(paintDevice->logicalDpiY()) / QFixed(qt_defaultDpi()); | - | ||||||||||||||||||
3204 | } | - | ||||||||||||||||||
3205 | - | |||||||||||||||||||
3206 | - | |||||||||||||||||||
3207 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |