Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qtextdocumentfragment.h" | - |
41 | #include "qtextdocumentfragment_p.h" | - |
42 | #include "qtextcursor_p.h" | - |
43 | #include "qtextlist.h" | - |
44 | | - |
45 | #include <qdebug.h> | - |
46 | #include <qtextcodec.h> | - |
47 | #include <qbytearray.h> | - |
48 | #include <qdatastream.h> | - |
49 | #include <qdatetime.h> | - |
50 | | - |
51 | QT_BEGIN_NAMESPACE | - |
52 | | - |
53 | QTextCopyHelper::QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat, const QTextCharFormat &fmt) | - |
54 | #if defined(Q_CC_DIAB) // compiler bug | - |
55 | : formatCollection(*_destination.d->priv->formatCollection()), originalText((const QString)_source.d->priv->buffer()) | - |
56 | #else | - |
57 | : formatCollection(*_destination.d->priv->formatCollection()), originalText(_source.d->priv->buffer()) | - |
58 | #endif | - |
59 | { | - |
60 | src = _source.d->priv; | - |
61 | dst = _destination.d->priv; | - |
62 | insertPos = _destination.position(); | - |
63 | this->forceCharFormat = forceCharFormat; | - |
64 | primaryCharFormatIndex = convertFormatIndex(fmt); | - |
65 | cursor = _source; | - |
66 | } | - |
67 | | - |
68 | int QTextCopyHelper::convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet) | - |
69 | { | - |
70 | QTextFormat fmt = oldFormat; | - |
71 | if (objectIndexToSet != -1) { | - |
72 | fmt.setObjectIndex(objectIndexToSet); | - |
73 | } else if (fmt.objectIndex() != -1) { | - |
74 | int newObjectIndex = objectIndexMap.value(fmt.objectIndex(), -1); | - |
75 | if (newObjectIndex == -1) { | - |
76 | QTextFormat objFormat = src->formatCollection()->objectFormat(fmt.objectIndex()); | - |
77 | Q_ASSERT(objFormat.objectIndex() == -1); | - |
78 | newObjectIndex = formatCollection.createObjectIndex(objFormat); | - |
79 | objectIndexMap.insert(fmt.objectIndex(), newObjectIndex); | - |
80 | } | - |
81 | fmt.setObjectIndex(newObjectIndex); | - |
82 | } | - |
83 | int idx = formatCollection.indexForFormat(fmt); | - |
84 | Q_ASSERT(formatCollection.format(idx).type() == oldFormat.type()); | - |
85 | return idx; | - |
86 | } | - |
87 | | - |
88 | int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex) | - |
89 | { | - |
90 | QTextDocumentPrivate::FragmentIterator fragIt = src->find(pos); | - |
91 | const QTextFragmentData * const frag = fragIt.value(); | - |
92 | | - |
93 | Q_ASSERT(objectIndex == -1 | - |
94 | || (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1)); | - |
95 | | - |
96 | int charFormatIndex; | - |
97 | if (forceCharFormat) | - |
98 | charFormatIndex = primaryCharFormatIndex; | - |
99 | else | - |
100 | charFormatIndex = convertFormatIndex(frag->format, objectIndex); | - |
101 | | - |
102 | const int inFragmentOffset = qMax(0, pos - fragIt.position()); | - |
103 | int charsToCopy = qMin(int(frag->size_array[0] - inFragmentOffset), endPos - pos); | - |
104 | | - |
105 | QTextBlock nextBlock = src->blocksFind(pos + 1); | - |
106 | | - |
107 | int blockIdx = -2; | - |
108 | if (nextBlock.position() == pos + 1) { | - |
109 | blockIdx = convertFormatIndex(nextBlock.blockFormat()); | - |
110 | } else if (pos == 0 && insertPos == 0) { | - |
111 | dst->setBlockFormat(dst->blocksBegin(), dst->blocksBegin(), convertFormat(src->blocksBegin().blockFormat()).toBlockFormat()); | - |
112 | dst->setCharFormat(-1, 1, convertFormat(src->blocksBegin().charFormat()).toCharFormat()); | - |
113 | } | - |
114 | | - |
115 | QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy); | - |
116 | if (txtToInsert.length() == 1 | - |
117 | && (txtToInsert.at(0) == QChar::ParagraphSeparator | - |
118 | || txtToInsert.at(0) == QTextBeginningOfFrame | - |
119 | || txtToInsert.at(0) == QTextEndOfFrame | - |
120 | ) | - |
121 | ) { | - |
122 | dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex); | - |
123 | ++insertPos; | - |
124 | } else { | - |
125 | if (nextBlock.textList()) { | - |
126 | QTextBlock dstBlock = dst->blocksFind(insertPos); | - |
127 | if (!dstBlock.textList()) { | - |
128 | | - |
129 | | - |
130 | | - |
131 | int listBlockFormatIndex = convertFormatIndex(nextBlock.blockFormat()); | - |
132 | int listCharFormatIndex = convertFormatIndex(nextBlock.charFormat()); | - |
133 | dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex); | - |
134 | ++insertPos; | - |
135 | } | - |
136 | } | - |
137 | dst->insert(insertPos, txtToInsert, charFormatIndex); | - |
138 | const int userState = nextBlock.userState(); | - |
139 | if (userState != -1) | - |
140 | dst->blocksFind(insertPos).setUserState(userState); | - |
141 | insertPos += txtToInsert.length(); | - |
142 | } | - |
143 | | - |
144 | return charsToCopy; | - |
145 | } | - |
146 | | - |
147 | void QTextCopyHelper::appendFragments(int pos, int endPos) | - |
148 | { | - |
149 | Q_ASSERT(pos < endPos); | - |
150 | | - |
151 | while (pos < endPos) | - |
152 | pos += appendFragment(pos, endPos); | - |
153 | } | - |
154 | | - |
155 | void QTextCopyHelper::copy() | - |
156 | { | - |
157 | if (cursor.hasComplexSelection()) { | - |
158 | QTextTable *table = cursor.currentTable(); | - |
159 | int row_start, col_start, num_rows, num_cols; | - |
160 | cursor.selectedTableCells(&row_start, &num_rows, &col_start, &num_cols); | - |
161 | | - |
162 | QTextTableFormat tableFormat = table->format(); | - |
163 | tableFormat.setColumns(num_cols); | - |
164 | tableFormat.clearColumnWidthConstraints(); | - |
165 | const int objectIndex = dst->formatCollection()->createObjectIndex(tableFormat); | - |
166 | | - |
167 | Q_ASSERT(row_start != -1); | - |
168 | for (int r = row_start; r < row_start + num_rows; ++r) { | - |
169 | for (int c = col_start; c < col_start + num_cols; ++c) { | - |
170 | QTextTableCell cell = table->cellAt(r, c); | - |
171 | const int rspan = cell.rowSpan(); | - |
172 | const int cspan = cell.columnSpan(); | - |
173 | if (rspan != 1) { | - |
174 | int cr = cell.row(); | - |
175 | if (cr != r) | - |
176 | continue; | - |
177 | } | - |
178 | if (cspan != 1) { | - |
179 | int cc = cell.column(); | - |
180 | if (cc != c) | - |
181 | continue; | - |
182 | } | - |
183 | | - |
184 | | - |
185 | QTextCharFormat cellFormat = cell.format(); | - |
186 | if (r + rspan >= row_start + num_rows) { | - |
187 | cellFormat.setTableCellRowSpan(row_start + num_rows - r); | - |
188 | } | - |
189 | if (c + cspan >= col_start + num_cols) { | - |
190 | cellFormat.setTableCellColumnSpan(col_start + num_cols - c); | - |
191 | } | - |
192 | const int charFormatIndex = convertFormatIndex(cellFormat, objectIndex); | - |
193 | | - |
194 | int blockIdx = -2; | - |
195 | const int cellPos = cell.firstPosition(); | - |
196 | QTextBlock block = src->blocksFind(cellPos); | - |
197 | if (block.position() == cellPos) { | - |
198 | blockIdx = convertFormatIndex(block.blockFormat()); | - |
199 | } | - |
200 | | - |
201 | dst->insertBlock(QTextBeginningOfFrame, insertPos, blockIdx, charFormatIndex); | - |
202 | ++insertPos; | - |
203 | | - |
204 | | - |
205 | if (cell.lastPosition() > cellPos) { | - |
206 | | - |
207 | appendFragments(cellPos, cell.lastPosition()); | - |
208 | } | - |
209 | } | - |
210 | } | - |
211 | | - |
212 | | - |
213 | int end = table->lastPosition(); | - |
214 | appendFragment(end, end+1, objectIndex); | - |
215 | } else { | - |
216 | appendFragments(cursor.selectionStart(), cursor.selectionEnd()); | - |
217 | } | - |
218 | } | - |
219 | | - |
220 | QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(const QTextCursor &_cursor) | - |
221 | : ref(1), doc(new QTextDocument), importedFromPlainText(false) | - |
222 | { | - |
223 | doc->setUndoRedoEnabled(false); | - |
224 | | - |
225 | if (!_cursor.hasSelection()) | - |
226 | return; | - |
227 | | - |
228 | doc->docHandle()->beginEditBlock(); | - |
229 | QTextCursor destCursor(doc); | - |
230 | QTextCopyHelper(_cursor, destCursor).copy(); | - |
231 | doc->docHandle()->endEditBlock(); | - |
232 | | - |
233 | if (_cursor.d) | - |
234 | doc->docHandle()->mergeCachedResources(_cursor.d->priv); | - |
235 | } | - |
236 | | - |
237 | void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const | - |
238 | { | - |
239 | if (_cursor.isNull()) | - |
240 | return; | - |
241 | | - |
242 | QTextDocumentPrivate *destPieceTable = _cursor.d->priv; | - |
243 | destPieceTable->beginEditBlock(); | - |
244 | | - |
245 | QTextCursor sourceCursor(doc); | - |
246 | sourceCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); | - |
247 | QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy(); | - |
248 | | - |
249 | destPieceTable->endEditBlock(); | - |
250 | } | - |
251 | | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | QTextDocumentFragment::QTextDocumentFragment() | - |
281 | : d(0) | - |
282 | { | - |
283 | } | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | QTextDocumentFragment::QTextDocumentFragment(const QTextDocument *document) | - |
291 | : d(0) | - |
292 | { | - |
293 | if (!document) | - |
294 | return; | - |
295 | | - |
296 | QTextCursor cursor(const_cast<QTextDocument *>(document)); | - |
297 | cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); | - |
298 | d = new QTextDocumentFragmentPrivate(cursor); | - |
299 | } | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | QTextDocumentFragment::QTextDocumentFragment(const QTextCursor &cursor) | - |
308 | : d(0) | - |
309 | { | - |
310 | if (!cursor.hasSelection()) | - |
311 | return; | - |
312 | | - |
313 | d = new QTextDocumentFragmentPrivate(cursor); | - |
314 | } | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | QTextDocumentFragment::QTextDocumentFragment(const QTextDocumentFragment &rhs) | - |
322 | : d(rhs.d) | - |
323 | { | - |
324 | if (d) | - |
325 | d->ref.ref(); | - |
326 | } | - |
327 | | - |
328 | | - |
329 | | - |
330 | | - |
331 | | - |
332 | | - |
333 | QTextDocumentFragment &QTextDocumentFragment::operator=(const QTextDocumentFragment &rhs) | - |
334 | { | - |
335 | if (rhs.d) | - |
336 | rhs.d->ref.ref(); | - |
337 | if (d && !d->ref.deref()) | - |
338 | delete d; | - |
339 | d = rhs.d; | - |
340 | return *this; | - |
341 | } | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | QTextDocumentFragment::~QTextDocumentFragment() | - |
347 | { | - |
348 | if (d && !d->ref.deref()) | - |
349 | delete d; | - |
350 | } | - |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | bool QTextDocumentFragment::isEmpty() const | - |
356 | { | - |
357 | return !d || !d->doc || d->doc->docHandle()->length() <= 1; | - |
358 | } | - |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | QString QTextDocumentFragment::toPlainText() const | - |
367 | { | - |
368 | if (!d) | - |
369 | return QString(); | - |
370 | | - |
371 | return d->doc->toPlainText(); | - |
372 | } | - |
373 | | - |
374 | #ifndef QT_NO_TEXTHTMLPARSER | - |
375 | | - |
376 | | - |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | QString QTextDocumentFragment::toHtml(const QByteArray &encoding) const | - |
385 | { | - |
386 | if (!d) | - |
387 | return QString(); | - |
388 | | - |
389 | return QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment); | - |
390 | } | - |
391 | | - |
392 | #endif // QT_NO_TEXTHTMLPARSER | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | QTextDocumentFragment QTextDocumentFragment::fromPlainText(const QString &plainText) | - |
401 | { | - |
402 | QTextDocumentFragment res; | - |
403 | | - |
404 | res.d = new QTextDocumentFragmentPrivate; | - |
405 | res.d->importedFromPlainText = true; | - |
406 | QTextCursor cursor(res.d->doc); | - |
407 | cursor.insertText(plainText); | - |
408 | return res; | - |
409 | } | - |
410 | | - |
411 | static QTextListFormat::Style nextListStyle(QTextListFormat::Style style) | - |
412 | { | - |
413 | if (style == QTextListFormat::ListDisc) | - |
414 | return QTextListFormat::ListCircle; | - |
415 | else if (style == QTextListFormat::ListCircle) | - |
416 | return QTextListFormat::ListSquare; | - |
417 | return style; | - |
418 | } | - |
419 | | - |
420 | #ifndef QT_NO_TEXTHTMLPARSER | - |
421 | | - |
422 | QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html, ImportMode mode, const QTextDocument *resourceProvider) | - |
423 | : indent(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(mode) | - |
424 | { | - |
425 | cursor = QTextCursor(doc); | - |
426 | wsm = QTextHtmlParserNode::WhiteSpaceNormal; | - |
427 | | - |
428 | QString html = _html; | - |
429 | const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->")); | - |
430 | if (startFragmentPos != -1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
431 | QString qt3RichTextHeader(const QLatin1String qt3RichTextHeader("<meta name=\"qrichtext\" content=\"1\" />"));); | - |
432 | | - |
433 | | - |
434 | const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader); | - |
435 | | - |
436 | const int endFragmentPos = html.indexOf(QLatin1String("<!--EndFragment-->")); | - |
437 | if (startFragmentPos < endFragmentPos)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
438 | html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos); never executed: html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos); | 0 |
439 | else | - |
440 | html = html.mid(startFragmentPos); never executed: html = html.mid(startFragmentPos); | 0 |
441 | | - |
442 | if (hasQtRichtextMetaTag)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
443 | html.prepend(qt3RichTextHeader); never executed: html.prepend(qt3RichTextHeader); | 0 |
444 | } never executed: end of block | 0 |
445 | | - |
446 | parse(html, resourceProvider ? resourceProvider : doc); | - |
447 | | - |
448 | } never executed: end of block | 0 |
449 | | - |
450 | void QTextHtmlImporter::import() | - |
451 | { | - |
452 | cursor.beginEditBlock(); | - |
453 | hasBlock = true; | - |
454 | forceBlockMerging = false; | - |
455 | compressNextWhitespace = RemoveWhiteSpace; | - |
456 | blockTagClosed = false; | - |
457 | for (currentNodeIdx = 0; currentNodeIdx < count(); ++currentNodeIdx) { | - |
458 | currentNode = &at(currentNodeIdx); | - |
459 | wsm = textEditMode ? QTextHtmlParserNode::WhiteSpacePreWrap : currentNode->wsm; | - |
460 | | - |
461 | | - |
462 | | - |
463 | | - |
464 | | - |
465 | | - |
466 | | - |
467 | | - |
468 | | - |
469 | | - |
470 | | - |
471 | | - |
472 | | - |
473 | | - |
474 | | - |
475 | | - |
476 | | - |
477 | | - |
478 | | - |
479 | | - |
480 | if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) { | - |
481 | blockTagClosed = closeTag(); | - |
482 | | - |
483 | | - |
484 | | - |
485 | if (blockTagClosed | - |
486 | && !currentNode->isBlock() | - |
487 | && currentNode->id != Html_unknown) | - |
488 | { | - |
489 | hasBlock = false; | - |
490 | } else if (blockTagClosed && hasBlock) { | - |
491 | | - |
492 | QTextBlockFormat blockFormat = currentNode->blockFormat; | - |
493 | blockFormat.setIndent(indent); | - |
494 | | - |
495 | QTextBlockFormat oldFormat = cursor.blockFormat(); | - |
496 | if (oldFormat.hasProperty(QTextFormat::PageBreakPolicy)) { | - |
497 | QTextFormat::PageBreakFlags pageBreak = oldFormat.pageBreakPolicy(); | - |
498 | if (pageBreak == QTextFormat::PageBreak_AlwaysAfter) | - |
499 | | - |
500 | | - |
501 | | - |
502 | | - |
503 | pageBreak = QTextFormat::PageBreak_AlwaysBefore; | - |
504 | blockFormat.setPageBreakPolicy(pageBreak); | - |
505 | } | - |
506 | | - |
507 | cursor.setBlockFormat(blockFormat); | - |
508 | } | - |
509 | } | - |
510 | | - |
511 | if (currentNode->displayMode == QTextHtmlElement::DisplayNone) { | - |
512 | if (currentNode->id == Html_title) | - |
513 | doc->setMetaInformation(QTextDocument::DocumentTitle, currentNode->text); | - |
514 | | - |
515 | continue; | - |
516 | } | - |
517 | | - |
518 | if (processSpecialNodes() == ContinueWithNextNode) | - |
519 | continue; | - |
520 | | - |
521 | | - |
522 | if (blockTagClosed | - |
523 | && !hasBlock | - |
524 | && !currentNode->isBlock() | - |
525 | && !currentNode->text.isEmpty() && !currentNode->hasOnlyWhitespace() | - |
526 | && currentNode->displayMode == QTextHtmlElement::DisplayInline) { | - |
527 | | - |
528 | QTextBlockFormat block = currentNode->blockFormat; | - |
529 | block.setIndent(indent); | - |
530 | | - |
531 | appendBlock(block, currentNode->charFormat); | - |
532 | | - |
533 | hasBlock = true; | - |
534 | } | - |
535 | | - |
536 | if (currentNode->isBlock()) { | - |
537 | QTextHtmlImporter::ProcessNodeResult result = processBlockNode(); | - |
538 | if (result == ContinueWithNextNode) { | - |
539 | continue; | - |
540 | } else if (result == ContinueWithNextSibling) { | - |
541 | currentNodeIdx += currentNode->children.size(); | - |
542 | continue; | - |
543 | } | - |
544 | } | - |
545 | | - |
546 | if (currentNode->charFormat.isAnchor() && !currentNode->charFormat.anchorName().isEmpty()) { | - |
547 | namedAnchors.append(currentNode->charFormat.anchorName()); | - |
548 | } | - |
549 | | - |
550 | if (appendNodeText()) | - |
551 | hasBlock = false; | - |
552 | | - |
553 | } | - |
554 | | - |
555 | cursor.endEditBlock(); | - |
556 | } | - |
557 | | - |
558 | bool QTextHtmlImporter::appendNodeText() | - |
559 | { | - |
560 | const int initialCursorPosition = cursor.position(); | - |
561 | QTextCharFormat format = currentNode->charFormat; | - |
562 | | - |
563 | if(wsm == QTextHtmlParserNode::WhiteSpacePre || wsm == QTextHtmlParserNode::WhiteSpacePreWrap) | - |
564 | compressNextWhitespace = PreserveWhiteSpace; | - |
565 | | - |
566 | QString text = currentNode->text; | - |
567 | | - |
568 | QString textToInsert; | - |
569 | textToInsert.reserve(text.size()); | - |
570 | | - |
571 | for (int i = 0; i < text.length(); ++i) { | - |
572 | QChar ch = text.at(i); | - |
573 | | - |
574 | if (ch.isSpace() | - |
575 | && ch != QChar::Nbsp | - |
576 | && ch != QChar::ParagraphSeparator) { | - |
577 | | - |
578 | if (compressNextWhitespace == CollapseWhiteSpace) | - |
579 | compressNextWhitespace = RemoveWhiteSpace; | - |
580 | else if(compressNextWhitespace == RemoveWhiteSpace) | - |
581 | continue; | - |
582 | | - |
583 | if (wsm == QTextHtmlParserNode::WhiteSpacePre | - |
584 | || textEditMode | - |
585 | ) { | - |
586 | if (ch == QLatin1Char('\n')) { | - |
587 | if (textEditMode) | - |
588 | continue; | - |
589 | } else if (ch == QLatin1Char('\r')) { | - |
590 | continue; | - |
591 | } | - |
592 | } else if (wsm != QTextHtmlParserNode::WhiteSpacePreWrap) { | - |
593 | compressNextWhitespace = RemoveWhiteSpace; | - |
594 | if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap) | - |
595 | ch = QChar::Nbsp; | - |
596 | else | - |
597 | ch = QLatin1Char(' '); | - |
598 | } | - |
599 | } else { | - |
600 | compressNextWhitespace = PreserveWhiteSpace; | - |
601 | } | - |
602 | | - |
603 | if (ch == QLatin1Char('\n') | - |
604 | || ch == QChar::ParagraphSeparator) { | - |
605 | | - |
606 | if (!textToInsert.isEmpty()) { | - |
607 | cursor.insertText(textToInsert, format); | - |
608 | textToInsert.clear(); | - |
609 | } | - |
610 | | - |
611 | QTextBlockFormat fmt = cursor.blockFormat(); | - |
612 | | - |
613 | if (fmt.hasProperty(QTextFormat::BlockBottomMargin)) { | - |
614 | QTextBlockFormat tmp = fmt; | - |
615 | tmp.clearProperty(QTextFormat::BlockBottomMargin); | - |
616 | cursor.setBlockFormat(tmp); | - |
617 | } | - |
618 | | - |
619 | fmt.clearProperty(QTextFormat::BlockTopMargin); | - |
620 | appendBlock(fmt, cursor.charFormat()); | - |
621 | } else { | - |
622 | if (!namedAnchors.isEmpty()) { | - |
623 | if (!textToInsert.isEmpty()) { | - |
624 | cursor.insertText(textToInsert, format); | - |
625 | textToInsert.clear(); | - |
626 | } | - |
627 | | - |
628 | format.setAnchor(true); | - |
629 | format.setAnchorNames(namedAnchors); | - |
630 | cursor.insertText(ch, format); | - |
631 | namedAnchors.clear(); | - |
632 | format.clearProperty(QTextFormat::IsAnchor); | - |
633 | format.clearProperty(QTextFormat::AnchorName); | - |
634 | } else { | - |
635 | textToInsert += ch; | - |
636 | } | - |
637 | } | - |
638 | } | - |
639 | | - |
640 | if (!textToInsert.isEmpty()) { | - |
641 | cursor.insertText(textToInsert, format); | - |
642 | } | - |
643 | | - |
644 | return cursor.position() != initialCursorPosition; | - |
645 | } | - |
646 | | - |
647 | QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() | - |
648 | { | - |
649 | switch (currentNode->id) { | - |
650 | case Html_body: | - |
651 | if (currentNode->charFormat.background().style() != Qt::NoBrush) { | - |
652 | QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); | - |
653 | fmt.setBackground(currentNode->charFormat.background()); | - |
654 | doc->rootFrame()->setFrameFormat(fmt); | - |
655 | const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush); | - |
656 | } | - |
657 | compressNextWhitespace = RemoveWhiteSpace; | - |
658 | break; | - |
659 | | - |
660 | case Html_ol: | - |
661 | case Html_ul: { | - |
662 | QTextListFormat::Style style = currentNode->listStyle; | - |
663 | | - |
664 | if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) { | - |
665 | const QTextHtmlParserNode *n = &at(currentNode->parent); | - |
666 | while (n) { | - |
667 | if (n->id == Html_ul) { | - |
668 | style = nextListStyle(currentNode->listStyle); | - |
669 | } | - |
670 | if (n->parent) | - |
671 | n = &at(n->parent); | - |
672 | else | - |
673 | n = 0; | - |
674 | } | - |
675 | } | - |
676 | | - |
677 | QTextListFormat listFmt; | - |
678 | listFmt.setStyle(style); | - |
679 | if (!currentNode->textListNumberPrefix.isNull()) | - |
680 | listFmt.setNumberPrefix(currentNode->textListNumberPrefix); | - |
681 | if (!currentNode->textListNumberSuffix.isNull()) | - |
682 | listFmt.setNumberSuffix(currentNode->textListNumberSuffix); | - |
683 | | - |
684 | ++indent; | - |
685 | if (currentNode->hasCssListIndent) | - |
686 | listFmt.setIndent(currentNode->cssListIndent); | - |
687 | else | - |
688 | listFmt.setIndent(indent); | - |
689 | | - |
690 | List l; | - |
691 | l.format = listFmt; | - |
692 | l.listNode = currentNodeIdx; | - |
693 | lists.append(l); | - |
694 | compressNextWhitespace = RemoveWhiteSpace; | - |
695 | | - |
696 | | - |
697 | const QString simpl = currentNode->text.simplified(); | - |
698 | if (simpl.isEmpty() || simpl.at(0).isSpace()) | - |
699 | return ContinueWithNextNode; | - |
700 | break; | - |
701 | } | - |
702 | | - |
703 | case Html_table: { | - |
704 | Table t = scanTable(currentNodeIdx); | - |
705 | tables.append(t); | - |
706 | hasBlock = false; | - |
707 | compressNextWhitespace = RemoveWhiteSpace; | - |
708 | return ContinueWithNextNode; | - |
709 | } | - |
710 | | - |
711 | case Html_tr: | - |
712 | return ContinueWithNextNode; | - |
713 | | - |
714 | case Html_img: { | - |
715 | QTextImageFormat fmt; | - |
716 | fmt.setName(currentNode->imageName); | - |
717 | | - |
718 | fmt.merge(currentNode->charFormat); | - |
719 | | - |
720 | if (currentNode->imageWidth != -1) | - |
721 | fmt.setWidth(currentNode->imageWidth); | - |
722 | if (currentNode->imageHeight != -1) | - |
723 | fmt.setHeight(currentNode->imageHeight); | - |
724 | | - |
725 | cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat)); | - |
726 | | - |
727 | cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); | - |
728 | cursor.mergeCharFormat(currentNode->charFormat); | - |
729 | cursor.movePosition(QTextCursor::Right); | - |
730 | compressNextWhitespace = CollapseWhiteSpace; | - |
731 | | - |
732 | hasBlock = false; | - |
733 | return ContinueWithNextNode; | - |
734 | } | - |
735 | | - |
736 | case Html_hr: { | - |
737 | QTextBlockFormat blockFormat = currentNode->blockFormat; | - |
738 | blockFormat.setTopMargin(topMargin(currentNodeIdx)); | - |
739 | blockFormat.setBottomMargin(bottomMargin(currentNodeIdx)); | - |
740 | blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width); | - |
741 | if (hasBlock && importMode == ImportToDocument) | - |
742 | cursor.mergeBlockFormat(blockFormat); | - |
743 | else | - |
744 | appendBlock(blockFormat); | - |
745 | hasBlock = false; | - |
746 | compressNextWhitespace = RemoveWhiteSpace; | - |
747 | return ContinueWithNextNode; | - |
748 | } | - |
749 | | - |
750 | default: break; | - |
751 | } | - |
752 | return ContinueWithCurrentNode; | - |
753 | } | - |
754 | | - |
755 | | - |
756 | bool QTextHtmlImporter::closeTag() | - |
757 | { | - |
758 | const QTextHtmlParserNode *closedNode = &at(currentNodeIdx - 1); | - |
759 | const int endDepth = depth(currentNodeIdx) - 1; | - |
760 | int depth = this->depth(currentNodeIdx - 1); | - |
761 | bool blockTagClosed = false; | - |
762 | | - |
763 | while (depth > endDepth) { | - |
764 | Table *t = 0; | - |
765 | if (!tables.isEmpty()) | - |
766 | t = &tables.last(); | - |
767 | | - |
768 | switch (closedNode->id) { | - |
769 | case Html_tr: | - |
770 | if (t && !t->isTextFrame) { | - |
771 | ++t->currentRow; | - |
772 | | - |
773 | | - |
774 | while (!t->currentCell.atEnd() && t->currentCell.row < t->currentRow) | - |
775 | ++t->currentCell; | - |
776 | } | - |
777 | | - |
778 | blockTagClosed = true; | - |
779 | break; | - |
780 | | - |
781 | case Html_table: | - |
782 | if (!t) | - |
783 | break; | - |
784 | indent = t->lastIndent; | - |
785 | | - |
786 | tables.resize(tables.size() - 1); | - |
787 | t = 0; | - |
788 | | - |
789 | if (tables.isEmpty()) { | - |
790 | cursor = doc->rootFrame()->lastCursorPosition(); | - |
791 | } else { | - |
792 | t = &tables.last(); | - |
793 | if (t->isTextFrame) | - |
794 | cursor = t->frame->lastCursorPosition(); | - |
795 | else if (!t->currentCell.atEnd()) | - |
796 | cursor = t->currentCell.cell().lastCursorPosition(); | - |
797 | } | - |
798 | | - |
799 | | - |
800 | | - |
801 | | - |
802 | blockTagClosed = false; | - |
803 | compressNextWhitespace = RemoveWhiteSpace; | - |
804 | break; | - |
805 | | - |
806 | case Html_th: | - |
807 | case Html_td: | - |
808 | if (t && !t->isTextFrame) | - |
809 | ++t->currentCell; | - |
810 | blockTagClosed = true; | - |
811 | compressNextWhitespace = RemoveWhiteSpace; | - |
812 | break; | - |
813 | | - |
814 | case Html_ol: | - |
815 | case Html_ul: | - |
816 | if (lists.isEmpty()) | - |
817 | break; | - |
818 | lists.resize(lists.size() - 1); | - |
819 | --indent; | - |
820 | blockTagClosed = true; | - |
821 | break; | - |
822 | | - |
823 | case Html_br: | - |
824 | compressNextWhitespace = RemoveWhiteSpace; | - |
825 | break; | - |
826 | | - |
827 | case Html_div: | - |
828 | if (closedNode->children.isEmpty()) | - |
829 | break; | - |
830 | | - |
831 | default: | - |
832 | if (closedNode->isBlock()) | - |
833 | blockTagClosed = true; | - |
834 | break; | - |
835 | } | - |
836 | | - |
837 | closedNode = &at(closedNode->parent); | - |
838 | --depth; | - |
839 | } | - |
840 | | - |
841 | return blockTagClosed; | - |
842 | } | - |
843 | | - |
844 | QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) | - |
845 | { | - |
846 | Table table; | - |
847 | table.columns = 0; | - |
848 | | - |
849 | QVector<QTextLength> columnWidths; | - |
850 | | - |
851 | int tableHeaderRowCount = 0; | - |
852 | QVector<int> rowNodes; | - |
853 | rowNodes.reserve(at(tableNodeIdx).children.count()); | - |
854 | foreachfor (int row ,: at(tableNodeIdx).children) { | - |
855 | switch (at(row).id) { | - |
856 | case Html_tr: never executed: case Html_tr: | 0 |
857 | rowNodes += row; | - |
858 | break; never executed: break; | 0 |
859 | case Html_thead: never executed: case Html_thead: | 0 |
860 | case Html_tbody: never executed: case Html_tbody: | 0 |
861 | case Html_tfoot: never executed: case Html_tfoot: | 0 |
862 | foreachfor (int potentialRow ,: at(row).children) { | - |
863 | if (at(potentialRow).id == Html_tr) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
864 | rowNodes += potentialRow; | - |
865 | if (at(row).id == Html_thead)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
866 | ++tableHeaderRowCount; never executed: ++tableHeaderRowCount; | 0 |
867 | } never executed: end of block | 0 |
868 | } never executed: end of block | 0 |
869 | break; never executed: break; | 0 |
870 | default: break; never executed: break; never executed: default: | 0 |
871 | } | - |
872 | } | - |
873 | | - |
874 | QVector<RowColSpanInfo> rowColSpans; | - |
875 | QVector<RowColSpanInfo> rowColSpanForColumn; | - |
876 | | - |
877 | int effectiveRow = 0; | - |
878 | foreachfor (int row ,: qAsConst(rowNodes))) { | - |
879 | int colsInRow = 0; | - |
880 | | - |
881 | foreachfor (int cell ,: at(row).children) { | - |
882 | if (at(cell).isTableCell()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
883 | | - |
884 | while (colsInRow < rowColSpanForColumn.size()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
885 | const RowColSpanInfo &spanInfo = rowColSpanForColumn[.at(colsInRow];); | - |
886 | | - |
887 | if (spanInfo.row + spanInfo.rowSpan > effectiveRow) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
888 | Q_ASSERT(spanInfo.col == colsInRow); | - |
889 | colsInRow += spanInfo.colSpan; | - |
890 | } else never executed: end of block | 0 |
891 | break; never executed: break; | 0 |
892 | } | - |
893 | | - |
894 | const QTextHtmlParserNode &c = at(cell); | - |
895 | const int currentColumn = colsInRow; | - |
896 | colsInRow += c.tableCellColSpan; | - |
897 | | - |
898 | RowColSpanInfo spanInfo; | - |
899 | spanInfo.row = effectiveRow; | - |
900 | spanInfo.col = currentColumn; | - |
901 | spanInfo.colSpan = c.tableCellColSpan; | - |
902 | spanInfo.rowSpan = c.tableCellRowSpan; | - |
903 | if (spanInfo.colSpan > 1 || spanInfo.rowSpan > 1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
904 | rowColSpans.append(spanInfo); never executed: rowColSpans.append(spanInfo); | 0 |
905 | | - |
906 | columnWidths.resize(qMax(columnWidths.count(), colsInRow)); | - |
907 | rowColSpanForColumn.resize(columnWidths.size()); | - |
908 | for (int i = currentColumn; i < currentColumn + c.tableCellColSpan; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
909 | if (columnWidths.at(i).type() == QTextLength::VariableLength) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
910 | QTextLength w = c.width; | - |
911 | if (c.tableCellColSpan > 1 && w.type() != QTextLength::VariableLength)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
912 | w = QTextLength(w.type(), w.value(100.) / c.tableCellColSpan); never executed: w = QTextLength(w.type(), w.value(100.) / c.tableCellColSpan); | 0 |
913 | columnWidths[i] = w; | - |
914 | } never executed: end of block | 0 |
915 | rowColSpanForColumn[i] = spanInfo; | - |
916 | } never executed: end of block | 0 |
917 | } never executed: end of block | 0 |
918 | } never executed: end of block | 0 |
919 | | - |
920 | table.columns = qMax(table.columns, colsInRow); | - |
921 | | - |
922 | ++effectiveRow; | - |
923 | } never executed: end of block | 0 |
924 | table.rows = effectiveRow; | - |
925 | | - |
926 | table.lastIndent = indent; | - |
927 | indent = 0; | - |
928 | | - |
929 | if (table.rows == 0 || table.columns == 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
930 | return table; never executed: return table; | 0 |
931 | | - |
932 | QTextFrameFormat fmt; | - |
933 | const QTextHtmlParserNode &node = at(tableNodeIdx); | - |
934 | | - |
935 | if (!node.isTextFrame) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
936 | QTextTableFormat tableFmt; | - |
937 | tableFmt.setCellSpacing(node.tableCellSpacing); | - |
938 | tableFmt.setCellPadding(node.tableCellPadding); | - |
939 | if (node.blockFormat.hasProperty(QTextFormat::BlockAlignment))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
940 | tableFmt.setAlignment(node.blockFormat.alignment()); never executed: tableFmt.setAlignment(node.blockFormat.alignment()); | 0 |
941 | tableFmt.setColumns(table.columns); | - |
942 | tableFmt.setColumnWidthConstraints(columnWidths); | - |
943 | tableFmt.setHeaderRowCount(tableHeaderRowCount); | - |
944 | fmt = tableFmt; | - |
945 | } never executed: end of block | 0 |
946 | | - |
947 | fmt.setTopMargin(topMargin(tableNodeIdx)); | - |
948 | fmt.setBottomMargin(bottomMargin(tableNodeIdx)); | - |
949 | fmt.setLeftMargin(leftMargin(tableNodeIdx) | - |
950 | + table.lastIndent * 40 | - |
951 | ); | - |
952 | fmt.setRightMargin(rightMargin(tableNodeIdx)); | - |
953 | | - |
954 | | - |
955 | if (qFuzzyCompare(fmt.leftMargin(), fmt.rightMargin())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
956 | && qFuzzyCompare(fmt.leftMargin(), fmt.topMargin())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
957 | && qFuzzyCompare(fmt.leftMargin(), fmt.bottomMargin()))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
958 | fmt.setProperty(QTextFormat::FrameMargin, fmt.leftMargin()); never executed: fmt.setProperty(QTextFormat::FrameMargin, fmt.leftMargin()); | 0 |
959 | | - |
960 | fmt.setBorderStyle(node.borderStyle); | - |
961 | fmt.setBorderBrush(node.borderBrush); | - |
962 | fmt.setBorder(node.tableBorder); | - |
963 | fmt.setWidth(node.width); | - |
964 | fmt.setHeight(node.height); | - |
965 | if (node.blockFormat.hasProperty(QTextFormat::PageBreakPolicy))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
966 | fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy()); never executed: fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy()); | 0 |
967 | | - |
968 | if (node.blockFormat.hasProperty(QTextFormat::LayoutDirection))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
969 | fmt.setLayoutDirection(node.blockFormat.layoutDirection()); never executed: fmt.setLayoutDirection(node.blockFormat.layoutDirection()); | 0 |
970 | if (node.charFormat.background().style() != Qt::NoBrush)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
971 | fmt.setBackground(node.charFormat.background()); never executed: fmt.setBackground(node.charFormat.background()); | 0 |
972 | fmt.setPosition(QTextFrameFormat::Position(node.cssFloat)); | - |
973 | | - |
974 | if (node.isTextFrame) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
975 | if (node.isRootFrame) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
976 | table.frame = cursor.currentFrame(); | - |
977 | table.frame->setFrameFormat(fmt); | - |
978 | } else never executed: end of block | 0 |
979 | table.frame = cursor.insertFrame(fmt); never executed: table.frame = cursor.insertFrame(fmt); | 0 |
980 | | - |
981 | table.isTextFrame = true; | - |
982 | } else { never executed: end of block | 0 |
983 | const int oldPos = cursor.position(); | - |
984 | QTextTable *textTable = cursor.insertTable(table.rows, table.columns, fmt.toTableFormat()); | - |
985 | table.frame = textTable; | - |
986 | | - |
987 | for (int i = 0; i < rowColSpans.count(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
988 | const RowColSpanInfo &nfo = rowColSpans.at(i); | - |
989 | textTable->mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan); | - |
990 | } never executed: end of block | 0 |
991 | | - |
992 | table.currentCell = TableCellIterator(textTable); | - |
993 | cursor.setPosition(oldPos); | - |
994 | } never executed: end of block | 0 |
995 | return table; never executed: return table; | 0 |
996 | } | - |
997 | | - |
998 | QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() | - |
999 | { | - |
1000 | QTextBlockFormat block; | - |
1001 | QTextCharFormat charFmt; | - |
1002 | bool modifiedBlockFormat = true; | - |
1003 | bool modifiedCharFormat = true; | - |
1004 | | - |
1005 | if (currentNode->isTableCell() && !tables.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1006 | Table &t = tables.last(); | - |
1007 | if (!t.isTextFrame && !t.currentCell.atEnd()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1008 | QTextTableCell cell = t.currentCell.cell(); | - |
1009 | if (cell.isValid()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1010 | QTextTableCellFormat fmt = cell.format().toTableCellFormat(); | - |
1011 | if (topPadding(currentNodeIdx) >= 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1012 | fmt.setTopPadding(topPadding(currentNodeIdx)); never executed: fmt.setTopPadding(topPadding(currentNodeIdx)); | 0 |
1013 | if (bottomPadding(currentNodeIdx) >= 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1014 | fmt.setBottomPadding(bottomPadding(currentNodeIdx)); never executed: fmt.setBottomPadding(bottomPadding(currentNodeIdx)); | 0 |
1015 | if (leftPadding(currentNodeIdx) >= 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1016 | fmt.setLeftPadding(leftPadding(currentNodeIdx)); never executed: fmt.setLeftPadding(leftPadding(currentNodeIdx)); | 0 |
1017 | if (rightPadding(currentNodeIdx) >= 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1018 | fmt.setRightPadding(rightPadding(currentNodeIdx)); never executed: fmt.setRightPadding(rightPadding(currentNodeIdx)); | 0 |
1019 | cell.setFormat(fmt); | - |
1020 | | - |
1021 | cursor.setPosition(cell.firstPosition()); | - |
1022 | } never executed: end of block | 0 |
1023 | } never executed: end of block | 0 |
1024 | hasBlock = true; | - |
1025 | compressNextWhitespace = RemoveWhiteSpace; | - |
1026 | | - |
1027 | if (currentNode->charFormat.background().style() != Qt::NoBrush) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1028 | charFmt.setBackground(currentNode->charFormat.background()); | - |
1029 | cursor.mergeBlockCharFormat(charFmt); | - |
1030 | } never executed: end of block | 0 |
1031 | } never executed: end of block | 0 |
1032 | | - |
1033 | if (hasBlock) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1034 | block = cursor.blockFormat(); | - |
1035 | charFmt = cursor.blockCharFormat(); | - |
1036 | modifiedBlockFormat = false; | - |
1037 | modifiedCharFormat = false; | - |
1038 | } never executed: end of block | 0 |
1039 | | - |
1040 | | - |
1041 | { | - |
1042 | qreal tm = qreal(topMargin(currentNodeIdx)); | - |
1043 | if (tm > block.topMargin()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1044 | block.setTopMargin(tm); | - |
1045 | modifiedBlockFormat = true; | - |
1046 | } never executed: end of block | 0 |
1047 | } | - |
1048 | | - |
1049 | int bottomMargin = this->bottomMargin(currentNodeIdx); | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | const QTextHtmlParserNode *parentNode = currentNode->parent ? &at(currentNode->parent) : 0;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1054 | if ((currentNode->id == Html_li || currentNode->id == Html_dt || currentNode->id == Html_dd)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1055 | && parentNodeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1056 | && (parentNode->isListStart() || parentNode->id == Html_dl)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1057 | && (parentNode->children.last() == currentNodeIdx)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1058 | bottomMargin = qMax(bottomMargin, this->bottomMargin(currentNode->parent)); | - |
1059 | } never executed: end of block | 0 |
1060 | | - |
1061 | if (block.bottomMargin() != bottomMargin) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1062 | block.setBottomMargin(bottomMargin); | - |
1063 | modifiedBlockFormat = true; | - |
1064 | } never executed: end of block | 0 |
1065 | | - |
1066 | { | - |
1067 | const qreal lm = leftMargin(currentNodeIdx); | - |
1068 | const qreal rm = rightMargin(currentNodeIdx); | - |
1069 | | - |
1070 | if (block.leftMargin() != lm) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1071 | block.setLeftMargin(lm); | - |
1072 | modifiedBlockFormat = true; | - |
1073 | } never executed: end of block | 0 |
1074 | if (block.rightMargin() != rm) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1075 | block.setRightMargin(rm); | - |
1076 | modifiedBlockFormat = true; | - |
1077 | } never executed: end of block | 0 |
1078 | } | - |
1079 | | - |
1080 | if (currentNode->id != Html_liTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1081 | && indent != 0TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1082 | && (lists.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1083 | || !hasBlockTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1084 | || !lists.lastconstLast().listTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1085 | || lists.lastconstLast().list->itemNumber(cursor.block()) == -1TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1086 | ) | - |
1087 | ) { | - |
1088 | block.setIndent(indent); | - |
1089 | modifiedBlockFormat = true; | - |
1090 | } never executed: end of block | 0 |
1091 | | - |
1092 | if (currentNode->blockFormat.propertyCount() > 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1093 | modifiedBlockFormat = true; | - |
1094 | block.merge(currentNode->blockFormat); | - |
1095 | } never executed: end of block | 0 |
1096 | | - |
1097 | if (currentNode->charFormat.propertyCount() > 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1098 | modifiedCharFormat = true; | - |
1099 | charFmt.merge(currentNode->charFormat); | - |
1100 | } never executed: end of block | 0 |
1101 | | - |
1102 | | - |
1103 | | - |
1104 | | - |
1105 | if (wsm == QTextHtmlParserNode::WhiteSpacePre) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1106 | block.setNonBreakableLines(true); | - |
1107 | modifiedBlockFormat = true; | - |
1108 | } never executed: end of block | 0 |
1109 | | - |
1110 | if (currentNode->charFormat.background().style() != Qt::NoBrush && !currentNode->isTableCell()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1111 | block.setBackground(currentNode->charFormat.background()); | - |
1112 | modifiedBlockFormat = true; | - |
1113 | } never executed: end of block | 0 |
1114 | | - |
1115 | if (hasBlock && (!currentNode->isEmptyParagraph || forceBlockMerging)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1116 | if (modifiedBlockFormat)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1117 | cursor.setBlockFormat(block); never executed: cursor.setBlockFormat(block); | 0 |
1118 | if (modifiedCharFormat)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1119 | cursor.setBlockCharFormat(charFmt); never executed: cursor.setBlockCharFormat(charFmt); | 0 |
1120 | } else { never executed: end of block | 0 |
1121 | if (currentNodeIdx == 1 && cursor.position() == 0 && currentNode->isEmptyParagraph) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1122 | cursor.setBlockFormat(block); | - |
1123 | cursor.setBlockCharFormat(charFmt); | - |
1124 | } else { never executed: end of block | 0 |
1125 | appendBlock(block, charFmt); | - |
1126 | } never executed: end of block | 0 |
1127 | } | - |
1128 | | - |
1129 | if (currentNode->userState != -1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1130 | cursor.block().setUserState(currentNode->userState); never executed: cursor.block().setUserState(currentNode->userState); | 0 |
1131 | | - |
1132 | if (currentNode->id == Html_li && !lists.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1133 | List &l = lists.last(); | - |
1134 | if (l.list) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1135 | l.list->add(cursor.block()); | - |
1136 | } else { never executed: end of block | 0 |
1137 | l.list = cursor.createList(l.format); | - |
1138 | const qreal listTopMargin = topMargin(l.listNode); | - |
1139 | if (listTopMargin > block.topMargin()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1140 | block.setTopMargin(listTopMargin); | - |
1141 | cursor.mergeBlockFormat(block); | - |
1142 | } never executed: end of block | 0 |
1143 | } never executed: end of block | 0 |
1144 | if (hasBlock) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1145 | QTextBlockFormat fmt; | - |
1146 | fmt.setIndent(currentNode->blockFormat.indent()); | - |
1147 | cursor.mergeBlockFormat(fmt); | - |
1148 | } never executed: end of block | 0 |
1149 | } never executed: end of block | 0 |
1150 | | - |
1151 | forceBlockMerging = false; | - |
1152 | if (currentNode->id == Html_body || currentNode->id == Html_html)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1153 | forceBlockMerging = true; never executed: forceBlockMerging = true; | 0 |
1154 | | - |
1155 | if (currentNode->isEmptyParagraph) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1156 | hasBlock = false; | - |
1157 | return ContinueWithNextSibling; never executed: return ContinueWithNextSibling; | 0 |
1158 | } | - |
1159 | | - |
1160 | hasBlock = true; | - |
1161 | blockTagClosed = false; | - |
1162 | return ContinueWithCurrentNode; never executed: return ContinueWithCurrentNode; | 0 |
1163 | } | - |
1164 | | - |
1165 | void QTextHtmlImporter::appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt) | - |
1166 | { | - |
1167 | if (!namedAnchors.isEmpty()) { | - |
1168 | charFmt.setAnchor(true); | - |
1169 | charFmt.setAnchorNames(namedAnchors); | - |
1170 | namedAnchors.clear(); | - |
1171 | } | - |
1172 | | - |
1173 | cursor.insertBlock(format, charFmt); | - |
1174 | | - |
1175 | if (wsm != QTextHtmlParserNode::WhiteSpacePre && wsm != QTextHtmlParserNode::WhiteSpacePreWrap) | - |
1176 | compressNextWhitespace = RemoveWhiteSpace; | - |
1177 | } | - |
1178 | | - |
1179 | #endif // QT_NO_TEXTHTMLPARSER | - |
1180 | | - |
1181 | | - |
1182 | | - |
1183 | | - |
1184 | | - |
1185 | | - |
1186 | | - |
1187 | | - |
1188 | | - |
1189 | | - |
1190 | #ifndef QT_NO_TEXTHTMLPARSER | - |
1191 | | - |
1192 | QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &html) | - |
1193 | { | - |
1194 | return fromHtml(html, 0); | - |
1195 | } | - |
1196 | | - |
1197 | | - |
1198 | | - |
1199 | | - |
1200 | | - |
1201 | | - |
1202 | | - |
1203 | | - |
1204 | | - |
1205 | | - |
1206 | | - |
1207 | | - |
1208 | | - |
1209 | | - |
1210 | QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &html, const QTextDocument *resourceProvider) | - |
1211 | { | - |
1212 | QTextDocumentFragment res; | - |
1213 | res.d = new QTextDocumentFragmentPrivate; | - |
1214 | | - |
1215 | QTextHtmlImporter importer(res.d->doc, html, QTextHtmlImporter::ImportToFragment, resourceProvider); | - |
1216 | importer.import(); | - |
1217 | return res; | - |
1218 | } | - |
1219 | | - |
1220 | QT_END_NAMESPACE | - |
1221 | #endif // QT_NO_TEXTHTMLPARSER | - |
| | |