Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocument.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | __attribute__((visibility("default"))) unsigned int qt_int_sqrt(unsigned int n); | - | ||||||||||||
9 | bool Qt::mightBeRichText(const QString& text) | - | ||||||||||||
10 | { | - | ||||||||||||
11 | if (text.isEmpty()) | - | ||||||||||||
12 | return false; | - | ||||||||||||
13 | int start = 0; | - | ||||||||||||
14 | - | |||||||||||||
15 | while (start < text.length() && text.at(start).isSpace()) | - | ||||||||||||
16 | ++start; | - | ||||||||||||
17 | - | |||||||||||||
18 | - | |||||||||||||
19 | if (text.mid(start, 5) == QLatin1String("<?xml")) { | - | ||||||||||||
20 | while (start < text.length()) { | - | ||||||||||||
21 | if (text.at(start) == QLatin1Char('?') | - | ||||||||||||
22 | && start + 2 < text.length() | - | ||||||||||||
23 | && text.at(start + 1) == QLatin1Char('>')) { | - | ||||||||||||
24 | start += 2; | - | ||||||||||||
25 | break; | - | ||||||||||||
26 | } | - | ||||||||||||
27 | ++start; | - | ||||||||||||
28 | } | - | ||||||||||||
29 | - | |||||||||||||
30 | while (start < text.length() && text.at(start).isSpace()) | - | ||||||||||||
31 | ++start; | - | ||||||||||||
32 | } | - | ||||||||||||
33 | - | |||||||||||||
34 | if (text.mid(start, 5).toLower() == QLatin1String("<!doc")) | - | ||||||||||||
35 | return true; | - | ||||||||||||
36 | int open = start; | - | ||||||||||||
37 | while (open < text.length() && text.at(open) != QLatin1Char('<') | - | ||||||||||||
38 | && text.at(open) != QLatin1Char('\n')) { | - | ||||||||||||
39 | if (text.at(open) == QLatin1Char('&') && text.mid(open+1,3) == QLatin1String("lt;")) | - | ||||||||||||
40 | return true; | - | ||||||||||||
41 | ++open; | - | ||||||||||||
42 | } | - | ||||||||||||
43 | if (open < text.length() && text.at(open) == QLatin1Char('<')) { | - | ||||||||||||
44 | const int close = text.indexOf(QLatin1Char('>'), open); | - | ||||||||||||
45 | if (close > -1) { | - | ||||||||||||
46 | QString tag; | - | ||||||||||||
47 | for (int i = open+1; i < close; ++i) { | - | ||||||||||||
48 | if (text[i].isDigit() || text[i].isLetter()) | - | ||||||||||||
49 | tag += text[i]; | - | ||||||||||||
50 | else if (!tag.isEmpty() && text[i].isSpace()) | - | ||||||||||||
51 | break; | - | ||||||||||||
52 | else if (!tag.isEmpty() && text[i] == QLatin1Char('/') && i + 1 == close) | - | ||||||||||||
53 | break; | - | ||||||||||||
54 | else if (!text[i].isSpace() && (!tag.isEmpty() || text[i] != QLatin1Char('!'))) | - | ||||||||||||
55 | return false; | - | ||||||||||||
56 | } | - | ||||||||||||
57 | - | |||||||||||||
58 | return QTextHtmlParser::lookupElement(tag.toLower()) != -1; | - | ||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | - | |||||||||||||
62 | } | - | ||||||||||||
63 | } | - | ||||||||||||
64 | return false; | - | ||||||||||||
65 | } | - | ||||||||||||
66 | QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) | - | ||||||||||||
67 | { | - | ||||||||||||
68 | int col = 0; | - | ||||||||||||
69 | QString rich; | - | ||||||||||||
70 | rich += QLatin1String("<p>"); | - | ||||||||||||
71 | for (int i = 0; i < plain.length(); ++i) { | - | ||||||||||||
72 | if (plain[i] == QLatin1Char('\n')){ | - | ||||||||||||
73 | int c = 1; | - | ||||||||||||
74 | while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) { | - | ||||||||||||
75 | i++; | - | ||||||||||||
76 | c++; | - | ||||||||||||
77 | } | - | ||||||||||||
78 | if (c == 1) | - | ||||||||||||
79 | rich += QLatin1String("<br>\n"); | - | ||||||||||||
80 | else { | - | ||||||||||||
81 | rich += QLatin1String("</p>\n"); | - | ||||||||||||
82 | while (--c > 1) | - | ||||||||||||
83 | rich += QLatin1String("<br>\n"); | - | ||||||||||||
84 | rich += QLatin1String("<p>"); | - | ||||||||||||
85 | } | - | ||||||||||||
86 | col = 0; | - | ||||||||||||
87 | } else { | - | ||||||||||||
88 | if (mode == Qt::WhiteSpacePre && plain[i] == QLatin1Char('\t')){ | - | ||||||||||||
89 | rich += QChar(0x00a0U); | - | ||||||||||||
90 | ++col; | - | ||||||||||||
91 | while (col % 8) { | - | ||||||||||||
92 | rich += QChar(0x00a0U); | - | ||||||||||||
93 | ++col; | - | ||||||||||||
94 | } | - | ||||||||||||
95 | } | - | ||||||||||||
96 | else if (mode == Qt::WhiteSpacePre && plain[i].isSpace()) | - | ||||||||||||
97 | rich += QChar(0x00a0U); | - | ||||||||||||
98 | else if (plain[i] == QLatin1Char('<')) | - | ||||||||||||
99 | rich += QLatin1String("<"); | - | ||||||||||||
100 | else if (plain[i] == QLatin1Char('>')) | - | ||||||||||||
101 | rich += QLatin1String(">"); | - | ||||||||||||
102 | else if (plain[i] == QLatin1Char('&')) | - | ||||||||||||
103 | rich += QLatin1String("&"); | - | ||||||||||||
104 | else | - | ||||||||||||
105 | rich += plain[i]; | - | ||||||||||||
106 | ++col; | - | ||||||||||||
107 | } | - | ||||||||||||
108 | } | - | ||||||||||||
109 | if (col != 0) | - | ||||||||||||
110 | rich += QLatin1String("</p>"); | - | ||||||||||||
111 | return rich; | - | ||||||||||||
112 | } | - | ||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | - | |||||||||||||
119 | - | |||||||||||||
120 | QTextCodec *Qt::codecForHtml(const QByteArray &ba) | - | ||||||||||||
121 | { | - | ||||||||||||
122 | return QTextCodec::codecForHtml(ba); | - | ||||||||||||
123 | } | - | ||||||||||||
124 | QTextDocument::QTextDocument(QObject *parent) | - | ||||||||||||
125 | : QObject(*new QTextDocumentPrivate, parent) | - | ||||||||||||
126 | { | - | ||||||||||||
127 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
128 | d->init(); | - | ||||||||||||
129 | } | - | ||||||||||||
130 | - | |||||||||||||
131 | - | |||||||||||||
132 | - | |||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | QTextDocument::QTextDocument(const QString &text, QObject *parent) | - | ||||||||||||
136 | : QObject(*new QTextDocumentPrivate, parent) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
139 | d->init(); | - | ||||||||||||
140 | QTextCursor(this).insertText(text); | - | ||||||||||||
141 | } | - | ||||||||||||
142 | - | |||||||||||||
143 | - | |||||||||||||
144 | - | |||||||||||||
145 | - | |||||||||||||
146 | QTextDocument::QTextDocument(QTextDocumentPrivate &dd, QObject *parent) | - | ||||||||||||
147 | : QObject(dd, parent) | - | ||||||||||||
148 | { | - | ||||||||||||
149 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
150 | d->init(); | - | ||||||||||||
151 | } | - | ||||||||||||
152 | - | |||||||||||||
153 | - | |||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | QTextDocument::~QTextDocument() | - | ||||||||||||
157 | { | - | ||||||||||||
158 | } | - | ||||||||||||
159 | - | |||||||||||||
160 | - | |||||||||||||
161 | - | |||||||||||||
162 | - | |||||||||||||
163 | - | |||||||||||||
164 | - | |||||||||||||
165 | QTextDocument *QTextDocument::clone(QObject *parent) const | - | ||||||||||||
166 | { | - | ||||||||||||
167 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
168 | QTextDocument *doc = new QTextDocument(parent); | - | ||||||||||||
169 | QTextCursor(doc).insertFragment(QTextDocumentFragment(this)); | - | ||||||||||||
170 | doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat()); | - | ||||||||||||
171 | QTextDocumentPrivate *priv = doc->d_func(); | - | ||||||||||||
172 | priv->title = d->title; | - | ||||||||||||
173 | priv->url = d->url; | - | ||||||||||||
174 | priv->pageSize = d->pageSize; | - | ||||||||||||
175 | priv->indentWidth = d->indentWidth; | - | ||||||||||||
176 | priv->defaultTextOption = d->defaultTextOption; | - | ||||||||||||
177 | priv->setDefaultFont(d->defaultFont()); | - | ||||||||||||
178 | priv->resources = d->resources; | - | ||||||||||||
179 | priv->cachedResources.clear(); | - | ||||||||||||
180 | - | |||||||||||||
181 | priv->defaultStyleSheet = d->defaultStyleSheet; | - | ||||||||||||
182 | priv->parsedDefaultStyleSheet = d->parsedDefaultStyleSheet; | - | ||||||||||||
183 | - | |||||||||||||
184 | return doc; | - | ||||||||||||
185 | } | - | ||||||||||||
186 | - | |||||||||||||
187 | - | |||||||||||||
188 | - | |||||||||||||
189 | - | |||||||||||||
190 | bool QTextDocument::isEmpty() const | - | ||||||||||||
191 | { | - | ||||||||||||
192 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
193 | - | |||||||||||||
194 | - | |||||||||||||
195 | return d->length() <= 1; | - | ||||||||||||
196 | } | - | ||||||||||||
197 | - | |||||||||||||
198 | - | |||||||||||||
199 | - | |||||||||||||
200 | - | |||||||||||||
201 | void QTextDocument::clear() | - | ||||||||||||
202 | { | - | ||||||||||||
203 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
204 | d->clear(); | - | ||||||||||||
205 | d->resources.clear(); | - | ||||||||||||
206 | } | - | ||||||||||||
207 | void QTextDocument::undo(QTextCursor *cursor) | - | ||||||||||||
208 | { | - | ||||||||||||
209 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
210 | const int pos = d->undoRedo(true); | - | ||||||||||||
211 | if (cursor && pos >= 0) { | - | ||||||||||||
212 | *cursor = QTextCursor(this); | - | ||||||||||||
213 | cursor->setPosition(pos); | - | ||||||||||||
214 | } | - | ||||||||||||
215 | } | - | ||||||||||||
216 | void QTextDocument::redo(QTextCursor *cursor) | - | ||||||||||||
217 | { | - | ||||||||||||
218 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
219 | const int pos = d->undoRedo(false); | - | ||||||||||||
220 | if (cursor && pos >= 0) { | - | ||||||||||||
221 | *cursor = QTextCursor(this); | - | ||||||||||||
222 | cursor->setPosition(pos); | - | ||||||||||||
223 | } | - | ||||||||||||
224 | } | - | ||||||||||||
225 | void QTextDocument::clearUndoRedoStacks(Stacks stacksToClear) | - | ||||||||||||
226 | { | - | ||||||||||||
227 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
228 | d->clearUndoRedoStacks(stacksToClear, true); | - | ||||||||||||
229 | } | - | ||||||||||||
230 | - | |||||||||||||
231 | - | |||||||||||||
232 | - | |||||||||||||
233 | - | |||||||||||||
234 | - | |||||||||||||
235 | void QTextDocument::undo() | - | ||||||||||||
236 | { | - | ||||||||||||
237 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
238 | d->undoRedo(true); | - | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | - | |||||||||||||
242 | - | |||||||||||||
243 | - | |||||||||||||
244 | - | |||||||||||||
245 | void QTextDocument::redo() | - | ||||||||||||
246 | { | - | ||||||||||||
247 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
248 | d->undoRedo(false); | - | ||||||||||||
249 | } | - | ||||||||||||
250 | - | |||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
253 | - | |||||||||||||
254 | - | |||||||||||||
255 | - | |||||||||||||
256 | void QTextDocument::appendUndoItem(QAbstractUndoItem *item) | - | ||||||||||||
257 | { | - | ||||||||||||
258 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
259 | d->appendUndoItem(item); | - | ||||||||||||
260 | } | - | ||||||||||||
261 | void QTextDocument::setUndoRedoEnabled(bool enable) | - | ||||||||||||
262 | { | - | ||||||||||||
263 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
264 | d->enableUndoRedo(enable); | - | ||||||||||||
265 | } | - | ||||||||||||
266 | - | |||||||||||||
267 | bool QTextDocument::isUndoRedoEnabled() const | - | ||||||||||||
268 | { | - | ||||||||||||
269 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
270 | return d->isUndoRedoEnabled(); | - | ||||||||||||
271 | } | - | ||||||||||||
272 | int QTextDocument::maximumBlockCount() const | - | ||||||||||||
273 | { | - | ||||||||||||
274 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
275 | return d->maximumBlockCount; | - | ||||||||||||
276 | } | - | ||||||||||||
277 | - | |||||||||||||
278 | void QTextDocument::setMaximumBlockCount(int maximum) | - | ||||||||||||
279 | { | - | ||||||||||||
280 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
281 | d->maximumBlockCount = maximum; | - | ||||||||||||
282 | d->ensureMaximumBlockCount(); | - | ||||||||||||
283 | setUndoRedoEnabled(false); | - | ||||||||||||
284 | } | - | ||||||||||||
285 | QTextOption QTextDocument::defaultTextOption() const | - | ||||||||||||
286 | { | - | ||||||||||||
287 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
288 | return d->defaultTextOption; | - | ||||||||||||
289 | } | - | ||||||||||||
290 | - | |||||||||||||
291 | - | |||||||||||||
292 | - | |||||||||||||
293 | - | |||||||||||||
294 | - | |||||||||||||
295 | - | |||||||||||||
296 | void QTextDocument::setDefaultTextOption(const QTextOption &option) | - | ||||||||||||
297 | { | - | ||||||||||||
298 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
299 | d->defaultTextOption = option; | - | ||||||||||||
300 | if (d->lout) | - | ||||||||||||
301 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
302 | } | - | ||||||||||||
303 | QUrl QTextDocument::baseUrl() const | - | ||||||||||||
304 | { | - | ||||||||||||
305 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
306 | return d->baseUrl; | - | ||||||||||||
307 | } | - | ||||||||||||
308 | - | |||||||||||||
309 | void QTextDocument::setBaseUrl(const QUrl &url) | - | ||||||||||||
310 | { | - | ||||||||||||
311 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
312 | if (d->baseUrl != url) { | - | ||||||||||||
313 | d->baseUrl = url; | - | ||||||||||||
314 | if (d->lout) | - | ||||||||||||
315 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
316 | baseUrlChanged(url); | - | ||||||||||||
317 | } | - | ||||||||||||
318 | } | - | ||||||||||||
319 | - | |||||||||||||
320 | - | |||||||||||||
321 | - | |||||||||||||
322 | - | |||||||||||||
323 | - | |||||||||||||
324 | - | |||||||||||||
325 | - | |||||||||||||
326 | Qt::CursorMoveStyle QTextDocument::defaultCursorMoveStyle() const | - | ||||||||||||
327 | { | - | ||||||||||||
328 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
329 | return d->defaultCursorMoveStyle; | - | ||||||||||||
330 | } | - | ||||||||||||
331 | - | |||||||||||||
332 | - | |||||||||||||
333 | - | |||||||||||||
334 | - | |||||||||||||
335 | - | |||||||||||||
336 | - | |||||||||||||
337 | void QTextDocument::setDefaultCursorMoveStyle(Qt::CursorMoveStyle style) | - | ||||||||||||
338 | { | - | ||||||||||||
339 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
340 | d->defaultCursorMoveStyle = style; | - | ||||||||||||
341 | } | - | ||||||||||||
342 | void QTextDocument::markContentsDirty(int from, int length) | - | ||||||||||||
343 | { | - | ||||||||||||
344 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
345 | d->documentChange(from, length); | - | ||||||||||||
346 | if (!d->inContentsChange) { | - | ||||||||||||
347 | if (d->lout) { | - | ||||||||||||
348 | d->lout->documentChanged(d->docChangeFrom, d->docChangeOldLength, d->docChangeLength); | - | ||||||||||||
349 | d->docChangeFrom = -1; | - | ||||||||||||
350 | } | - | ||||||||||||
351 | } | - | ||||||||||||
352 | } | - | ||||||||||||
353 | void QTextDocument::setUseDesignMetrics(bool b) | - | ||||||||||||
354 | { | - | ||||||||||||
355 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
356 | if (b == d->defaultTextOption.useDesignMetrics()) | - | ||||||||||||
357 | return; | - | ||||||||||||
358 | d->defaultTextOption.setUseDesignMetrics(b); | - | ||||||||||||
359 | if (d->lout) | - | ||||||||||||
360 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
361 | } | - | ||||||||||||
362 | - | |||||||||||||
363 | bool QTextDocument::useDesignMetrics() const | - | ||||||||||||
364 | { | - | ||||||||||||
365 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
366 | return d->defaultTextOption.useDesignMetrics(); | - | ||||||||||||
367 | } | - | ||||||||||||
368 | - | |||||||||||||
369 | - | |||||||||||||
370 | - | |||||||||||||
371 | - | |||||||||||||
372 | - | |||||||||||||
373 | - | |||||||||||||
374 | - | |||||||||||||
375 | void QTextDocument::drawContents(QPainter *p, const QRectF &rect) | - | ||||||||||||
376 | { | - | ||||||||||||
377 | p->save(); | - | ||||||||||||
378 | QAbstractTextDocumentLayout::PaintContext ctx; | - | ||||||||||||
379 | if (rect.isValid()) { | - | ||||||||||||
380 | p->setClipRect(rect); | - | ||||||||||||
381 | ctx.clip = rect; | - | ||||||||||||
382 | } | - | ||||||||||||
383 | documentLayout()->draw(p, ctx); | - | ||||||||||||
384 | p->restore(); | - | ||||||||||||
385 | } | - | ||||||||||||
386 | void QTextDocument::setTextWidth(qreal width) | - | ||||||||||||
387 | { | - | ||||||||||||
388 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
389 | QSizeF sz = d->pageSize; | - | ||||||||||||
390 | sz.setWidth(width); | - | ||||||||||||
391 | sz.setHeight(-1); | - | ||||||||||||
392 | setPageSize(sz); | - | ||||||||||||
393 | } | - | ||||||||||||
394 | - | |||||||||||||
395 | qreal QTextDocument::textWidth() const | - | ||||||||||||
396 | { | - | ||||||||||||
397 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
398 | return d->pageSize.width(); | - | ||||||||||||
399 | } | - | ||||||||||||
400 | qreal QTextDocument::idealWidth() const | - | ||||||||||||
401 | { | - | ||||||||||||
402 | if (QTextDocumentLayout *lout = qobject_cast<QTextDocumentLayout *>(documentLayout())) | - | ||||||||||||
403 | return lout->idealWidth(); | - | ||||||||||||
404 | return textWidth(); | - | ||||||||||||
405 | } | - | ||||||||||||
406 | - | |||||||||||||
407 | - | |||||||||||||
408 | - | |||||||||||||
409 | - | |||||||||||||
410 | - | |||||||||||||
411 | - | |||||||||||||
412 | - | |||||||||||||
413 | qreal QTextDocument::documentMargin() const | - | ||||||||||||
414 | { | - | ||||||||||||
415 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
416 | return d->documentMargin; | - | ||||||||||||
417 | } | - | ||||||||||||
418 | - | |||||||||||||
419 | void QTextDocument::setDocumentMargin(qreal margin) | - | ||||||||||||
420 | { | - | ||||||||||||
421 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
422 | if (d->documentMargin != margin) { | - | ||||||||||||
423 | d->documentMargin = margin; | - | ||||||||||||
424 | - | |||||||||||||
425 | QTextFrame* root = rootFrame(); | - | ||||||||||||
426 | QTextFrameFormat format = root->frameFormat(); | - | ||||||||||||
427 | format.setMargin(margin); | - | ||||||||||||
428 | root->setFrameFormat(format); | - | ||||||||||||
429 | - | |||||||||||||
430 | if (d->lout) | - | ||||||||||||
431 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
432 | } | - | ||||||||||||
433 | } | - | ||||||||||||
434 | qreal QTextDocument::indentWidth() const | - | ||||||||||||
435 | { | - | ||||||||||||
436 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
437 | return d->indentWidth; | - | ||||||||||||
438 | } | - | ||||||||||||
439 | void QTextDocument::setIndentWidth(qreal width) | - | ||||||||||||
440 | { | - | ||||||||||||
441 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
442 | if (d->indentWidth != width) { | - | ||||||||||||
443 | d->indentWidth = width; | - | ||||||||||||
444 | if (d->lout) | - | ||||||||||||
445 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
446 | } | - | ||||||||||||
447 | } | - | ||||||||||||
448 | void QTextDocument::adjustSize() | - | ||||||||||||
449 | { | - | ||||||||||||
450 | - | |||||||||||||
451 | QFont f = defaultFont(); | - | ||||||||||||
452 | QFontMetrics fm(f); | - | ||||||||||||
453 | int mw = fm.width(QLatin1Char('x')) * 80; | - | ||||||||||||
454 | int w = mw; | - | ||||||||||||
455 | setTextWidth(w); | - | ||||||||||||
456 | QSizeF size = documentLayout()->documentSize(); | - | ||||||||||||
457 | if (size.width() != 0) { | - | ||||||||||||
458 | w = qt_int_sqrt((uint)(5 * size.height() * size.width() / 3)); | - | ||||||||||||
459 | setTextWidth(qMin(w, mw)); | - | ||||||||||||
460 | - | |||||||||||||
461 | size = documentLayout()->documentSize(); | - | ||||||||||||
462 | if (w*3 < 5*size.height()) { | - | ||||||||||||
463 | w = qt_int_sqrt((uint)(2 * size.height() * size.width())); | - | ||||||||||||
464 | setTextWidth(qMin(w, mw)); | - | ||||||||||||
465 | } | - | ||||||||||||
466 | } | - | ||||||||||||
467 | setTextWidth(idealWidth()); | - | ||||||||||||
468 | } | - | ||||||||||||
469 | QSizeF QTextDocument::size() const | - | ||||||||||||
470 | { | - | ||||||||||||
471 | return documentLayout()->documentSize(); | - | ||||||||||||
472 | } | - | ||||||||||||
473 | int QTextDocument::blockCount() const | - | ||||||||||||
474 | { | - | ||||||||||||
475 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
476 | return d->blockMap().numNodes(); | - | ||||||||||||
477 | } | - | ||||||||||||
478 | int QTextDocument::lineCount() const | - | ||||||||||||
479 | { | - | ||||||||||||
480 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
481 | return d->blockMap().length(2); | - | ||||||||||||
482 | } | - | ||||||||||||
483 | int QTextDocument::characterCount() const | - | ||||||||||||
484 | { | - | ||||||||||||
485 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
486 | return d->length(); | - | ||||||||||||
487 | } | - | ||||||||||||
488 | QChar QTextDocument::characterAt(int pos) const | - | ||||||||||||
489 | { | - | ||||||||||||
490 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
491 | if (pos < 0 || pos >= d->length()) | - | ||||||||||||
492 | return QChar(); | - | ||||||||||||
493 | QTextDocumentPrivate::FragmentIterator fragIt = d->find(pos); | - | ||||||||||||
494 | const QTextFragmentData * const frag = fragIt.value(); | - | ||||||||||||
495 | const int offsetInFragment = qMax(0, pos - fragIt.position()); | - | ||||||||||||
496 | return d->text.at(frag->stringPosition + offsetInFragment); | - | ||||||||||||
497 | } | - | ||||||||||||
498 | void QTextDocument::setDefaultStyleSheet(const QString &sheet) | - | ||||||||||||
499 | { | - | ||||||||||||
500 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
501 | d->defaultStyleSheet = sheet; | - | ||||||||||||
502 | QCss::Parser parser(sheet); | - | ||||||||||||
503 | d->parsedDefaultStyleSheet = QCss::StyleSheet(); | - | ||||||||||||
504 | d->parsedDefaultStyleSheet.origin = QCss::StyleSheetOrigin_UserAgent; | - | ||||||||||||
505 | parser.parse(&d->parsedDefaultStyleSheet); | - | ||||||||||||
506 | } | - | ||||||||||||
507 | - | |||||||||||||
508 | QString QTextDocument::defaultStyleSheet() const | - | ||||||||||||
509 | { | - | ||||||||||||
510 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
511 | return d->defaultStyleSheet; | - | ||||||||||||
512 | } | - | ||||||||||||
513 | bool QTextDocument::isUndoAvailable() const | - | ||||||||||||
514 | { | - | ||||||||||||
515 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
516 | return d->isUndoAvailable(); | - | ||||||||||||
517 | } | - | ||||||||||||
518 | - | |||||||||||||
519 | - | |||||||||||||
520 | - | |||||||||||||
521 | - | |||||||||||||
522 | - | |||||||||||||
523 | - | |||||||||||||
524 | bool QTextDocument::isRedoAvailable() const | - | ||||||||||||
525 | { | - | ||||||||||||
526 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
527 | return d->isRedoAvailable(); | - | ||||||||||||
528 | } | - | ||||||||||||
529 | - | |||||||||||||
530 | - | |||||||||||||
531 | - | |||||||||||||
532 | - | |||||||||||||
533 | - | |||||||||||||
534 | - | |||||||||||||
535 | - | |||||||||||||
536 | int QTextDocument::availableUndoSteps() const | - | ||||||||||||
537 | { | - | ||||||||||||
538 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
539 | return d->availableUndoSteps(); | - | ||||||||||||
540 | } | - | ||||||||||||
541 | - | |||||||||||||
542 | - | |||||||||||||
543 | - | |||||||||||||
544 | - | |||||||||||||
545 | - | |||||||||||||
546 | - | |||||||||||||
547 | - | |||||||||||||
548 | int QTextDocument::availableRedoSteps() const | - | ||||||||||||
549 | { | - | ||||||||||||
550 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
551 | return d->availableRedoSteps(); | - | ||||||||||||
552 | } | - | ||||||||||||
553 | int QTextDocument::revision() const | - | ||||||||||||
554 | { | - | ||||||||||||
555 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
556 | return d->revision; | - | ||||||||||||
557 | } | - | ||||||||||||
558 | void QTextDocument::setDocumentLayout(QAbstractTextDocumentLayout *layout) | - | ||||||||||||
559 | { | - | ||||||||||||
560 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
561 | d->setLayout(layout); | - | ||||||||||||
562 | } | - | ||||||||||||
563 | - | |||||||||||||
564 | - | |||||||||||||
565 | - | |||||||||||||
566 | - | |||||||||||||
567 | QAbstractTextDocumentLayout *QTextDocument::documentLayout() const | - | ||||||||||||
568 | { | - | ||||||||||||
569 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
570 | if (!d->lout) { | - | ||||||||||||
571 | QTextDocument *that = const_cast<QTextDocument *>(this); | - | ||||||||||||
572 | that->d_func()->setLayout(new QTextDocumentLayout(that)); | - | ||||||||||||
573 | } | - | ||||||||||||
574 | return d->lout; | - | ||||||||||||
575 | } | - | ||||||||||||
576 | QString QTextDocument::metaInformation(MetaInformation info) const | - | ||||||||||||
577 | { | - | ||||||||||||
578 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
579 | switch (info) { | - | ||||||||||||
580 | case DocumentTitle: | - | ||||||||||||
581 | return d->title; | - | ||||||||||||
582 | case DocumentUrl: | - | ||||||||||||
583 | return d->url; | - | ||||||||||||
584 | } | - | ||||||||||||
585 | return QString(); | - | ||||||||||||
586 | } | - | ||||||||||||
587 | - | |||||||||||||
588 | - | |||||||||||||
589 | - | |||||||||||||
590 | - | |||||||||||||
591 | - | |||||||||||||
592 | - | |||||||||||||
593 | - | |||||||||||||
594 | void QTextDocument::setMetaInformation(MetaInformation info, const QString &string) | - | ||||||||||||
595 | { | - | ||||||||||||
596 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
597 | switch (info) { | - | ||||||||||||
598 | case DocumentTitle: | - | ||||||||||||
599 | d->title = string; | - | ||||||||||||
600 | break; | - | ||||||||||||
601 | case DocumentUrl: | - | ||||||||||||
602 | d->url = string; | - | ||||||||||||
603 | break; | - | ||||||||||||
604 | } | - | ||||||||||||
605 | } | - | ||||||||||||
606 | QString QTextDocument::toPlainText() const | - | ||||||||||||
607 | { | - | ||||||||||||
608 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
609 | QString txt = d->plainText(); | - | ||||||||||||
610 | - | |||||||||||||
611 | QChar *uc = txt.data(); | - | ||||||||||||
612 | QChar *e = uc + txt.size(); | - | ||||||||||||
613 | - | |||||||||||||
614 | for (; uc != e; ++uc) { | - | ||||||||||||
615 | switch (uc->unicode()) { | - | ||||||||||||
616 | case 0xfdd0: | - | ||||||||||||
617 | case 0xfdd1: | - | ||||||||||||
618 | case QChar::ParagraphSeparator: | - | ||||||||||||
619 | case QChar::LineSeparator: | - | ||||||||||||
620 | *uc = QLatin1Char('\n'); | - | ||||||||||||
621 | break; | - | ||||||||||||
622 | case QChar::Nbsp: | - | ||||||||||||
623 | *uc = QLatin1Char(' '); | - | ||||||||||||
624 | break; | - | ||||||||||||
625 | default: | - | ||||||||||||
626 | ; | - | ||||||||||||
627 | } | - | ||||||||||||
628 | } | - | ||||||||||||
629 | return txt; | - | ||||||||||||
630 | } | - | ||||||||||||
631 | - | |||||||||||||
632 | - | |||||||||||||
633 | - | |||||||||||||
634 | - | |||||||||||||
635 | - | |||||||||||||
636 | - | |||||||||||||
637 | - | |||||||||||||
638 | void QTextDocument::setPlainText(const QString &text) | - | ||||||||||||
639 | { | - | ||||||||||||
640 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
641 | bool previousState = d->isUndoRedoEnabled(); | - | ||||||||||||
642 | d->enableUndoRedo(false); | - | ||||||||||||
643 | d->beginEditBlock(); | - | ||||||||||||
644 | d->clear(); | - | ||||||||||||
645 | QTextCursor(this).insertText(text); | - | ||||||||||||
646 | d->endEditBlock(); | - | ||||||||||||
647 | d->enableUndoRedo(previousState); | - | ||||||||||||
648 | } | - | ||||||||||||
649 | void QTextDocument::setHtml(const QString &html) | - | ||||||||||||
650 | { | - | ||||||||||||
651 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
652 | bool previousState = d->isUndoRedoEnabled(); | - | ||||||||||||
653 | d->enableUndoRedo(false); | - | ||||||||||||
654 | d->beginEditBlock(); | - | ||||||||||||
655 | d->clear(); | - | ||||||||||||
656 | QTextHtmlImporter(this, html, QTextHtmlImporter::ImportToDocument).import(); | - | ||||||||||||
657 | d->endEditBlock(); | - | ||||||||||||
658 | d->enableUndoRedo(previousState); | - | ||||||||||||
659 | } | - | ||||||||||||
660 | static bool findInBlock(const QTextBlock &block, const QString &expression, int offset, | - | ||||||||||||
661 | QTextDocument::FindFlags options, QTextCursor *cursor) | - | ||||||||||||
662 | { | - | ||||||||||||
663 | QString text = block.text(); | - | ||||||||||||
664 | text.replace(QChar::Nbsp, QLatin1Char(' ')); | - | ||||||||||||
665 | Qt::CaseSensitivity sensitivity = options & QTextDocument::FindCaseSensitively ? Qt::CaseSensitive : Qt::CaseInsensitive; | - | ||||||||||||
666 | int idx = -1; | - | ||||||||||||
667 | - | |||||||||||||
668 | while (offset >= 0 && offset <= text.length()) { | - | ||||||||||||
669 | idx = (options & QTextDocument::FindBackward) ? | - | ||||||||||||
670 | text.lastIndexOf(expression, offset, sensitivity) : text.indexOf(expression, offset, sensitivity); | - | ||||||||||||
671 | if (idx == -1) | - | ||||||||||||
672 | return false; | - | ||||||||||||
673 | - | |||||||||||||
674 | if (options & QTextDocument::FindWholeWords) { | - | ||||||||||||
675 | const int start = idx; | - | ||||||||||||
676 | const int end = start + expression.length(); | - | ||||||||||||
677 | if ((start != 0 && text.at(start - 1).isLetterOrNumber()) | - | ||||||||||||
678 | || (end != text.length() && text.at(end).isLetterOrNumber())) { | - | ||||||||||||
679 | - | |||||||||||||
680 | offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1; | - | ||||||||||||
681 | idx = -1; | - | ||||||||||||
682 | continue; | - | ||||||||||||
683 | } | - | ||||||||||||
684 | } | - | ||||||||||||
685 | - | |||||||||||||
686 | *cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx); | - | ||||||||||||
687 | cursor->setPosition(cursor->position() + expression.length(), QTextCursor::KeepAnchor); | - | ||||||||||||
688 | return true; | - | ||||||||||||
689 | } | - | ||||||||||||
690 | return false; | - | ||||||||||||
691 | } | - | ||||||||||||
692 | QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags options) const | - | ||||||||||||
693 | { | - | ||||||||||||
694 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
695 | - | |||||||||||||
696 | if (subString.isEmpty()) | - | ||||||||||||
697 | return QTextCursor(); | - | ||||||||||||
698 | - | |||||||||||||
699 | int pos = from; | - | ||||||||||||
700 | - | |||||||||||||
701 | - | |||||||||||||
702 | if (options & FindBackward) { | - | ||||||||||||
703 | --pos ; | - | ||||||||||||
704 | if (pos < 0) | - | ||||||||||||
705 | return QTextCursor(); | - | ||||||||||||
706 | } | - | ||||||||||||
707 | - | |||||||||||||
708 | QTextCursor cursor; | - | ||||||||||||
709 | QTextBlock block = d->blocksFind(pos); | - | ||||||||||||
710 | int blockOffset = pos - block.position(); | - | ||||||||||||
711 | - | |||||||||||||
712 | if (!(options & FindBackward)) { | - | ||||||||||||
713 | while (block.isValid()) { | - | ||||||||||||
714 | if (findInBlock(block, subString, blockOffset, options, &cursor)) | - | ||||||||||||
715 | return cursor; | - | ||||||||||||
716 | block = block.next(); | - | ||||||||||||
717 | blockOffset = 0; | - | ||||||||||||
718 | } | - | ||||||||||||
719 | } else { | - | ||||||||||||
720 | while (block.isValid()) { | - | ||||||||||||
721 | if (findInBlock(block, subString, blockOffset, options, &cursor)) | - | ||||||||||||
722 | return cursor; | - | ||||||||||||
723 | block = block.previous(); | - | ||||||||||||
724 | blockOffset = block.length() - 2; | - | ||||||||||||
725 | } | - | ||||||||||||
726 | } | - | ||||||||||||
727 | - | |||||||||||||
728 | return QTextCursor(); | - | ||||||||||||
729 | } | - | ||||||||||||
730 | QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cursor, FindFlags options) const | - | ||||||||||||
731 | { | - | ||||||||||||
732 | int pos = 0; | - | ||||||||||||
733 | if (!cursor.isNull()) { | - | ||||||||||||
734 | if (options & QTextDocument::FindBackward) | - | ||||||||||||
735 | pos = cursor.selectionStart(); | - | ||||||||||||
736 | else | - | ||||||||||||
737 | pos = cursor.selectionEnd(); | - | ||||||||||||
738 | } | - | ||||||||||||
739 | - | |||||||||||||
740 | return find(subString, pos, options); | - | ||||||||||||
741 | } | - | ||||||||||||
742 | - | |||||||||||||
743 | - | |||||||||||||
744 | - | |||||||||||||
745 | static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset, | - | ||||||||||||
746 | QTextDocument::FindFlags options, QTextCursor *cursor) | - | ||||||||||||
747 | { | - | ||||||||||||
748 | QRegExp expr(expression); | - | ||||||||||||
749 | QString text = block.text(); | - | ||||||||||||
750 | text.replace(QChar::Nbsp, QLatin1Char(' ')); | - | ||||||||||||
751 | - | |||||||||||||
752 | int idx = -1; | - | ||||||||||||
753 | while (offset >=0 && offset <= text.length()) { | - | ||||||||||||
754 | idx = (options & QTextDocument::FindBackward) ? | - | ||||||||||||
755 | expr.lastIndexIn(text, offset) : expr.indexIn(text, offset); | - | ||||||||||||
756 | if (idx == -1) | - | ||||||||||||
757 | return false; | - | ||||||||||||
758 | - | |||||||||||||
759 | if (options & QTextDocument::FindWholeWords) { | - | ||||||||||||
760 | const int start = idx; | - | ||||||||||||
761 | const int end = start + expr.matchedLength(); | - | ||||||||||||
762 | if ((start != 0 && text.at(start - 1).isLetterOrNumber()) | - | ||||||||||||
763 | || (end != text.length() && text.at(end).isLetterOrNumber())) { | - | ||||||||||||
764 | - | |||||||||||||
765 | offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1; | - | ||||||||||||
766 | idx = -1; | - | ||||||||||||
767 | continue; | - | ||||||||||||
768 | } | - | ||||||||||||
769 | } | - | ||||||||||||
770 | - | |||||||||||||
771 | *cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx); | - | ||||||||||||
772 | cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor); | - | ||||||||||||
773 | return true; | - | ||||||||||||
774 | } | - | ||||||||||||
775 | return false; | - | ||||||||||||
776 | } | - | ||||||||||||
777 | QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags options) const | - | ||||||||||||
778 | { | - | ||||||||||||
779 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
780 | - | |||||||||||||
781 | if (expr.isEmpty()) | - | ||||||||||||
782 | return QTextCursor(); | - | ||||||||||||
783 | - | |||||||||||||
784 | int pos = from; | - | ||||||||||||
785 | - | |||||||||||||
786 | - | |||||||||||||
787 | if (options & FindBackward) { | - | ||||||||||||
788 | --pos ; | - | ||||||||||||
789 | if(pos < 0) | - | ||||||||||||
790 | return QTextCursor(); | - | ||||||||||||
791 | } | - | ||||||||||||
792 | - | |||||||||||||
793 | QTextCursor cursor; | - | ||||||||||||
794 | QTextBlock block = d->blocksFind(pos); | - | ||||||||||||
795 | int blockOffset = pos - block.position(); | - | ||||||||||||
796 | if (!(options & FindBackward)) { | - | ||||||||||||
797 | while (block.isValid()) { | - | ||||||||||||
798 | if (findInBlock(block, expr, blockOffset, options, &cursor)) | - | ||||||||||||
799 | return cursor; | - | ||||||||||||
800 | block = block.next(); | - | ||||||||||||
801 | blockOffset = 0; | - | ||||||||||||
802 | } | - | ||||||||||||
803 | } else { | - | ||||||||||||
804 | while (block.isValid()) { | - | ||||||||||||
805 | if (findInBlock(block, expr, blockOffset, options, &cursor)) | - | ||||||||||||
806 | return cursor; | - | ||||||||||||
807 | block = block.previous(); | - | ||||||||||||
808 | blockOffset = block.length() - 1; | - | ||||||||||||
809 | } | - | ||||||||||||
810 | } | - | ||||||||||||
811 | - | |||||||||||||
812 | return QTextCursor(); | - | ||||||||||||
813 | } | - | ||||||||||||
814 | QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const | - | ||||||||||||
815 | { | - | ||||||||||||
816 | int pos = 0; | - | ||||||||||||
817 | if (!cursor.isNull()) { | - | ||||||||||||
818 | if (options & QTextDocument::FindBackward) | - | ||||||||||||
819 | pos = cursor.selectionStart(); | - | ||||||||||||
820 | else | - | ||||||||||||
821 | pos = cursor.selectionEnd(); | - | ||||||||||||
822 | } | - | ||||||||||||
823 | return find(expr, pos, options); | - | ||||||||||||
824 | } | - | ||||||||||||
825 | - | |||||||||||||
826 | - | |||||||||||||
827 | - | |||||||||||||
828 | static bool findInBlock(const QTextBlock &block, const QRegularExpression &expression, int offset, | - | ||||||||||||
829 | QTextDocument::FindFlags options, QTextCursor *cursor) | - | ||||||||||||
830 | { | - | ||||||||||||
831 | QRegularExpression expr(expression); | - | ||||||||||||
832 | if (!(options & QTextDocument::FindCaseSensitively)) | - | ||||||||||||
833 | expr.setPatternOptions(expr.patternOptions() | QRegularExpression::CaseInsensitiveOption); | - | ||||||||||||
834 | else | - | ||||||||||||
835 | expr.setPatternOptions(expr.patternOptions() & ~QRegularExpression::CaseInsensitiveOption); | - | ||||||||||||
836 | - | |||||||||||||
837 | QString text = block.text(); | - | ||||||||||||
838 | text.replace(QChar::Nbsp, QLatin1Char(' ')); | - | ||||||||||||
839 | QRegularExpressionMatch match; | - | ||||||||||||
840 | int idx = -1; | - | ||||||||||||
841 | - | |||||||||||||
842 | while (offset >= 0 && offset <= text.length()) { | - | ||||||||||||
843 | idx = (options & QTextDocument::FindBackward) ? | - | ||||||||||||
844 | text.lastIndexOf(expr, offset, &match) : text.indexOf(expr, offset, &match); | - | ||||||||||||
845 | if (idx == -1) | - | ||||||||||||
846 | return false; | - | ||||||||||||
847 | - | |||||||||||||
848 | if (options & QTextDocument::FindWholeWords) { | - | ||||||||||||
849 | const int start = idx; | - | ||||||||||||
850 | const int end = start + match.capturedLength(); | - | ||||||||||||
851 | if ((start != 0 && text.at(start - 1).isLetterOrNumber()) | - | ||||||||||||
852 | || (end != text.length() && text.at(end).isLetterOrNumber())) { | - | ||||||||||||
853 | - | |||||||||||||
854 | offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1; | - | ||||||||||||
855 | idx = -1; | - | ||||||||||||
856 | continue; | - | ||||||||||||
857 | } | - | ||||||||||||
858 | } | - | ||||||||||||
859 | - | |||||||||||||
860 | *cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx); | - | ||||||||||||
861 | cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor); | - | ||||||||||||
862 | return true; | - | ||||||||||||
863 | } | - | ||||||||||||
864 | return false; | - | ||||||||||||
865 | } | - | ||||||||||||
866 | QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFlags options) const | - | ||||||||||||
867 | { | - | ||||||||||||
868 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
869 | - | |||||||||||||
870 | if (!expr.isValid()) | - | ||||||||||||
871 | return QTextCursor(); | - | ||||||||||||
872 | - | |||||||||||||
873 | int pos = from; | - | ||||||||||||
874 | - | |||||||||||||
875 | - | |||||||||||||
876 | if (options & FindBackward) { | - | ||||||||||||
877 | --pos ; | - | ||||||||||||
878 | if (pos < 0) | - | ||||||||||||
879 | return QTextCursor(); | - | ||||||||||||
880 | } | - | ||||||||||||
881 | - | |||||||||||||
882 | QTextCursor cursor; | - | ||||||||||||
883 | QTextBlock block = d->blocksFind(pos); | - | ||||||||||||
884 | int blockOffset = pos - block.position(); | - | ||||||||||||
885 | - | |||||||||||||
886 | if (!(options & FindBackward)) { | - | ||||||||||||
887 | while (block.isValid()) { | - | ||||||||||||
888 | if (findInBlock(block, expr, blockOffset, options, &cursor)) | - | ||||||||||||
889 | return cursor; | - | ||||||||||||
890 | block = block.next(); | - | ||||||||||||
891 | blockOffset = 0; | - | ||||||||||||
892 | } | - | ||||||||||||
893 | } else { | - | ||||||||||||
894 | while (block.isValid()) { | - | ||||||||||||
895 | if (findInBlock(block, expr, blockOffset, options, &cursor)) | - | ||||||||||||
896 | return cursor; | - | ||||||||||||
897 | block = block.previous(); | - | ||||||||||||
898 | blockOffset = block.length() - 1; | - | ||||||||||||
899 | } | - | ||||||||||||
900 | } | - | ||||||||||||
901 | - | |||||||||||||
902 | return QTextCursor(); | - | ||||||||||||
903 | } | - | ||||||||||||
904 | QTextCursor QTextDocument::find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options) const | - | ||||||||||||
905 | { | - | ||||||||||||
906 | int pos = 0; | - | ||||||||||||
907 | if (!cursor.isNull()) { | - | ||||||||||||
908 | if (options & QTextDocument::FindBackward) | - | ||||||||||||
909 | pos = cursor.selectionStart(); | - | ||||||||||||
910 | else | - | ||||||||||||
911 | pos = cursor.selectionEnd(); | - | ||||||||||||
912 | } | - | ||||||||||||
913 | return find(expr, pos, options); | - | ||||||||||||
914 | } | - | ||||||||||||
915 | QTextObject *QTextDocument::createObject(const QTextFormat &f) | - | ||||||||||||
916 | { | - | ||||||||||||
917 | QTextObject *obj = 0; | - | ||||||||||||
918 | if (f.isListFormat()) | - | ||||||||||||
919 | obj = new QTextList(this); | - | ||||||||||||
920 | else if (f.isTableFormat()) | - | ||||||||||||
921 | obj = new QTextTable(this); | - | ||||||||||||
922 | else if (f.isFrameFormat()) | - | ||||||||||||
923 | obj = new QTextFrame(this); | - | ||||||||||||
924 | - | |||||||||||||
925 | return obj; | - | ||||||||||||
926 | } | - | ||||||||||||
927 | - | |||||||||||||
928 | - | |||||||||||||
929 | - | |||||||||||||
930 | - | |||||||||||||
931 | - | |||||||||||||
932 | - | |||||||||||||
933 | QTextFrame *QTextDocument::frameAt(int pos) const | - | ||||||||||||
934 | { | - | ||||||||||||
935 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
936 | return d->frameAt(pos); | - | ||||||||||||
937 | } | - | ||||||||||||
938 | - | |||||||||||||
939 | - | |||||||||||||
940 | - | |||||||||||||
941 | - | |||||||||||||
942 | QTextFrame *QTextDocument::rootFrame() const | - | ||||||||||||
943 | { | - | ||||||||||||
944 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
945 | return d->rootFrame(); | - | ||||||||||||
946 | } | - | ||||||||||||
947 | - | |||||||||||||
948 | - | |||||||||||||
949 | - | |||||||||||||
950 | - | |||||||||||||
951 | QTextObject *QTextDocument::object(int objectIndex) const | - | ||||||||||||
952 | { | - | ||||||||||||
953 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
954 | return d->objectForIndex(objectIndex); | - | ||||||||||||
955 | } | - | ||||||||||||
956 | - | |||||||||||||
957 | - | |||||||||||||
958 | - | |||||||||||||
959 | - | |||||||||||||
960 | QTextObject *QTextDocument::objectForFormat(const QTextFormat &f) const | - | ||||||||||||
961 | { | - | ||||||||||||
962 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
963 | return d->objectForFormat(f); | - | ||||||||||||
964 | } | - | ||||||||||||
965 | - | |||||||||||||
966 | - | |||||||||||||
967 | - | |||||||||||||
968 | - | |||||||||||||
969 | - | |||||||||||||
970 | QTextBlock QTextDocument::findBlock(int pos) const | - | ||||||||||||
971 | { | - | ||||||||||||
972 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
973 | return QTextBlock(docHandle(), d->blockMap().findNode(pos)); | - | ||||||||||||
974 | } | - | ||||||||||||
975 | - | |||||||||||||
976 | - | |||||||||||||
977 | - | |||||||||||||
978 | - | |||||||||||||
979 | - | |||||||||||||
980 | - | |||||||||||||
981 | - | |||||||||||||
982 | QTextBlock QTextDocument::findBlockByNumber(int blockNumber) const | - | ||||||||||||
983 | { | - | ||||||||||||
984 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
985 | return QTextBlock(docHandle(), d->blockMap().findNode(blockNumber, 1)); | - | ||||||||||||
986 | } | - | ||||||||||||
987 | - | |||||||||||||
988 | - | |||||||||||||
989 | - | |||||||||||||
990 | - | |||||||||||||
991 | - | |||||||||||||
992 | - | |||||||||||||
993 | - | |||||||||||||
994 | QTextBlock QTextDocument::findBlockByLineNumber(int lineNumber) const | - | ||||||||||||
995 | { | - | ||||||||||||
996 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
997 | return QTextBlock(docHandle(), d->blockMap().findNode(lineNumber, 2)); | - | ||||||||||||
998 | } | - | ||||||||||||
999 | - | |||||||||||||
1000 | - | |||||||||||||
1001 | - | |||||||||||||
1002 | - | |||||||||||||
1003 | - | |||||||||||||
1004 | - | |||||||||||||
1005 | QTextBlock QTextDocument::begin() const | - | ||||||||||||
1006 | { | - | ||||||||||||
1007 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1008 | return QTextBlock(docHandle(), d->blockMap().begin().n); | - | ||||||||||||
1009 | } | - | ||||||||||||
1010 | QTextBlock QTextDocument::end() const | - | ||||||||||||
1011 | { | - | ||||||||||||
1012 | return QTextBlock(docHandle(), 0); | - | ||||||||||||
1013 | } | - | ||||||||||||
1014 | - | |||||||||||||
1015 | - | |||||||||||||
1016 | - | |||||||||||||
1017 | - | |||||||||||||
1018 | - | |||||||||||||
1019 | QTextBlock QTextDocument::firstBlock() const | - | ||||||||||||
1020 | { | - | ||||||||||||
1021 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1022 | return QTextBlock(docHandle(), d->blockMap().begin().n); | - | ||||||||||||
1023 | } | - | ||||||||||||
1024 | - | |||||||||||||
1025 | - | |||||||||||||
1026 | - | |||||||||||||
1027 | - | |||||||||||||
1028 | - | |||||||||||||
1029 | QTextBlock QTextDocument::lastBlock() const | - | ||||||||||||
1030 | { | - | ||||||||||||
1031 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1032 | return QTextBlock(docHandle(), d->blockMap().last().n); | - | ||||||||||||
1033 | } | - | ||||||||||||
1034 | void QTextDocument::setPageSize(const QSizeF &size) | - | ||||||||||||
1035 | { | - | ||||||||||||
1036 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1037 | d->pageSize = size; | - | ||||||||||||
1038 | if (d->lout) | - | ||||||||||||
1039 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
1040 | } | - | ||||||||||||
1041 | - | |||||||||||||
1042 | QSizeF QTextDocument::pageSize() const | - | ||||||||||||
1043 | { | - | ||||||||||||
1044 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1045 | return d->pageSize; | - | ||||||||||||
1046 | } | - | ||||||||||||
1047 | - | |||||||||||||
1048 | - | |||||||||||||
1049 | - | |||||||||||||
1050 | - | |||||||||||||
1051 | int QTextDocument::pageCount() const | - | ||||||||||||
1052 | { | - | ||||||||||||
1053 | return documentLayout()->pageCount(); | - | ||||||||||||
1054 | } | - | ||||||||||||
1055 | - | |||||||||||||
1056 | - | |||||||||||||
1057 | - | |||||||||||||
1058 | - | |||||||||||||
1059 | void QTextDocument::setDefaultFont(const QFont &font) | - | ||||||||||||
1060 | { | - | ||||||||||||
1061 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1062 | d->setDefaultFont(font); | - | ||||||||||||
1063 | if (d->lout) | - | ||||||||||||
1064 | d->lout->documentChanged(0, 0, d->length()); | - | ||||||||||||
1065 | } | - | ||||||||||||
1066 | - | |||||||||||||
1067 | - | |||||||||||||
1068 | - | |||||||||||||
1069 | - | |||||||||||||
1070 | QFont QTextDocument::defaultFont() const | - | ||||||||||||
1071 | { | - | ||||||||||||
1072 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1073 | return d->defaultFont(); | - | ||||||||||||
1074 | } | - | ||||||||||||
1075 | bool QTextDocument::isModified() const | - | ||||||||||||
1076 | { | - | ||||||||||||
1077 | return docHandle()->isModified(); | - | ||||||||||||
1078 | } | - | ||||||||||||
1079 | - | |||||||||||||
1080 | void QTextDocument::setModified(bool m) | - | ||||||||||||
1081 | { | - | ||||||||||||
1082 | docHandle()->setModified(m); | - | ||||||||||||
1083 | } | - | ||||||||||||
1084 | - | |||||||||||||
1085 | - | |||||||||||||
1086 | static void printPage(int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos) | - | ||||||||||||
1087 | { | - | ||||||||||||
1088 | painter->save(); | - | ||||||||||||
1089 | painter->translate(body.left(), body.top() - (index - 1) * body.height()); | - | ||||||||||||
1090 | QRectF view(0, (index - 1) * body.height(), body.width(), body.height()); | - | ||||||||||||
1091 | - | |||||||||||||
1092 | QAbstractTextDocumentLayout *layout = doc->documentLayout(); | - | ||||||||||||
1093 | QAbstractTextDocumentLayout::PaintContext ctx; | - | ||||||||||||
1094 | - | |||||||||||||
1095 | painter->setClipRect(view); | - | ||||||||||||
1096 | ctx.clip = view; | - | ||||||||||||
1097 | - | |||||||||||||
1098 | - | |||||||||||||
1099 | - | |||||||||||||
1100 | - | |||||||||||||
1101 | ctx.palette.setColor(QPalette::Text, Qt::black); | - | ||||||||||||
1102 | - | |||||||||||||
1103 | layout->draw(painter, ctx); | - | ||||||||||||
1104 | - | |||||||||||||
1105 | if (!pageNumberPos.isNull()) { | - | ||||||||||||
1106 | painter->setClipping(false); | - | ||||||||||||
1107 | painter->setFont(QFont(doc->defaultFont())); | - | ||||||||||||
1108 | const QString pageString = QString::number(index); | - | ||||||||||||
1109 | - | |||||||||||||
1110 | painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().width(pageString)), | - | ||||||||||||
1111 | qRound(pageNumberPos.y() + view.top()), | - | ||||||||||||
1112 | pageString); | - | ||||||||||||
1113 | } | - | ||||||||||||
1114 | - | |||||||||||||
1115 | painter->restore(); | - | ||||||||||||
1116 | } | - | ||||||||||||
1117 | void QTextDocument::print(QPagedPaintDevice *printer) const | - | ||||||||||||
1118 | { | - | ||||||||||||
1119 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1120 | - | |||||||||||||
1121 | if (!printer) | - | ||||||||||||
1122 | return; | - | ||||||||||||
1123 | - | |||||||||||||
1124 | bool documentPaginated = d->pageSize.isValid() && !d->pageSize.isNull() | - | ||||||||||||
1125 | && d->pageSize.height() != 2147483647; | - | ||||||||||||
1126 | - | |||||||||||||
1127 | QPagedPaintDevicePrivate *pd = QPagedPaintDevicePrivate::get(printer); | - | ||||||||||||
1128 | - | |||||||||||||
1129 | - | |||||||||||||
1130 | QPagedPaintDevice::Margins m = printer->margins(); | - | ||||||||||||
1131 | if (!documentPaginated && m.left == 0. && m.right == 0. && m.top == 0. && m.bottom == 0.) { | - | ||||||||||||
1132 | m.left = m.right = m.top = m.bottom = 2.; | - | ||||||||||||
1133 | printer->setMargins(m); | - | ||||||||||||
1134 | } | - | ||||||||||||
1135 | - | |||||||||||||
1136 | - | |||||||||||||
1137 | QPainter p(printer); | - | ||||||||||||
1138 | - | |||||||||||||
1139 | - | |||||||||||||
1140 | if (!p.isActive()) | - | ||||||||||||
1141 | return; | - | ||||||||||||
1142 | - | |||||||||||||
1143 | const QTextDocument *doc = this; | - | ||||||||||||
1144 | QScopedPointer<QTextDocument> clonedDoc; | - | ||||||||||||
1145 | (void)doc->documentLayout(); | - | ||||||||||||
1146 | - | |||||||||||||
1147 | QRectF body = QRectF(QPointF(0, 0), d->pageSize); | - | ||||||||||||
1148 | QPointF pageNumberPos; | - | ||||||||||||
1149 | - | |||||||||||||
1150 | if (documentPaginated) { | - | ||||||||||||
1151 | qreal sourceDpiX = qt_defaultDpi(); | - | ||||||||||||
1152 | qreal sourceDpiY = sourceDpiX; | - | ||||||||||||
1153 | - | |||||||||||||
1154 | QPaintDevice *dev = doc->documentLayout()->paintDevice(); | - | ||||||||||||
1155 | if (dev) { | - | ||||||||||||
1156 | sourceDpiX = dev->logicalDpiX(); | - | ||||||||||||
1157 | sourceDpiY = dev->logicalDpiY(); | - | ||||||||||||
1158 | } | - | ||||||||||||
1159 | - | |||||||||||||
1160 | const qreal dpiScaleX = qreal(printer->logicalDpiX()) / sourceDpiX; | - | ||||||||||||
1161 | const qreal dpiScaleY = qreal(printer->logicalDpiY()) / sourceDpiY; | - | ||||||||||||
1162 | - | |||||||||||||
1163 | - | |||||||||||||
1164 | p.scale(dpiScaleX, dpiScaleY); | - | ||||||||||||
1165 | - | |||||||||||||
1166 | QSizeF scaledPageSize = d->pageSize; | - | ||||||||||||
1167 | scaledPageSize.rwidth() *= dpiScaleX; | - | ||||||||||||
1168 | scaledPageSize.rheight() *= dpiScaleY; | - | ||||||||||||
1169 | - | |||||||||||||
1170 | const QSizeF printerPageSize(printer->width(), printer->height()); | - | ||||||||||||
1171 | - | |||||||||||||
1172 | - | |||||||||||||
1173 | p.scale(printerPageSize.width() / scaledPageSize.width(), | - | ||||||||||||
1174 | printerPageSize.height() / scaledPageSize.height()); | - | ||||||||||||
1175 | } else { | - | ||||||||||||
1176 | doc = clone(const_cast<QTextDocument *>(this)); | - | ||||||||||||
1177 | clonedDoc.reset(const_cast<QTextDocument *>(doc)); | - | ||||||||||||
1178 | - | |||||||||||||
1179 | for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock(); | - | ||||||||||||
1180 | srcBlock.isValid() && dstBlock.isValid(); | - | ||||||||||||
1181 | srcBlock = srcBlock.next(), dstBlock = dstBlock.next()) { | - | ||||||||||||
1182 | dstBlock.layout()->setFormats(srcBlock.layout()->formats()); | - | ||||||||||||
1183 | } | - | ||||||||||||
1184 | - | |||||||||||||
1185 | QAbstractTextDocumentLayout *layout = doc->documentLayout(); | - | ||||||||||||
1186 | layout->setPaintDevice(p.device()); | - | ||||||||||||
1187 | - | |||||||||||||
1188 | - | |||||||||||||
1189 | layout->d_func()->handlers = documentLayout()->d_func()->handlers; | - | ||||||||||||
1190 | - | |||||||||||||
1191 | int dpiy = p.device()->logicalDpiY(); | - | ||||||||||||
1192 | int margin = (int) ((2/2.54)*dpiy); | - | ||||||||||||
1193 | QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); | - | ||||||||||||
1194 | fmt.setMargin(margin); | - | ||||||||||||
1195 | doc->rootFrame()->setFrameFormat(fmt); | - | ||||||||||||
1196 | - | |||||||||||||
1197 | body = QRectF(0, 0, printer->width(), printer->height()); | - | ||||||||||||
1198 | pageNumberPos = QPointF(body.width() - margin, | - | ||||||||||||
1199 | body.height() - margin | - | ||||||||||||
1200 | + QFontMetrics(doc->defaultFont(), p.device()).ascent() | - | ||||||||||||
1201 | + 5 * dpiy / 72.0); | - | ||||||||||||
1202 | clonedDoc->setPageSize(body.size()); | - | ||||||||||||
1203 | } | - | ||||||||||||
1204 | - | |||||||||||||
1205 | int fromPage = pd->fromPage; | - | ||||||||||||
1206 | int toPage = pd->toPage; | - | ||||||||||||
1207 | bool ascending = true; | - | ||||||||||||
1208 | - | |||||||||||||
1209 | if (fromPage == 0 && toPage == 0) { | - | ||||||||||||
1210 | fromPage = 1; | - | ||||||||||||
1211 | toPage = doc->pageCount(); | - | ||||||||||||
1212 | } | - | ||||||||||||
1213 | - | |||||||||||||
1214 | fromPage = qMax(1, fromPage); | - | ||||||||||||
1215 | toPage = qMin(doc->pageCount(), toPage); | - | ||||||||||||
1216 | - | |||||||||||||
1217 | if (toPage < fromPage) { | - | ||||||||||||
1218 | - | |||||||||||||
1219 | - | |||||||||||||
1220 | return; | - | ||||||||||||
1221 | } | - | ||||||||||||
1222 | int page = fromPage; | - | ||||||||||||
1223 | while (true) { | - | ||||||||||||
1224 | printPage(page, &p, doc, body, pageNumberPos); | - | ||||||||||||
1225 | - | |||||||||||||
1226 | if (page == toPage) | - | ||||||||||||
1227 | break; | - | ||||||||||||
1228 | - | |||||||||||||
1229 | if (ascending) | - | ||||||||||||
1230 | ++page; | - | ||||||||||||
1231 | else | - | ||||||||||||
1232 | --page; | - | ||||||||||||
1233 | - | |||||||||||||
1234 | if (!printer->newPage()) | - | ||||||||||||
1235 | return; | - | ||||||||||||
1236 | } | - | ||||||||||||
1237 | } | - | ||||||||||||
1238 | QVariant QTextDocument::resource(int type, const QUrl &name) const | - | ||||||||||||
1239 | { | - | ||||||||||||
1240 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1241 | const QUrl url = d->baseUrl.resolved(name); | - | ||||||||||||
1242 | QVariant r = d->resources.value(url); | - | ||||||||||||
1243 | if (!r.isValid()) { | - | ||||||||||||
1244 | r = d->cachedResources.value(url); | - | ||||||||||||
1245 | if (!r.isValid()) | - | ||||||||||||
1246 | r = const_cast<QTextDocument *>(this)->loadResource(type, url); | - | ||||||||||||
1247 | } | - | ||||||||||||
1248 | return r; | - | ||||||||||||
1249 | } | - | ||||||||||||
1250 | void QTextDocument::addResource(int type, const QUrl &name, const QVariant &resource) | - | ||||||||||||
1251 | { | - | ||||||||||||
1252 | (void)type;; | - | ||||||||||||
1253 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1254 | d->resources.insert(name, resource); | - | ||||||||||||
1255 | } | - | ||||||||||||
1256 | QVariant QTextDocument::loadResource(int type, const QUrl &name) | - | ||||||||||||
1257 | { | - | ||||||||||||
1258 | QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
1259 | QVariant r; | - | ||||||||||||
1260 | - | |||||||||||||
1261 | QObject *p = parent(); | - | ||||||||||||
1262 | if (p) { | - | ||||||||||||
1263 | const QMetaObject *me = p->metaObject(); | - | ||||||||||||
1264 | int index = me->indexOfMethod("loadResource(int,QUrl)"); | - | ||||||||||||
1265 | if (index >= 0) { | - | ||||||||||||
1266 | QMetaMethod loader = me->method(index); | - | ||||||||||||
1267 | loader.invoke(p, QReturnArgument<QVariant >("QVariant", r), QArgument<int >("int", type), QArgument<QUrl >("QUrl", name)); | - | ||||||||||||
1268 | } | - | ||||||||||||
1269 | } | - | ||||||||||||
1270 | - | |||||||||||||
1271 | - | |||||||||||||
1272 | if (r.isNull() && name.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1273 | QString mimetype; | - | ||||||||||||
1274 | QByteArray payload; | - | ||||||||||||
1275 | if (qDecodeDataUrl(name, mimetype, payload)) | - | ||||||||||||
1276 | r = payload; | - | ||||||||||||
1277 | } | - | ||||||||||||
1278 | - | |||||||||||||
1279 | - | |||||||||||||
1280 | if (!qobject_cast<QTextDocument *>(p) && r.isNull()) { | - | ||||||||||||
1281 | QUrl resourceUrl = name; | - | ||||||||||||
1282 | - | |||||||||||||
1283 | if (name.isRelative()) { | - | ||||||||||||
1284 | QUrl currentURL = d->url; | - | ||||||||||||
1285 | - | |||||||||||||
1286 | - | |||||||||||||
1287 | if (!(currentURL.isRelative() | - | ||||||||||||
1288 | || (currentURL.scheme() == QLatin1String("file") | - | ||||||||||||
1289 | && !QFileInfo(currentURL.toLocalFile()).isAbsolute())) | - | ||||||||||||
1290 | || (name.hasFragment() && name.path().isEmpty())) { | - | ||||||||||||
1291 | resourceUrl = currentURL.resolved(name); | - | ||||||||||||
1292 | } else { | - | ||||||||||||
1293 | - | |||||||||||||
1294 | - | |||||||||||||
1295 | - | |||||||||||||
1296 | QFileInfo fi(currentURL.toLocalFile()); | - | ||||||||||||
1297 | if (fi.exists()) { | - | ||||||||||||
1298 | resourceUrl = | - | ||||||||||||
1299 | QUrl::fromLocalFile(fi.absolutePath() + QDir::separator()).resolved(name); | - | ||||||||||||
1300 | } else if (currentURL.isEmpty()) { | - | ||||||||||||
1301 | resourceUrl.setScheme(QLatin1String("file")); | - | ||||||||||||
1302 | } | - | ||||||||||||
1303 | } | - | ||||||||||||
1304 | } | - | ||||||||||||
1305 | - | |||||||||||||
1306 | QString s = resourceUrl.toLocalFile(); | - | ||||||||||||
1307 | QFile f(s); | - | ||||||||||||
1308 | if (!s.isEmpty() && f.open(QFile::ReadOnly)) { | - | ||||||||||||
1309 | r = f.readAll(); | - | ||||||||||||
1310 | f.close(); | - | ||||||||||||
1311 | } | - | ||||||||||||
1312 | } | - | ||||||||||||
1313 | - | |||||||||||||
1314 | if (!r.isNull()) { | - | ||||||||||||
1315 | if (type == ImageResource && r.type() == QVariant::ByteArray) { | - | ||||||||||||
1316 | if (QCoreApplication::instance()->thread() != QThread::currentThread()) { | - | ||||||||||||
1317 | - | |||||||||||||
1318 | QImage image; | - | ||||||||||||
1319 | image.loadFromData(r.toByteArray()); | - | ||||||||||||
1320 | if (!image.isNull()) | - | ||||||||||||
1321 | r = image; | - | ||||||||||||
1322 | } else { | - | ||||||||||||
1323 | QPixmap pm; | - | ||||||||||||
1324 | pm.loadFromData(r.toByteArray()); | - | ||||||||||||
1325 | if (!pm.isNull()) | - | ||||||||||||
1326 | r = pm; | - | ||||||||||||
1327 | } | - | ||||||||||||
1328 | } | - | ||||||||||||
1329 | d->cachedResources.insert(name, r); | - | ||||||||||||
1330 | } | - | ||||||||||||
1331 | return r; | - | ||||||||||||
1332 | } | - | ||||||||||||
1333 | - | |||||||||||||
1334 | static QTextFormat formatDifference(const QTextFormat &from, const QTextFormat &to) | - | ||||||||||||
1335 | { | - | ||||||||||||
1336 | QTextFormat diff = to; | - | ||||||||||||
1337 | - | |||||||||||||
1338 | const QMap<int, QVariant> props = to.properties(); | - | ||||||||||||
1339 | for (QMap<int, QVariant>::ConstIterator it = props.begin(), end = props.end(); | - | ||||||||||||
1340 | it != end; ++it) | - | ||||||||||||
1341 | if (it.value() == from.property(it.key())) | - | ||||||||||||
1342 | diff.clearProperty(it.key()); | - | ||||||||||||
1343 | - | |||||||||||||
1344 | return diff; | - | ||||||||||||
1345 | } | - | ||||||||||||
1346 | - | |||||||||||||
1347 | static QString colorValue(QColor color) | - | ||||||||||||
1348 | { | - | ||||||||||||
1349 | QString result; | - | ||||||||||||
1350 | - | |||||||||||||
1351 | if (color.alpha() == 255) { | - | ||||||||||||
1352 | result = color.name(); | - | ||||||||||||
1353 | } else if (color.alpha()) { | - | ||||||||||||
1354 | QString alphaValue = QString::number(color.alphaF(), 'f', 6).remove(QRegExp(QLatin1String("\\.?0*$"))); | - | ||||||||||||
1355 | result = QString::fromLatin1("rgba(%1,%2,%3,%4)").arg(color.red()) | - | ||||||||||||
1356 | .arg(color.green()) | - | ||||||||||||
1357 | .arg(color.blue()) | - | ||||||||||||
1358 | .arg(alphaValue); | - | ||||||||||||
1359 | } else { | - | ||||||||||||
1360 | result = QLatin1String("transparent"); | - | ||||||||||||
1361 | } | - | ||||||||||||
1362 | - | |||||||||||||
1363 | return result; | - | ||||||||||||
1364 | } | - | ||||||||||||
1365 | - | |||||||||||||
1366 | QTextHtmlExporter::QTextHtmlExporter(const QTextDocument *_doc) | - | ||||||||||||
1367 | : doc(_doc), fragmentMarkers(false) | - | ||||||||||||
1368 | { | - | ||||||||||||
1369 | const QFont defaultFont = doc->defaultFont(); | - | ||||||||||||
1370 | defaultCharFormat.setFont(defaultFont); | - | ||||||||||||
1371 | - | |||||||||||||
1372 | defaultCharFormat.clearProperty(QTextFormat::FontUnderline); | - | ||||||||||||
1373 | defaultCharFormat.clearProperty(QTextFormat::FontOverline); | - | ||||||||||||
1374 | defaultCharFormat.clearProperty(QTextFormat::FontStrikeOut); | - | ||||||||||||
1375 | defaultCharFormat.clearProperty(QTextFormat::TextUnderlineStyle); | - | ||||||||||||
1376 | } | - | ||||||||||||
1377 | - | |||||||||||||
1378 | - | |||||||||||||
1379 | - | |||||||||||||
1380 | - | |||||||||||||
1381 | - | |||||||||||||
1382 | - | |||||||||||||
1383 | QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode) | - | ||||||||||||
1384 | { | - | ||||||||||||
1385 | html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " | - | ||||||||||||
1386 | "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" | - | ||||||||||||
1387 | "<html><head><meta name=\"qrichtext\" content=\"1\" />"); | - | ||||||||||||
1388 | html.reserve(doc->docHandle()->length()); | - | ||||||||||||
1389 | - | |||||||||||||
1390 | fragmentMarkers = (mode == ExportFragment); | - | ||||||||||||
1391 | - | |||||||||||||
1392 | if (!encoding.isEmpty()) | - | ||||||||||||
1393 | html += QString::fromLatin1("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%1\" />").arg(QString::fromLatin1(encoding)); | - | ||||||||||||
1394 | - | |||||||||||||
1395 | QString title = doc->metaInformation(QTextDocument::DocumentTitle); | - | ||||||||||||
1396 | if (!title.isEmpty()) | - | ||||||||||||
1397 | html += QString::fromLatin1("<title>") + title + QString::fromLatin1("</title>"); | - | ||||||||||||
1398 | html += QLatin1String("<style type=\"text/css\">\n"); | - | ||||||||||||
1399 | html += QLatin1String("p, li { white-space: pre-wrap; }\n"); | - | ||||||||||||
1400 | html += QLatin1String("</style>"); | - | ||||||||||||
1401 | html += QLatin1String("</head><body"); | - | ||||||||||||
1402 | - | |||||||||||||
1403 | if (mode == ExportEntireDocument) { | - | ||||||||||||
1404 | html += QLatin1String(" style=\""); | - | ||||||||||||
1405 | - | |||||||||||||
1406 | emitFontFamily(defaultCharFormat.fontFamily()); | - | ||||||||||||
1407 | - | |||||||||||||
1408 | if (defaultCharFormat.hasProperty(QTextFormat::FontPointSize)) { | - | ||||||||||||
1409 | html += QLatin1String(" font-size:"); | - | ||||||||||||
1410 | html += QString::number(defaultCharFormat.fontPointSize()); | - | ||||||||||||
1411 | html += QLatin1String("pt;"); | - | ||||||||||||
1412 | } else if (defaultCharFormat.hasProperty(QTextFormat::FontPixelSize)) { | - | ||||||||||||
1413 | html += QLatin1String(" font-size:"); | - | ||||||||||||
1414 | html += QString::number(defaultCharFormat.intProperty(QTextFormat::FontPixelSize)); | - | ||||||||||||
1415 | html += QLatin1String("px;"); | - | ||||||||||||
1416 | } | - | ||||||||||||
1417 | - | |||||||||||||
1418 | html += QLatin1String(" font-weight:"); | - | ||||||||||||
1419 | html += QString::number(defaultCharFormat.fontWeight() * 8); | - | ||||||||||||
1420 | html += QLatin1Char(';'); | - | ||||||||||||
1421 | - | |||||||||||||
1422 | html += QLatin1String(" font-style:"); | - | ||||||||||||
1423 | html += (defaultCharFormat.fontItalic() ? QLatin1String("italic") : QLatin1String("normal")); | - | ||||||||||||
1424 | html += QLatin1Char(';'); | - | ||||||||||||
1425 | - | |||||||||||||
1426 | - | |||||||||||||
1427 | - | |||||||||||||
1428 | - | |||||||||||||
1429 | html += QLatin1Char('\"'); | - | ||||||||||||
1430 | - | |||||||||||||
1431 | const QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); | - | ||||||||||||
1432 | emitBackgroundAttribute(fmt); | - | ||||||||||||
1433 | - | |||||||||||||
1434 | } else { | - | ||||||||||||
1435 | defaultCharFormat = QTextCharFormat(); | - | ||||||||||||
1436 | } | - | ||||||||||||
1437 | html += QLatin1Char('>'); | - | ||||||||||||
1438 | - | |||||||||||||
1439 | QTextFrameFormat rootFmt = doc->rootFrame()->frameFormat(); | - | ||||||||||||
1440 | rootFmt.clearProperty(QTextFormat::BackgroundBrush); | - | ||||||||||||
1441 | - | |||||||||||||
1442 | QTextFrameFormat defaultFmt; | - | ||||||||||||
1443 | defaultFmt.setMargin(doc->documentMargin()); | - | ||||||||||||
1444 | - | |||||||||||||
1445 | if (rootFmt == defaultFmt) | - | ||||||||||||
1446 | emitFrame(doc->rootFrame()->begin()); | - | ||||||||||||
1447 | else | - | ||||||||||||
1448 | emitTextFrame(doc->rootFrame()); | - | ||||||||||||
1449 | - | |||||||||||||
1450 | html += QLatin1String("</body></html>"); | - | ||||||||||||
1451 | return html; | - | ||||||||||||
1452 | } | - | ||||||||||||
1453 | - | |||||||||||||
1454 | void QTextHtmlExporter::emitAttribute(const char *attribute, const QString &value) | - | ||||||||||||
1455 | { | - | ||||||||||||
1456 | html += QLatin1Char(' '); | - | ||||||||||||
1457 | html += QLatin1String(attribute); | - | ||||||||||||
1458 | html += QLatin1String("=\""); | - | ||||||||||||
1459 | html += value.toHtmlEscaped(); | - | ||||||||||||
1460 | html += QLatin1Char('"'); | - | ||||||||||||
1461 | } | - | ||||||||||||
1462 | - | |||||||||||||
1463 | bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) | - | ||||||||||||
1464 | { | - | ||||||||||||
1465 | bool attributesEmitted = false; | - | ||||||||||||
1466 | - | |||||||||||||
1467 | { | - | ||||||||||||
1468 | const QString family = format.fontFamily(); | - | ||||||||||||
1469 | if (!family.isEmpty()
| 0 | ||||||||||||
1470 | emitFontFamily(family); | - | ||||||||||||
1471 | attributesEmitted = true; | - | ||||||||||||
1472 | } never executed: end of block | 0 | ||||||||||||
1473 | } | - | ||||||||||||
1474 | - | |||||||||||||
1475 | if (format.hasProperty(QTextFormat::FontPointSize)
| 0 | ||||||||||||
1476 | && format.fontPointSize() != defaultCharFormat.fontPointSize()
| 0 | ||||||||||||
1477 | html += QLatin1String(" font-size:"); | - | ||||||||||||
1478 | html += QString::number(format.fontPointSize()); | - | ||||||||||||
1479 | html += QLatin1String("pt;"); | - | ||||||||||||
1480 | attributesEmitted = true; | - | ||||||||||||
1481 | } never executed: else if (format.hasProperty(QTextFormat::FontSizeAdjustment)end of block
| 0 | ||||||||||||
1482 | static const char sizeNameData[] = | - | ||||||||||||
1483 | "small" "\0" | - | ||||||||||||
1484 | "medium" "\0" | - | ||||||||||||
1485 | "xx-large" ; | - | ||||||||||||
1486 | static const quint8 sizeNameOffsets[] = { | - | ||||||||||||
1487 | 0, | - | ||||||||||||
1488 | sizeof("small"), | - | ||||||||||||
1489 | sizeof("small") + sizeof("medium") + 3, | - | ||||||||||||
1490 | sizeof("small") + sizeof("medium") + 1, | - | ||||||||||||
1491 | sizeof("small") + sizeof("medium"), | - | ||||||||||||
1492 | }; | - | ||||||||||||
1493 | const char *name = 0; | - | ||||||||||||
1494 | const int idx = format.intProperty(QTextFormat::FontSizeAdjustment) + 1; | - | ||||||||||||
1495 | if (idx >= 0
| 0 | ||||||||||||
1496 | name = sizeNameData + sizeNameOffsets[idx]; | - | ||||||||||||
1497 | } never executed: end of block | 0 | ||||||||||||
1498 | if (name
| 0 | ||||||||||||
1499 | html += QLatin1String(" font-size:"); | - | ||||||||||||
1500 | html += QLatin1String(name); | - | ||||||||||||
1501 | html += QLatin1Char(';'); | - | ||||||||||||
1502 | attributesEmitted = true; | - | ||||||||||||
1503 | } never executed: end of block | 0 | ||||||||||||
1504 | } never executed: else if (format.hasProperty(QTextFormat::FontPixelSize)end of block
| 0 | ||||||||||||
1505 | html += QLatin1String(" font-size:"); | - | ||||||||||||
1506 | html += QString::number(format.intProperty(QTextFormat::FontPixelSize)); | - | ||||||||||||
1507 | html += QLatin1String("px;"); | - | ||||||||||||
1508 | attributesEmitted = true; | - | ||||||||||||
1509 | } never executed: end of block | 0 | ||||||||||||
1510 | - | |||||||||||||
1511 | if (format.hasProperty(QTextFormat::FontWeight)
| 0 | ||||||||||||
1512 | && format.fontWeight() != defaultCharFormat.fontWeight()
| 0 | ||||||||||||
1513 | html += QLatin1String(" font-weight:"); | - | ||||||||||||
1514 | html += QString::number(format.fontWeight() * 8); | - | ||||||||||||
1515 | html += QLatin1Char(';'); | - | ||||||||||||
1516 | attributesEmitted = true; | - | ||||||||||||
1517 | } never executed: end of block | 0 | ||||||||||||
1518 | - | |||||||||||||
1519 | if (format.hasProperty(QTextFormat::FontItalic)
| 0 | ||||||||||||
1520 | && format.fontItalic() != defaultCharFormat.fontItalic()
| 0 | ||||||||||||
1521 | html += QLatin1String(" font-style:"); | - | ||||||||||||
1522 | html += (format.fontItalic()
| 0 | ||||||||||||
1523 | html += QLatin1Char(';'); | - | ||||||||||||
1524 | attributesEmitted = true; | - | ||||||||||||
1525 | } never executed: end of block | 0 | ||||||||||||
1526 | - | |||||||||||||
1527 | QLatin1String decorationTag(" text-decoration:"); | - | ||||||||||||
1528 | html += decorationTag; | - | ||||||||||||
1529 | bool hasDecoration = false; | - | ||||||||||||
1530 | bool atLeastOneDecorationSet = false; | - | ||||||||||||
1531 | - | |||||||||||||
1532 | if ((format.hasProperty(QTextFormat::FontUnderline)
| 0 | ||||||||||||
1533 | && format.fontUnderline() != defaultCharFormat.fontUnderline()
| 0 | ||||||||||||
1534 | hasDecoration = true; | - | ||||||||||||
1535 | if (format.fontUnderline()
| 0 | ||||||||||||
1536 | html += QLatin1String(" underline"); | - | ||||||||||||
1537 | atLeastOneDecorationSet = true; | - | ||||||||||||
1538 | } never executed: end of block | 0 | ||||||||||||
1539 | } never executed: end of block | 0 | ||||||||||||
1540 | - | |||||||||||||
1541 | if (format.hasProperty(QTextFormat::FontOverline)
| 0 | ||||||||||||
1542 | && format.fontOverline() != defaultCharFormat.fontOverline()
| 0 | ||||||||||||
1543 | hasDecoration = true; | - | ||||||||||||
1544 | if (format.fontOverline()
| 0 | ||||||||||||
1545 | html += QLatin1String(" overline"); | - | ||||||||||||
1546 | atLeastOneDecorationSet = true; | - | ||||||||||||
1547 | } never executed: end of block | 0 | ||||||||||||
1548 | } never executed: end of block | 0 | ||||||||||||
1549 | - | |||||||||||||
1550 | if (format.hasProperty(QTextFormat::FontStrikeOut)
| 0 | ||||||||||||
1551 | && format.fontStrikeOut() != defaultCharFormat.fontStrikeOut()
| 0 | ||||||||||||
1552 | hasDecoration = true; | - | ||||||||||||
1553 | if (format.fontStrikeOut()
| 0 | ||||||||||||
1554 | html += QLatin1String(" line-through"); | - | ||||||||||||
1555 | atLeastOneDecorationSet = true; | - | ||||||||||||
1556 | } never executed: end of block | 0 | ||||||||||||
1557 | } never executed: end of block | 0 | ||||||||||||
1558 | - | |||||||||||||
1559 | if (hasDecoration
| 0 | ||||||||||||
1560 | if (!atLeastOneDecorationSet
| 0 | ||||||||||||
1561 | html += QLatin1String("none"); never executed: html += QLatin1String("none"); | 0 | ||||||||||||
1562 | html += QLatin1Char(';'); | - | ||||||||||||
1563 | attributesEmitted = true; | - | ||||||||||||
1564 | } never executed: else {end of block | 0 | ||||||||||||
1565 | html.chop(qstrlen(decorationTag.latin1()));size()); | - | ||||||||||||
1566 | } never executed: end of block | 0 | ||||||||||||
1567 | - | |||||||||||||
1568 | if (format.foreground() != defaultCharFormat.foreground()
| 0 | ||||||||||||
1569 | && format.foreground().style() != Qt::NoBrush
| 0 | ||||||||||||
1570 | html += QLatin1String(" color:"); | - | ||||||||||||
1571 | html += colorValue(format.foreground().color()); | - | ||||||||||||
1572 | html += QLatin1Char(';'); | - | ||||||||||||
1573 | attributesEmitted = true; | - | ||||||||||||
1574 | } never executed: end of block | 0 | ||||||||||||
1575 | - | |||||||||||||
1576 | if (format.background() != defaultCharFormat.background()
| 0 | ||||||||||||
1577 | && format.background().style() == Qt::SolidPattern
| 0 | ||||||||||||
1578 | html += QLatin1String(" background-color:"); | - | ||||||||||||
1579 | html += colorValue(format.background().color()); | - | ||||||||||||
1580 | html += QLatin1Char(';'); | - | ||||||||||||
1581 | attributesEmitted = true; | - | ||||||||||||
1582 | } never executed: end of block | 0 | ||||||||||||
1583 | - | |||||||||||||
1584 | if (format.verticalAlignment() != defaultCharFormat.verticalAlignment()
| 0 | ||||||||||||
1585 | && format.verticalAlignment() != QTextCharFormat::AlignNormal
| 0 | ||||||||||||
1586 | { | - | ||||||||||||
1587 | html += QLatin1String(" vertical-align:"); | - | ||||||||||||
1588 | - | |||||||||||||
1589 | QTextCharFormat::VerticalAlignment valign = format.verticalAlignment(); | - | ||||||||||||
1590 | if (valign == QTextCharFormat::AlignSubScript
| 0 | ||||||||||||
1591 | html += QLatin1String("sub"); never executed: html += QLatin1String("sub"); | 0 | ||||||||||||
1592 | else if (valign == QTextCharFormat::AlignSuperScript
| 0 | ||||||||||||
1593 | html += QLatin1String("super"); never executed: html += QLatin1String("super"); | 0 | ||||||||||||
1594 | else if (valign == QTextCharFormat::AlignMiddle
| 0 | ||||||||||||
1595 | html += QLatin1String("middle"); never executed: html += QLatin1String("middle"); | 0 | ||||||||||||
1596 | else if (valign == QTextCharFormat::AlignTop
| 0 | ||||||||||||
1597 | html += QLatin1String("top"); never executed: html += QLatin1String("top"); | 0 | ||||||||||||
1598 | else if (valign == QTextCharFormat::AlignBottom
| 0 | ||||||||||||
1599 | html += QLatin1String("bottom"); never executed: html += QLatin1String("bottom"); | 0 | ||||||||||||
1600 | - | |||||||||||||
1601 | html += QLatin1Char(';'); | - | ||||||||||||
1602 | attributesEmitted = true; | - | ||||||||||||
1603 | } never executed: end of block | 0 | ||||||||||||
1604 | - | |||||||||||||
1605 | if (format.fontCapitalization() != QFont::MixedCase
| 0 | ||||||||||||
1606 | const QFont::Capitalization caps = format.fontCapitalization(); | - | ||||||||||||
1607 | if (caps == QFont::AllUppercase
| 0 | ||||||||||||
1608 | html += QLatin1String(" text-transform:uppercase;"); never executed: html += QLatin1String(" text-transform:uppercase;"); | 0 | ||||||||||||
1609 | else if (caps == QFont::AllLowercase
| 0 | ||||||||||||
1610 | html += QLatin1String(" text-transform:lowercase;"); never executed: html += QLatin1String(" text-transform:lowercase;"); | 0 | ||||||||||||
1611 | else if (caps == QFont::SmallCaps
| 0 | ||||||||||||
1612 | html += QLatin1String(" font-variant:small-caps;"); never executed: html += QLatin1String(" font-variant:small-caps;"); | 0 | ||||||||||||
1613 | attributesEmitted = true; | - | ||||||||||||
1614 | } never executed: end of block | 0 | ||||||||||||
1615 | - | |||||||||||||
1616 | if (format.fontWordSpacing() != 0.0
| 0 | ||||||||||||
1617 | html += QLatin1String(" word-spacing:"); | - | ||||||||||||
1618 | html += QString::number(format.fontWordSpacing()); | - | ||||||||||||
1619 | html += QLatin1String("px;"); | - | ||||||||||||
1620 | attributesEmitted = true; | - | ||||||||||||
1621 | } never executed: end of block | 0 | ||||||||||||
1622 | - | |||||||||||||
1623 | return never executed: attributesEmitted;return attributesEmitted; never executed: return attributesEmitted; | 0 | ||||||||||||
1624 | } | - | ||||||||||||
1625 | - | |||||||||||||
1626 | void QTextHtmlExporter::emitTextLength(const char *attribute, const QTextLength &length) | - | ||||||||||||
1627 | { | - | ||||||||||||
1628 | if (length.type() == QTextLength::VariableLength) | - | ||||||||||||
1629 | return; | - | ||||||||||||
1630 | - | |||||||||||||
1631 | html += QLatin1Char(' '); | - | ||||||||||||
1632 | html += QLatin1String(attribute); | - | ||||||||||||
1633 | html += QLatin1String("=\""); | - | ||||||||||||
1634 | html += QString::number(length.rawValue()); | - | ||||||||||||
1635 | - | |||||||||||||
1636 | if (length.type() == QTextLength::PercentageLength) | - | ||||||||||||
1637 | html += QLatin1String("%\""); | - | ||||||||||||
1638 | else | - | ||||||||||||
1639 | html += QLatin1Char('\"'); | - | ||||||||||||
1640 | } | - | ||||||||||||
1641 | - | |||||||||||||
1642 | void QTextHtmlExporter::emitAlignment(Qt::Alignment align) | - | ||||||||||||
1643 | { | - | ||||||||||||
1644 | if (align & Qt::AlignLeft) | - | ||||||||||||
1645 | return; | - | ||||||||||||
1646 | else if (align & Qt::AlignRight) | - | ||||||||||||
1647 | html += QLatin1String(" align=\"right\""); | - | ||||||||||||
1648 | else if (align & Qt::AlignHCenter) | - | ||||||||||||
1649 | html += QLatin1String(" align=\"center\""); | - | ||||||||||||
1650 | else if (align & Qt::AlignJustify) | - | ||||||||||||
1651 | html += QLatin1String(" align=\"justify\""); | - | ||||||||||||
1652 | } | - | ||||||||||||
1653 | - | |||||||||||||
1654 | void QTextHtmlExporter::emitFloatStyle(QTextFrameFormat::Position pos, StyleMode mode) | - | ||||||||||||
1655 | { | - | ||||||||||||
1656 | if (pos == QTextFrameFormat::InFlow) | - | ||||||||||||
1657 | return; | - | ||||||||||||
1658 | - | |||||||||||||
1659 | if (mode == EmitStyleTag) | - | ||||||||||||
1660 | html += QLatin1String(" style=\"float:"); | - | ||||||||||||
1661 | else | - | ||||||||||||
1662 | html += QLatin1String(" float:"); | - | ||||||||||||
1663 | - | |||||||||||||
1664 | if (pos == QTextFrameFormat::FloatLeft) | - | ||||||||||||
1665 | html += QLatin1String(" left;"); | - | ||||||||||||
1666 | else if (pos == QTextFrameFormat::FloatRight) | - | ||||||||||||
1667 | html += QLatin1String(" right;"); | - | ||||||||||||
1668 | else | - | ||||||||||||
1669 | ((!(0)) ? qt_assert_x("QTextHtmlExporter::emitFloatStyle()", "pos should be a valid enum type",__FILE__,25352541) : qt_noop()); | - | ||||||||||||
1670 | - | |||||||||||||
1671 | if (mode == EmitStyleTag) | - | ||||||||||||
1672 | html += QLatin1Char('\"'); | - | ||||||||||||
1673 | } | - | ||||||||||||
1674 | - | |||||||||||||
1675 | void QTextHtmlExporter::emitBorderStyle(QTextFrameFormat::BorderStyle style) | - | ||||||||||||
1676 | { | - | ||||||||||||
1677 | ((!(style <= QTextFrameFormat::BorderStyle_Outset)) ? qt_assert("style <= QTextFrameFormat::BorderStyle_Outset",__FILE__,25432549) : qt_noop()); | - | ||||||||||||
1678 | - | |||||||||||||
1679 | html += QLatin1String(" border-style:"); | - | ||||||||||||
1680 | - | |||||||||||||
1681 | switch (style) { | - | ||||||||||||
1682 | case QTextFrameFormat::BorderStyle_None: | - | ||||||||||||
1683 | html += QLatin1String("none"); | - | ||||||||||||
1684 | break; | - | ||||||||||||
1685 | case QTextFrameFormat::BorderStyle_Dotted: | - | ||||||||||||
1686 | html += QLatin1String("dotted"); | - | ||||||||||||
1687 | break; | - | ||||||||||||
1688 | case QTextFrameFormat::BorderStyle_Dashed: | - | ||||||||||||
1689 | html += QLatin1String("dashed"); | - | ||||||||||||
1690 | break; | - | ||||||||||||
1691 | case QTextFrameFormat::BorderStyle_Solid: | - | ||||||||||||
1692 | html += QLatin1String("solid"); | - | ||||||||||||
1693 | break; | - | ||||||||||||
1694 | case QTextFrameFormat::BorderStyle_Double: | - | ||||||||||||
1695 | html += QLatin1String("double"); | - | ||||||||||||
1696 | break; | - | ||||||||||||
1697 | case QTextFrameFormat::BorderStyle_DotDash: | - | ||||||||||||
1698 | html += QLatin1String("dot-dash"); | - | ||||||||||||
1699 | break; | - | ||||||||||||
1700 | case QTextFrameFormat::BorderStyle_DotDotDash: | - | ||||||||||||
1701 | html += QLatin1String("dot-dot-dash"); | - | ||||||||||||
1702 | break; | - | ||||||||||||
1703 | case QTextFrameFormat::BorderStyle_Groove: | - | ||||||||||||
1704 | html += QLatin1String("groove"); | - | ||||||||||||
1705 | break; | - | ||||||||||||
1706 | case QTextFrameFormat::BorderStyle_Ridge: | - | ||||||||||||
1707 | html += QLatin1String("ridge"); | - | ||||||||||||
1708 | break; | - | ||||||||||||
1709 | case QTextFrameFormat::BorderStyle_Inset: | - | ||||||||||||
1710 | html += QLatin1String("inset"); | - | ||||||||||||
1711 | break; | - | ||||||||||||
1712 | case QTextFrameFormat::BorderStyle_Outset: | - | ||||||||||||
1713 | html += QLatin1String("outset"); | - | ||||||||||||
1714 | break; | - | ||||||||||||
1715 | default: | - | ||||||||||||
1716 | ((!(false)) ? qt_assert("false",__FILE__,25822588) : qt_noop()); | - | ||||||||||||
1717 | break; | - | ||||||||||||
1718 | }; | - | ||||||||||||
1719 | - | |||||||||||||
1720 | html += QLatin1Char(';'); | - | ||||||||||||
1721 | } | - | ||||||||||||
1722 | - | |||||||||||||
1723 | void QTextHtmlExporter::emitPageBreakPolicy(QTextFormat::PageBreakFlags policy) | - | ||||||||||||
1724 | { | - | ||||||||||||
1725 | if (policy & QTextFormat::PageBreak_AlwaysBefore) | - | ||||||||||||
1726 | html += QLatin1String(" page-break-before:always;"); | - | ||||||||||||
1727 | - | |||||||||||||
1728 | if (policy & QTextFormat::PageBreak_AlwaysAfter) | - | ||||||||||||
1729 | html += QLatin1String(" page-break-after:always;"); | - | ||||||||||||
1730 | } | - | ||||||||||||
1731 | - | |||||||||||||
1732 | void QTextHtmlExporter::emitFontFamily(const QString &family) | - | ||||||||||||
1733 | { | - | ||||||||||||
1734 | html += QLatin1String(" font-family:"); | - | ||||||||||||
1735 | - | |||||||||||||
1736 | QLatin1String quote("\'"); | - | ||||||||||||
1737 | if (family.contains(QLatin1Char('\''))) | - | ||||||||||||
1738 | quote = QLatin1String("""); | - | ||||||||||||
1739 | - | |||||||||||||
1740 | html += quote; | - | ||||||||||||
1741 | html += family.toHtmlEscaped(); | - | ||||||||||||
1742 | html += quote; | - | ||||||||||||
1743 | html += QLatin1Char(';'); | - | ||||||||||||
1744 | } | - | ||||||||||||
1745 | - | |||||||||||||
1746 | void QTextHtmlExporter::emitMargins(const QString &top, const QString &bottom, const QString &left, const QString &right) | - | ||||||||||||
1747 | { | - | ||||||||||||
1748 | html += QLatin1String(" margin-top:"); | - | ||||||||||||
1749 | html += top; | - | ||||||||||||
1750 | html += QLatin1String("px;"); | - | ||||||||||||
1751 | - | |||||||||||||
1752 | html += QLatin1String(" margin-bottom:"); | - | ||||||||||||
1753 | html += bottom; | - | ||||||||||||
1754 | html += QLatin1String("px;"); | - | ||||||||||||
1755 | - | |||||||||||||
1756 | html += QLatin1String(" margin-left:"); | - | ||||||||||||
1757 | html += left; | - | ||||||||||||
1758 | html += QLatin1String("px;"); | - | ||||||||||||
1759 | - | |||||||||||||
1760 | html += QLatin1String(" margin-right:"); | - | ||||||||||||
1761 | html += right; | - | ||||||||||||
1762 | html += QLatin1String("px;"); | - | ||||||||||||
1763 | } | - | ||||||||||||
1764 | - | |||||||||||||
1765 | void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) | - | ||||||||||||
1766 | { | - | ||||||||||||
1767 | const QTextCharFormat format = fragment.charFormat(); | - | ||||||||||||
1768 | - | |||||||||||||
1769 | bool closeAnchor = false; | - | ||||||||||||
1770 | - | |||||||||||||
1771 | if (format.isAnchor()
| 0 | ||||||||||||
1772 | const QString name = format.anchorName(); | - | ||||||||||||
1773 | if (!name.isEmpty()
| 0 | ||||||||||||
1774 | html += QLatin1String("<a name=\""); | - | ||||||||||||
1775 | html += name.toHtmlEscaped(); | - | ||||||||||||
1776 | html += QLatin1String("\"></a>"); | - | ||||||||||||
1777 | } never executed: end of block | 0 | ||||||||||||
1778 | const QString href = format.anchorHref(); | - | ||||||||||||
1779 | if (!href.isEmpty()
| 0 | ||||||||||||
1780 | html += QLatin1String("<a href=\""); | - | ||||||||||||
1781 | html += href.toHtmlEscaped(); | - | ||||||||||||
1782 | html += QLatin1String("\">"); | - | ||||||||||||
1783 | closeAnchor = true; | - | ||||||||||||
1784 | } never executed: end of block | 0 | ||||||||||||
1785 | } never executed: end of block | 0 | ||||||||||||
1786 | - | |||||||||||||
1787 | QString txt = fragment.text(); | - | ||||||||||||
1788 | const bool isObject = txt.contains(QChar::ObjectReplacementCharacter); | - | ||||||||||||
1789 | const bool isImage = isObject
| 0 | ||||||||||||
1790 | - | |||||||||||||
1791 | QLatin1String styleTag("<span style=\""); | - | ||||||||||||
1792 | html += styleTag; | - | ||||||||||||
1793 | - | |||||||||||||
1794 | bool attributesEmitted = false; | - | ||||||||||||
1795 | if (!isImage
| 0 | ||||||||||||
1796 | attributesEmitted = emitCharFormatStyle(format); never executed: attributesEmitted = emitCharFormatStyle(format); | 0 | ||||||||||||
1797 | if (attributesEmitted
| 0 | ||||||||||||
1798 | html += QLatin1String("\">"); never executed: html += QLatin1String("\">"); | 0 | ||||||||||||
1799 | else | - | ||||||||||||
1800 | html.chop(qstrlen(styleTag.latin1()));size()); never executed: html.chop(styleTag.size()); | 0 | ||||||||||||
1801 | - | |||||||||||||
1802 | if (isObject
| 0 | ||||||||||||
1803 | for (int i = 0; isImage
| 0 | ||||||||||||
1804 | QTextImageFormat imgFmt = format.toImageFormat(); | - | ||||||||||||
1805 | - | |||||||||||||
1806 | html += QLatin1String("<img"); | - | ||||||||||||
1807 | - | |||||||||||||
1808 | if (imgFmt.hasProperty(QTextFormat::ImageName)
| 0 | ||||||||||||
1809 | emitAttribute("src", imgFmt.name()); never executed: emitAttribute("src", imgFmt.name()); | 0 | ||||||||||||
1810 | - | |||||||||||||
1811 | if (imgFmt.hasProperty(QTextFormat::ImageWidth)
| 0 | ||||||||||||
1812 | emitAttribute("width", QString::number(imgFmt.width())); never executed: emitAttribute("width", QString::number(imgFmt.width())); | 0 | ||||||||||||
1813 | - | |||||||||||||
1814 | if (imgFmt.hasProperty(QTextFormat::ImageHeight)
| 0 | ||||||||||||
1815 | emitAttribute("height", QString::number(imgFmt.height())); never executed: emitAttribute("height", QString::number(imgFmt.height())); | 0 | ||||||||||||
1816 | - | |||||||||||||
1817 | if (imgFmt.verticalAlignment() == QTextCharFormat::AlignMiddle
| 0 | ||||||||||||
1818 | html += QLatin1String(" style=\"vertical-align: middle;\""); never executed: html += QLatin1String(" style=\"vertical-align: middle;\""); | 0 | ||||||||||||
1819 | else if (imgFmt.verticalAlignment() == QTextCharFormat::AlignTop
| 0 | ||||||||||||
1820 | html += QLatin1String(" style=\"vertical-align: top;\""); never executed: html += QLatin1String(" style=\"vertical-align: top;\""); | 0 | ||||||||||||
1821 | - | |||||||||||||
1822 | if (QTextFrame *imageFrame = qobject_cast<QTextFrame *>(doc->objectForFormat(imgFmt))
| 0 | ||||||||||||
1823 | emitFloatStyle(imageFrame->frameFormat().position()); never executed: emitFloatStyle(imageFrame->frameFormat().position()); | 0 | ||||||||||||
1824 | - | |||||||||||||
1825 | html += QLatin1String(" />"); | - | ||||||||||||
1826 | } never executed: end of block | 0 | ||||||||||||
1827 | } never executed: else {end of block | 0 | ||||||||||||
1828 | ((!(!txt.contains(QChar::ObjectReplacementCharacter))) ? qt_assert("!txt.contains(QChar::ObjectReplacementCharacter)",__FILE__,26942700) : qt_noop()); | - | ||||||||||||
1829 | - | |||||||||||||
1830 | txt = txt.toHtmlEscaped(); | - | ||||||||||||
1831 | - | |||||||||||||
1832 | - | |||||||||||||
1833 | QString forcedLineBreakRegExp = QString::fromLatin1("[\\na]"); | - | ||||||||||||
1834 | forcedLineBreakRegExp[3] = QChar::LineSeparator; | - | ||||||||||||
1835 | - | |||||||||||||
1836 | const QStringList lineshtml =+= txt.splitreplace(QRegExp(forcedLineBreakRegExp)); | - | ||||||||||||
for (int i = 0; i < lines.count(); ++i) { | ||||||||||||||
if (i > 0) | ||||||||||||||
html +=), QLatin1String("<br />"); | ||||||||||||||
html += lines.at(i); | ||||||||||||||
})); | ||||||||||||||
1837 | } never executed: end of block | 0 | ||||||||||||
1838 | - | |||||||||||||
1839 | if (attributesEmitted
| 0 | ||||||||||||
1840 | html += QLatin1String("</span>"); never executed: html += QLatin1String("</span>"); | 0 | ||||||||||||
1841 | - | |||||||||||||
1842 | if (closeAnchor
| 0 | ||||||||||||
1843 | html += QLatin1String("</a>"); never executed: html += QLatin1String("</a>"); | 0 | ||||||||||||
1844 | } never executed: end of block | 0 | ||||||||||||
1845 | - | |||||||||||||
1846 | static bool isOrderedList(int style) | - | ||||||||||||
1847 | { | - | ||||||||||||
1848 | return style == QTextListFormat::ListDecimal || style == QTextListFormat::ListLowerAlpha | - | ||||||||||||
1849 | || style == QTextListFormat::ListUpperAlpha | - | ||||||||||||
1850 | || style == QTextListFormat::ListUpperRoman | - | ||||||||||||
1851 | || style == QTextListFormat::ListLowerRoman | - | ||||||||||||
1852 | ; | - | ||||||||||||
1853 | } | - | ||||||||||||
1854 | - | |||||||||||||
1855 | void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block) | - | ||||||||||||
1856 | { | - | ||||||||||||
1857 | QTextBlockFormat format = block.blockFormat(); | - | ||||||||||||
1858 | emitAlignment(format.alignment()); | - | ||||||||||||
1859 | - | |||||||||||||
1860 | - | |||||||||||||
1861 | - | |||||||||||||
1862 | if (block.textDirection() == Qt::RightToLeft
| 0 | ||||||||||||
1863 | html += QLatin1String(" dir='rtl'"); never executed: html += QLatin1String(" dir='rtl'"); | 0 | ||||||||||||
1864 | - | |||||||||||||
1865 | QLatin1String style(" style=\""); | - | ||||||||||||
1866 | html += style; | - | ||||||||||||
1867 | - | |||||||||||||
1868 | const bool emptyBlock = block.begin().atEnd(); | - | ||||||||||||
1869 | if (emptyBlock
| 0 | ||||||||||||
1870 | html += QLatin1String("-qt-paragraph-type:empty;"); | - | ||||||||||||
1871 | } never executed: end of block | 0 | ||||||||||||
1872 | - | |||||||||||||
1873 | emitMargins(QString::number(format.topMargin()), | - | ||||||||||||
1874 | QString::number(format.bottomMargin()), | - | ||||||||||||
1875 | QString::number(format.leftMargin()), | - | ||||||||||||
1876 | QString::number(format.rightMargin())); | - | ||||||||||||
1877 | - | |||||||||||||
1878 | html += QLatin1String(" -qt-block-indent:"); | - | ||||||||||||
1879 | html += QString::number(format.indent()); | - | ||||||||||||
1880 | html += QLatin1Char(';'); | - | ||||||||||||
1881 | - | |||||||||||||
1882 | html += QLatin1String(" text-indent:"); | - | ||||||||||||
1883 | html += QString::number(format.textIndent()); | - | ||||||||||||
1884 | html += QLatin1String("px;"); | - | ||||||||||||
1885 | - | |||||||||||||
1886 | if (block.userState() != -1
| 0 | ||||||||||||
1887 | html += QLatin1String(" -qt-user-state:"); | - | ||||||||||||
1888 | html += QString::number(block.userState()); | - | ||||||||||||
1889 | html += QLatin1Char(';'); | - | ||||||||||||
1890 | } never executed: end of block | 0 | ||||||||||||
1891 | - | |||||||||||||
1892 | if (format.lineHeightType() != QTextBlockFormat::SingleHeight
| 0 | ||||||||||||
1893 | html += QLatin1String(" line-height:") | - | ||||||||||||
1894 | + QString::number(format.lineHeight()); | - | ||||||||||||
1895 | switch (format.lineHeightType()) { | - | ||||||||||||
1896 | case never executed: QTextBlockFormat::ProportionalHeight:case QTextBlockFormat::ProportionalHeight: never executed: case QTextBlockFormat::ProportionalHeight: | 0 | ||||||||||||
1897 | html += QLatin1String("%;"); | - | ||||||||||||
1898 | break; never executed: break; | 0 | ||||||||||||
1899 | case never executed: QTextBlockFormat::FixedHeight:case QTextBlockFormat::FixedHeight: never executed: case QTextBlockFormat::FixedHeight: | 0 | ||||||||||||
1900 | html += QLatin1String("; -qt-line-height-type: fixed;"); | - | ||||||||||||
1901 | break; never executed: break; | 0 | ||||||||||||
1902 | case never executed: QTextBlockFormat::MinimumHeight:case QTextBlockFormat::MinimumHeight: never executed: case QTextBlockFormat::MinimumHeight: | 0 | ||||||||||||
1903 | html += QLatin1String(" min-height:"px;"); | - | ||||||||||||
1904 | break; never executed: break; | 0 | ||||||||||||
1905 | case never executed: QTextBlockFormat::LineDistanceHeight:case QTextBlockFormat::LineDistanceHeight: never executed: case QTextBlockFormat::LineDistanceHeight: | 0 | ||||||||||||
1906 | html += QLatin1String("; -qt-line-spacingheight-type: line-distance;"); | - | ||||||||||||
1907 | break; never executed: break; | 0 | ||||||||||||
case QTextBlockFormat::SingleHeight: never executed: break; | ||||||||||||||
1908 | default never executed: :default: never executed: default: | 0 | ||||||||||||
1909 | break; | - | ||||||||||||
} | ||||||||||||||
html += QString::number(format.lineHeight()); | ||||||||||||||
if (format.lineHeightType() == QTextBlockFormat::ProportionalHeight) | ||||||||||||||
html += QLatin1String("%;"); | ||||||||||||||
else | ||||||||||||||
html += QLatin1String("px;"); | ||||||||||||||
1910 | break; never executed: break; | 0 | ||||||||||||
1911 | } | - | ||||||||||||
1912 | } | - | ||||||||||||
1913 | - | |||||||||||||
1914 | emitPageBreakPolicy(format.pageBreakPolicy()); | - | ||||||||||||
1915 | - | |||||||||||||
1916 | QTextCharFormat diff; | - | ||||||||||||
1917 | if (emptyBlock
| 0 | ||||||||||||
1918 | const QTextCharFormat blockCharFmt = block.charFormat(); | - | ||||||||||||
1919 | diff = formatDifference(defaultCharFormat, blockCharFmt).toCharFormat(); | - | ||||||||||||
1920 | } never executed: end of block | 0 | ||||||||||||
1921 | - | |||||||||||||
1922 | diff.clearProperty(QTextFormat::BackgroundBrush); | - | ||||||||||||
1923 | if (format.hasProperty(QTextFormat::BackgroundBrush)
| 0 | ||||||||||||
1924 | QBrush bg = format.background(); | - | ||||||||||||
1925 | if (bg.style() != Qt::NoBrush
| 0 | ||||||||||||
1926 | diff.setProperty(QTextFormat::BackgroundBrush, format.property(QTextFormat::BackgroundBrush)); never executed: diff.setProperty(QTextFormat::BackgroundBrush, format.property(QTextFormat::BackgroundBrush)); | 0 | ||||||||||||
1927 | } never executed: end of block | 0 | ||||||||||||
1928 | - | |||||||||||||
1929 | if (!diff.properties().isEmpty()
| 0 | ||||||||||||
1930 | emitCharFormatStyle(diff); never executed: emitCharFormatStyle(diff); | 0 | ||||||||||||
1931 | - | |||||||||||||
1932 | html += QLatin1Char('"'); | - | ||||||||||||
1933 | - | |||||||||||||
1934 | } never executed: end of block | 0 | ||||||||||||
1935 | - | |||||||||||||
1936 | void QTextHtmlExporter::emitBlock(const QTextBlock &block) | - | ||||||||||||
1937 | { | - | ||||||||||||
1938 | if (block.begin().atEnd()) { | - | ||||||||||||
1939 | - | |||||||||||||
1940 | int p = block.position(); | - | ||||||||||||
1941 | if (p > 0) | - | ||||||||||||
1942 | --p; | - | ||||||||||||
1943 | QTextDocumentPrivate::FragmentIterator frag = doc->docHandle()->find(p); | - | ||||||||||||
1944 | QChar ch = doc->docHandle()->buffer().at(frag->stringPosition); | - | ||||||||||||
1945 | if (ch == QChar(0xfdd0) | - | ||||||||||||
1946 | || ch == QChar(0xfdd1)) | - | ||||||||||||
1947 | return; | - | ||||||||||||
1948 | } | - | ||||||||||||
1949 | - | |||||||||||||
1950 | html += QLatin1Char('\n'); | - | ||||||||||||
1951 | - | |||||||||||||
1952 | - | |||||||||||||
1953 | - | |||||||||||||
1954 | QTextCharFormat oldDefaultCharFormat = defaultCharFormat; | - | ||||||||||||
1955 | - | |||||||||||||
1956 | QTextList *list = block.textList(); | - | ||||||||||||
1957 | if (list) { | - | ||||||||||||
1958 | if (list->itemNumber(block) == 0) { | - | ||||||||||||
1959 | const QTextListFormat format = list->format(); | - | ||||||||||||
1960 | const int style = format.style(); | - | ||||||||||||
1961 | switch (style) { | - | ||||||||||||
1962 | case QTextListFormat::ListDecimal: html += QLatin1String("<ol"); break; | - | ||||||||||||
1963 | case QTextListFormat::ListDisc: html += QLatin1String("<ul"); break; | - | ||||||||||||
1964 | case QTextListFormat::ListCircle: html += QLatin1String("<ul type=\"circle\""); break; | - | ||||||||||||
1965 | case QTextListFormat::ListSquare: html += QLatin1String("<ul type=\"square\""); break; | - | ||||||||||||
1966 | case QTextListFormat::ListLowerAlpha: html += QLatin1String("<ol type=\"a\""); break; | - | ||||||||||||
1967 | case QTextListFormat::ListUpperAlpha: html += QLatin1String("<ol type=\"A\""); break; | - | ||||||||||||
1968 | case QTextListFormat::ListLowerRoman: html += QLatin1String("<ol type=\"i\""); break; | - | ||||||||||||
1969 | case QTextListFormat::ListUpperRoman: html += QLatin1String("<ol type=\"I\""); break; | - | ||||||||||||
1970 | default: html += QLatin1String("<ul"); | - | ||||||||||||
1971 | } | - | ||||||||||||
1972 | - | |||||||||||||
1973 | QString styleString = QString::fromLatin1("margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;"); | - | ||||||||||||
1974 | - | |||||||||||||
1975 | if (format.hasProperty(QTextFormat::ListIndent)) { | - | ||||||||||||
1976 | styleString += QLatin1String(" -qt-list-indent: "); | - | ||||||||||||
1977 | styleString += QString::number(format.indent()); | - | ||||||||||||
1978 | styleString += QLatin1Char(';'); | - | ||||||||||||
1979 | } | - | ||||||||||||
1980 | - | |||||||||||||
1981 | if (format.hasProperty(QTextFormat::ListNumberPrefix)) { | - | ||||||||||||
1982 | QString numberPrefix = format.numberPrefix(); | - | ||||||||||||
1983 | numberPrefix.replace(QLatin1Char('"'), QLatin1String("\\22")); | - | ||||||||||||
1984 | numberPrefix.replace(QLatin1Char('\''), QLatin1String("\\27")); | - | ||||||||||||
1985 | styleString += QLatin1String(" -qt-list-number-prefix: "); | - | ||||||||||||
1986 | styleString += QLatin1Char('\''); | - | ||||||||||||
1987 | styleString += numberPrefix; | - | ||||||||||||
1988 | styleString += QLatin1Char('\''); | - | ||||||||||||
1989 | styleString += QLatin1Char(';'); | - | ||||||||||||
1990 | } | - | ||||||||||||
1991 | - | |||||||||||||
1992 | if (format.hasProperty(QTextFormat::ListNumberSuffix)) { | - | ||||||||||||
1993 | if (format.numberSuffix() != QLatin1String(".")) { | - | ||||||||||||
1994 | QString numberSuffix = format.numberSuffix(); | - | ||||||||||||
1995 | numberSuffix.replace(QLatin1Char('"'), QLatin1String("\\22")); | - | ||||||||||||
1996 | numberSuffix.replace(QLatin1Char('\''), QLatin1String("\\27")); | - | ||||||||||||
1997 | styleString += QLatin1String(" -qt-list-number-suffix: "); | - | ||||||||||||
1998 | styleString += QLatin1Char('\''); | - | ||||||||||||
1999 | styleString += numberSuffix; | - | ||||||||||||
2000 | styleString += QLatin1Char('\''); | - | ||||||||||||
2001 | styleString += QLatin1Char(';'); | - | ||||||||||||
2002 | } | - | ||||||||||||
2003 | } | - | ||||||||||||
2004 | - | |||||||||||||
2005 | html += QLatin1String(" style=\""); | - | ||||||||||||
2006 | html += styleString; | - | ||||||||||||
2007 | html += QLatin1String("\">"); | - | ||||||||||||
2008 | } | - | ||||||||||||
2009 | - | |||||||||||||
2010 | html += QLatin1String("<li"); | - | ||||||||||||
2011 | - | |||||||||||||
2012 | const QTextCharFormat blockFmt = formatDifference(defaultCharFormat, block.charFormat()).toCharFormat(); | - | ||||||||||||
2013 | if (!blockFmt.properties().isEmpty()) { | - | ||||||||||||
2014 | html += QLatin1String(" style=\""); | - | ||||||||||||
2015 | emitCharFormatStyle(blockFmt); | - | ||||||||||||
2016 | html += QLatin1Char('\"'); | - | ||||||||||||
2017 | - | |||||||||||||
2018 | defaultCharFormat.merge(block.charFormat()); | - | ||||||||||||
2019 | } | - | ||||||||||||
2020 | } | - | ||||||||||||
2021 | - | |||||||||||||
2022 | const QTextBlockFormat blockFormat = block.blockFormat(); | - | ||||||||||||
2023 | if (blockFormat.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) { | - | ||||||||||||
2024 | html += QLatin1String("<hr"); | - | ||||||||||||
2025 | - | |||||||||||||
2026 | QTextLength width = blockFormat.lengthProperty(QTextFormat::BlockTrailingHorizontalRulerWidth); | - | ||||||||||||
2027 | if (width.type() != QTextLength::VariableLength) | - | ||||||||||||
2028 | emitTextLength("width", width); | - | ||||||||||||
2029 | else | - | ||||||||||||
2030 | html += QLatin1Char(' '); | - | ||||||||||||
2031 | - | |||||||||||||
2032 | html += QLatin1String("/>"); | - | ||||||||||||
2033 | return; | - | ||||||||||||
2034 | } | - | ||||||||||||
2035 | - | |||||||||||||
2036 | const bool pre = blockFormat.nonBreakableLines(); | - | ||||||||||||
2037 | if (pre) { | - | ||||||||||||
2038 | if (list) | - | ||||||||||||
2039 | html += QLatin1Char('>'); | - | ||||||||||||
2040 | html += QLatin1String("<pre"); | - | ||||||||||||
2041 | } else if (!list) { | - | ||||||||||||
2042 | html += QLatin1String("<p"); | - | ||||||||||||
2043 | } | - | ||||||||||||
2044 | - | |||||||||||||
2045 | emitBlockAttributes(block); | - | ||||||||||||
2046 | - | |||||||||||||
2047 | html += QLatin1Char('>'); | - | ||||||||||||
2048 | if (block.begin().atEnd()) | - | ||||||||||||
2049 | html += QLatin1String("<br />"); | - | ||||||||||||
2050 | - | |||||||||||||
2051 | QTextBlock::Iterator it = block.begin(); | - | ||||||||||||
2052 | if (fragmentMarkers && !it.atEnd() && block == doc->begin()) | - | ||||||||||||
2053 | html += QLatin1String("<!--StartFragment-->"); | - | ||||||||||||
2054 | - | |||||||||||||
2055 | for (; !it.atEnd(); ++it) | - | ||||||||||||
2056 | emitFragment(it.fragment()); | - | ||||||||||||
2057 | - | |||||||||||||
2058 | if (fragmentMarkers && block.position() + block.length() == doc->docHandle()->length()) | - | ||||||||||||
2059 | html += QLatin1String("<!--EndFragment-->"); | - | ||||||||||||
2060 | - | |||||||||||||
2061 | if (pre) | - | ||||||||||||
2062 | html += QLatin1String("</pre>"); | - | ||||||||||||
2063 | else if (list) | - | ||||||||||||
2064 | html += QLatin1String("</li>"); | - | ||||||||||||
2065 | else | - | ||||||||||||
2066 | html += QLatin1String("</p>"); | - | ||||||||||||
2067 | - | |||||||||||||
2068 | if (list) { | - | ||||||||||||
2069 | if (list->itemNumber(block) == list->count() - 1) { | - | ||||||||||||
2070 | if (isOrderedList(list->format().style())) | - | ||||||||||||
2071 | html += QLatin1String("</ol>"); | - | ||||||||||||
2072 | else | - | ||||||||||||
2073 | html += QLatin1String("</ul>"); | - | ||||||||||||
2074 | } | - | ||||||||||||
2075 | } | - | ||||||||||||
2076 | - | |||||||||||||
2077 | defaultCharFormat = oldDefaultCharFormat; | - | ||||||||||||
2078 | } | - | ||||||||||||
2079 | - | |||||||||||||
2080 | extern bool qHasPixmapTexture(const QBrush& brush); | - | ||||||||||||
2081 | - | |||||||||||||
2082 | QString QTextHtmlExporter::findUrlForImage(const QTextDocument *doc, qint64 cacheKey, bool isPixmap) | - | ||||||||||||
2083 | { | - | ||||||||||||
2084 | QString url; | - | ||||||||||||
2085 | if (!doc) | - | ||||||||||||
2086 | return url; | - | ||||||||||||
2087 | - | |||||||||||||
2088 | if (QTextDocument *parent = qobject_cast<QTextDocument *>(doc->parent())) | - | ||||||||||||
2089 | return findUrlForImage(parent, cacheKey, isPixmap); | - | ||||||||||||
2090 | - | |||||||||||||
2091 | if (doc && doc->docHandle()) { | - | ||||||||||||
2092 | QTextDocumentPrivate *priv = doc->docHandle(); | - | ||||||||||||
2093 | QMap<QUrl, QVariant>::const_iterator it = priv->cachedResources.constBegin(); | - | ||||||||||||
2094 | for (; it != priv->cachedResources.constEnd(); ++it) { | - | ||||||||||||
2095 | - | |||||||||||||
2096 | const QVariant &v = it.value(); | - | ||||||||||||
2097 | if (v.type() == QVariant::Image && !isPixmap) { | - | ||||||||||||
2098 | if (qvariant_cast<QImage>(v).cacheKey() == cacheKey) | - | ||||||||||||
2099 | break; | - | ||||||||||||
2100 | } | - | ||||||||||||
2101 | - | |||||||||||||
2102 | if (v.type() == QVariant::Pixmap && isPixmap) { | - | ||||||||||||
2103 | if (qvariant_cast<QPixmap>(v).cacheKey() == cacheKey) | - | ||||||||||||
2104 | break; | - | ||||||||||||
2105 | } | - | ||||||||||||
2106 | } | - | ||||||||||||
2107 | - | |||||||||||||
2108 | if (it != priv->cachedResources.constEnd()) | - | ||||||||||||
2109 | url = it.key().toString(); | - | ||||||||||||
2110 | } | - | ||||||||||||
2111 | - | |||||||||||||
2112 | return url; | - | ||||||||||||
2113 | } | - | ||||||||||||
2114 | - | |||||||||||||
2115 | void QTextDocumentPrivate::mergeCachedResources(const QTextDocumentPrivate *priv) | - | ||||||||||||
2116 | { | - | ||||||||||||
2117 | if (!priv) | - | ||||||||||||
2118 | return; | - | ||||||||||||
2119 | - | |||||||||||||
2120 | cachedResources.unite(priv->cachedResources); | - | ||||||||||||
2121 | } | - | ||||||||||||
2122 | - | |||||||||||||
2123 | void QTextHtmlExporter::emitBackgroundAttribute(const QTextFormat &format) | - | ||||||||||||
2124 | { | - | ||||||||||||
2125 | if (format.hasProperty(QTextFormat::BackgroundImageUrl)) { | - | ||||||||||||
2126 | QString url = format.property(QTextFormat::BackgroundImageUrl).toString(); | - | ||||||||||||
2127 | emitAttribute("background", url); | - | ||||||||||||
2128 | } else { | - | ||||||||||||
2129 | const QBrush &brush = format.background(); | - | ||||||||||||
2130 | if (brush.style() == Qt::SolidPattern) { | - | ||||||||||||
2131 | emitAttribute("bgcolor", colorValue(brush.color())); | - | ||||||||||||
2132 | } else if (brush.style() == Qt::TexturePattern) { | - | ||||||||||||
2133 | const bool isPixmap = qHasPixmapTexture(brush); | - | ||||||||||||
2134 | const qint64 cacheKey = isPixmap ? brush.texture().cacheKey() : brush.textureImage().cacheKey(); | - | ||||||||||||
2135 | - | |||||||||||||
2136 | const QString url = findUrlForImage(doc, cacheKey, isPixmap); | - | ||||||||||||
2137 | - | |||||||||||||
2138 | if (!url.isEmpty()) | - | ||||||||||||
2139 | emitAttribute("background", url); | - | ||||||||||||
2140 | } | - | ||||||||||||
2141 | } | - | ||||||||||||
2142 | } | - | ||||||||||||
2143 | - | |||||||||||||
2144 | void QTextHtmlExporter::emitTable(const QTextTable *table) | - | ||||||||||||
2145 | { | - | ||||||||||||
2146 | QTextTableFormat format = table->format(); | - | ||||||||||||
2147 | - | |||||||||||||
2148 | html += QLatin1String("\n<table"); | - | ||||||||||||
2149 | - | |||||||||||||
2150 | if (format.hasProperty(QTextFormat::FrameBorder)) | - | ||||||||||||
2151 | emitAttribute("border", QString::number(format.border())); | - | ||||||||||||
2152 | - | |||||||||||||
2153 | emitFrameStyle(format, TableFrame); | - | ||||||||||||
2154 | - | |||||||||||||
2155 | emitAlignment(format.alignment()); | - | ||||||||||||
2156 | emitTextLength("width", format.width()); | - | ||||||||||||
2157 | - | |||||||||||||
2158 | if (format.hasProperty(QTextFormat::TableCellSpacing)) | - | ||||||||||||
2159 | emitAttribute("cellspacing", QString::number(format.cellSpacing())); | - | ||||||||||||
2160 | if (format.hasProperty(QTextFormat::TableCellPadding)) | - | ||||||||||||
2161 | emitAttribute("cellpadding", QString::number(format.cellPadding())); | - | ||||||||||||
2162 | - | |||||||||||||
2163 | emitBackgroundAttribute(format); | - | ||||||||||||
2164 | - | |||||||||||||
2165 | html += QLatin1Char('>'); | - | ||||||||||||
2166 | - | |||||||||||||
2167 | const int rows = table->rows(); | - | ||||||||||||
2168 | const int columns = table->columns(); | - | ||||||||||||
2169 | - | |||||||||||||
2170 | QVector<QTextLength> columnWidths = format.columnWidthConstraints(); | - | ||||||||||||
2171 | if (columnWidths.isEmpty()) { | - | ||||||||||||
2172 | columnWidths.resize(columns); | - | ||||||||||||
2173 | columnWidths.fill(QTextLength()); | - | ||||||||||||
2174 | } | - | ||||||||||||
2175 | ((!(columnWidths.count() == columns)) ? qt_assert("columnWidths.count() == columns",__FILE__,3047) : qt_noop()); | - | ||||||||||||
2176 | - | |||||||||||||
2177 | QVarLengthArray<bool> widthEmittedForColumn(columns); | - | ||||||||||||
2178 | for (int i = 0; i < columns; ++i) | - | ||||||||||||
2179 | widthEmittedForColumn[i] = false; | - | ||||||||||||
2180 | - | |||||||||||||
2181 | const int headerRowCount = qMin(format.headerRowCount(), rows); | - | ||||||||||||
2182 | if (headerRowCount > 0) | - | ||||||||||||
2183 | html += QLatin1String("<thead>"); | - | ||||||||||||
2184 | - | |||||||||||||
2185 | for (int row = 0; row < rows; ++row) { | - | ||||||||||||
2186 | html += QLatin1String("\n<tr>"); | - | ||||||||||||
2187 | - | |||||||||||||
2188 | for (int col = 0; col < columns; ++col) { | - | ||||||||||||
2189 | const QTextTableCell cell = table->cellAt(row, col); | - | ||||||||||||
2190 | - | |||||||||||||
2191 | - | |||||||||||||
2192 | if (cell.row() != row) | - | ||||||||||||
2193 | continue; | - | ||||||||||||
2194 | - | |||||||||||||
2195 | if (cell.column() != col) | - | ||||||||||||
2196 | continue; | - | ||||||||||||
2197 | - | |||||||||||||
2198 | html += QLatin1String("\n<td"); | - | ||||||||||||
2199 | - | |||||||||||||
2200 | if (!widthEmittedForColumn[col] && cell.columnSpan() == 1) { | - | ||||||||||||
2201 | emitTextLength("width", columnWidths.at(col)); | - | ||||||||||||
2202 | widthEmittedForColumn[col] = true; | - | ||||||||||||
2203 | } | - | ||||||||||||
2204 | - | |||||||||||||
2205 | if (cell.columnSpan() > 1) | - | ||||||||||||
2206 | emitAttribute("colspan", QString::number(cell.columnSpan())); | - | ||||||||||||
2207 | - | |||||||||||||
2208 | if (cell.rowSpan() > 1) | - | ||||||||||||
2209 | emitAttribute("rowspan", QString::number(cell.rowSpan())); | - | ||||||||||||
2210 | - | |||||||||||||
2211 | const QTextTableCellFormat cellFormat = cell.format().toTableCellFormat(); | - | ||||||||||||
2212 | emitBackgroundAttribute(cellFormat); | - | ||||||||||||
2213 | - | |||||||||||||
2214 | QTextCharFormat oldDefaultCharFormat = defaultCharFormat; | - | ||||||||||||
2215 | - | |||||||||||||
2216 | QTextCharFormat::VerticalAlignment valign = cellFormat.verticalAlignment(); | - | ||||||||||||
2217 | - | |||||||||||||
2218 | QString styleString; | - | ||||||||||||
2219 | if (valign >= QTextCharFormat::AlignMiddle && valign <= QTextCharFormat::AlignBottom) { | - | ||||||||||||
2220 | styleString += QLatin1String(" vertical-align:"); | - | ||||||||||||
2221 | switch (valign) { | - | ||||||||||||
2222 | case QTextCharFormat::AlignMiddle: | - | ||||||||||||
2223 | styleString += QLatin1String("middle"); | - | ||||||||||||
2224 | break; | - | ||||||||||||
2225 | case QTextCharFormat::AlignTop: | - | ||||||||||||
2226 | styleString += QLatin1String("top"); | - | ||||||||||||
2227 | break; | - | ||||||||||||
2228 | case QTextCharFormat::AlignBottom: | - | ||||||||||||
2229 | styleString += QLatin1String("bottom"); | - | ||||||||||||
2230 | break; | - | ||||||||||||
2231 | default: | - | ||||||||||||
2232 | break; | - | ||||||||||||
2233 | } | - | ||||||||||||
2234 | styleString += QLatin1Char(';'); | - | ||||||||||||
2235 | - | |||||||||||||
2236 | QTextCharFormat temp; | - | ||||||||||||
2237 | temp.setVerticalAlignment(valign); | - | ||||||||||||
2238 | defaultCharFormat.merge(temp); | - | ||||||||||||
2239 | } | - | ||||||||||||
2240 | - | |||||||||||||
2241 | if (cellFormat.hasProperty(QTextFormat::TableCellLeftPadding)) | - | ||||||||||||
2242 | styleString += QLatin1String(" padding-left:") + QString::number(cellFormat.leftPadding()) + QLatin1Char(';'); | - | ||||||||||||
2243 | if (cellFormat.hasProperty(QTextFormat::TableCellRightPadding)) | - | ||||||||||||
2244 | styleString += QLatin1String(" padding-right:") + QString::number(cellFormat.rightPadding()) + QLatin1Char(';'); | - | ||||||||||||
2245 | if (cellFormat.hasProperty(QTextFormat::TableCellTopPadding)) | - | ||||||||||||
2246 | styleString += QLatin1String(" padding-top:") + QString::number(cellFormat.topPadding()) + QLatin1Char(';'); | - | ||||||||||||
2247 | if (cellFormat.hasProperty(QTextFormat::TableCellBottomPadding)) | - | ||||||||||||
2248 | styleString += QLatin1String(" padding-bottom:") + QString::number(cellFormat.bottomPadding()) + QLatin1Char(';'); | - | ||||||||||||
2249 | - | |||||||||||||
2250 | if (!styleString.isEmpty()) | - | ||||||||||||
2251 | html += QLatin1String(" style=\"") + styleString + QLatin1Char('\"'); | - | ||||||||||||
2252 | - | |||||||||||||
2253 | html += QLatin1Char('>'); | - | ||||||||||||
2254 | - | |||||||||||||
2255 | emitFrame(cell.begin()); | - | ||||||||||||
2256 | - | |||||||||||||
2257 | html += QLatin1String("</td>"); | - | ||||||||||||
2258 | - | |||||||||||||
2259 | defaultCharFormat = oldDefaultCharFormat; | - | ||||||||||||
2260 | } | - | ||||||||||||
2261 | - | |||||||||||||
2262 | html += QLatin1String("</tr>"); | - | ||||||||||||
2263 | if (headerRowCount > 0 && row == headerRowCount - 1) | - | ||||||||||||
2264 | html += QLatin1String("</thead>"); | - | ||||||||||||
2265 | } | - | ||||||||||||
2266 | - | |||||||||||||
2267 | html += QLatin1String("</table>"); | - | ||||||||||||
2268 | } | - | ||||||||||||
2269 | - | |||||||||||||
2270 | void QTextHtmlExporter::emitFrame(QTextFrame::Iterator frameIt) | - | ||||||||||||
2271 | { | - | ||||||||||||
2272 | if (!frameIt.atEnd()) { | - | ||||||||||||
2273 | QTextFrame::Iterator next = frameIt; | - | ||||||||||||
2274 | ++next; | - | ||||||||||||
2275 | if (next.atEnd() | - | ||||||||||||
2276 | && frameIt.currentFrame() == 0 | - | ||||||||||||
2277 | && frameIt.parentFrame() != doc->rootFrame() | - | ||||||||||||
2278 | && frameIt.currentBlock().begin().atEnd()) | - | ||||||||||||
2279 | return; | - | ||||||||||||
2280 | } | - | ||||||||||||
2281 | - | |||||||||||||
2282 | for (QTextFrame::Iterator it = frameIt; | - | ||||||||||||
2283 | !it.atEnd(); ++it) { | - | ||||||||||||
2284 | if (QTextFrame *f = it.currentFrame()) { | - | ||||||||||||
2285 | if (QTextTable *table = qobject_cast<QTextTable *>(f)) { | - | ||||||||||||
2286 | emitTable(table); | - | ||||||||||||
2287 | } else { | - | ||||||||||||
2288 | emitTextFrame(f); | - | ||||||||||||
2289 | } | - | ||||||||||||
2290 | } else if (it.currentBlock().isValid()) { | - | ||||||||||||
2291 | emitBlock(it.currentBlock()); | - | ||||||||||||
2292 | } | - | ||||||||||||
2293 | } | - | ||||||||||||
2294 | } | - | ||||||||||||
2295 | - | |||||||||||||
2296 | void QTextHtmlExporter::emitTextFrame(const QTextFrame *f) | - | ||||||||||||
2297 | { | - | ||||||||||||
2298 | FrameType frameType = f->parentFrame() ? TextFrame : RootFrame; | - | ||||||||||||
2299 | - | |||||||||||||
2300 | html += QLatin1String("\n<table"); | - | ||||||||||||
2301 | QTextFrameFormat format = f->frameFormat(); | - | ||||||||||||
2302 | - | |||||||||||||
2303 | if (format.hasProperty(QTextFormat::FrameBorder)) | - | ||||||||||||
2304 | emitAttribute("border", QString::number(format.border())); | - | ||||||||||||
2305 | - | |||||||||||||
2306 | emitFrameStyle(format, frameType); | - | ||||||||||||
2307 | - | |||||||||||||
2308 | emitTextLength("width", format.width()); | - | ||||||||||||
2309 | emitTextLength("height", format.height()); | - | ||||||||||||
2310 | - | |||||||||||||
2311 | - | |||||||||||||
2312 | if (frameType != RootFrame) | - | ||||||||||||
2313 | emitBackgroundAttribute(format); | - | ||||||||||||
2314 | - | |||||||||||||
2315 | html += QLatin1Char('>'); | - | ||||||||||||
2316 | html += QLatin1String("\n<tr>\n<td style=\"border: none;\">"); | - | ||||||||||||
2317 | emitFrame(f->begin()); | - | ||||||||||||
2318 | html += QLatin1String("</td></tr></table>"); | - | ||||||||||||
2319 | } | - | ||||||||||||
2320 | - | |||||||||||||
2321 | void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType frameType) | - | ||||||||||||
2322 | { | - | ||||||||||||
2323 | QLatin1String styleAttribute(" style=\""); | - | ||||||||||||
2324 | html += styleAttribute; | - | ||||||||||||
2325 | const int originalHtmlLength = html.length(); | - | ||||||||||||
2326 | - | |||||||||||||
2327 | if (frameType == TextFrame
| 0 | ||||||||||||
2328 | html += QLatin1String("-qt-table-type: frame;"); never executed: html += QLatin1String("-qt-table-type: frame;"); | 0 | ||||||||||||
2329 | else if (frameType == RootFrame
| 0 | ||||||||||||
2330 | html += QLatin1String("-qt-table-type: root;"); never executed: html += QLatin1String("-qt-table-type: root;"); | 0 | ||||||||||||
2331 | - | |||||||||||||
2332 | const QTextFrameFormat defaultFormat; | - | ||||||||||||
2333 | - | |||||||||||||
2334 | emitFloatStyle(format.position(), OmitStyleTag); | - | ||||||||||||
2335 | emitPageBreakPolicy(format.pageBreakPolicy()); | - | ||||||||||||
2336 | - | |||||||||||||
2337 | if (format.borderBrush() != defaultFormat.borderBrush()
| 0 | ||||||||||||
2338 | html += QLatin1String(" border-color:"); | - | ||||||||||||
2339 | html += colorValue(format.borderBrush().color()); | - | ||||||||||||
2340 | html += QLatin1Char(';'); | - | ||||||||||||
2341 | } never executed: end of block | 0 | ||||||||||||
2342 | - | |||||||||||||
2343 | if (format.borderStyle() != defaultFormat.borderStyle()
| 0 | ||||||||||||
2344 | emitBorderStyle(format.borderStyle()); never executed: emitBorderStyle(format.borderStyle()); | 0 | ||||||||||||
2345 | - | |||||||||||||
2346 | if (format.hasProperty(QTextFormat::FrameMargin)
| 0 | ||||||||||||
2347 | || format.hasProperty(QTextFormat::FrameLeftMargin)
| 0 | ||||||||||||
2348 | || format.hasProperty(QTextFormat::FrameRightMargin)
| 0 | ||||||||||||
2349 | || format.hasProperty(QTextFormat::FrameTopMargin)
| 0 | ||||||||||||
2350 | || format.hasProperty(QTextFormat::FrameBottomMargin)
| 0 | ||||||||||||
2351 | emitMargins(QString::number(format.topMargin()), never executed: emitMargins(QString::number(format.topMargin()), QString::number(format.bottomMargin()), QString::number(format.leftMargin()), QString::number(format.rightMargin())); | 0 | ||||||||||||
2352 | QString::number(format.bottomMargin()), never executed: emitMargins(QString::number(format.topMargin()), QString::number(format.bottomMargin()), QString::number(format.leftMargin()), QString::number(format.rightMargin())); | 0 | ||||||||||||
2353 | QString::number(format.leftMargin()), never executed: emitMargins(QString::number(format.topMargin()), QString::number(format.bottomMargin()), QString::number(format.leftMargin()), QString::number(format.rightMargin())); | 0 | ||||||||||||
2354 | QString::number(format.rightMargin())); never executed: emitMargins(QString::number(format.topMargin()), QString::number(format.bottomMargin()), QString::number(format.leftMargin()), QString::number(format.rightMargin())); | 0 | ||||||||||||
2355 | - | |||||||||||||
2356 | if (html.length() == originalHtmlLength
| 0 | ||||||||||||
2357 | html.chop(qstrlen(styleAttribute.latin1()));size()); never executed: html.chop(styleAttribute.size()); | 0 | ||||||||||||
2358 | else | - | ||||||||||||
2359 | html += QLatin1Char('\"'); never executed: html += QLatin1Char('\"'); | 0 | ||||||||||||
2360 | } | - | ||||||||||||
2361 | QString QTextDocument::toHtml(const QByteArray &encoding) const | - | ||||||||||||
2362 | { | - | ||||||||||||
2363 | return QTextHtmlExporter(this).toHtml(encoding); | - | ||||||||||||
2364 | } | - | ||||||||||||
2365 | - | |||||||||||||
2366 | - | |||||||||||||
2367 | - | |||||||||||||
2368 | - | |||||||||||||
2369 | - | |||||||||||||
2370 | QVector<QTextFormat> QTextDocument::allFormats() const | - | ||||||||||||
2371 | { | - | ||||||||||||
2372 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
2373 | return d->formatCollection()->formats; | - | ||||||||||||
2374 | } | - | ||||||||||||
2375 | - | |||||||||||||
2376 | - | |||||||||||||
2377 | - | |||||||||||||
2378 | - | |||||||||||||
2379 | - | |||||||||||||
2380 | - | |||||||||||||
2381 | - | |||||||||||||
2382 | QTextDocumentPrivate *QTextDocument::docHandle() const | - | ||||||||||||
2383 | { | - | ||||||||||||
2384 | const QTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
2385 | return const_cast<QTextDocumentPrivate *>(d); | - | ||||||||||||
2386 | } | - | ||||||||||||
2387 | - | |||||||||||||
Switch to Source code | Preprocessed file |