Qt 4.8
qtextdocument.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtextdocument.h"
43 #include <qtextformat.h>
44 #include "qtextdocumentlayout_p.h"
45 #include "qtextdocumentfragment.h"
47 #include "qtexttable.h"
48 #include "qtextlist.h"
49 #include <qdebug.h>
50 #include <qregexp.h>
51 #include <qvarlengtharray.h>
52 #include <qtextcodec.h>
53 #include <qthread.h>
54 #include "qtexthtmlparser_p.h"
55 #include "qpainter.h"
56 #include "qprinter.h"
57 #include "qtextedit.h"
58 #include <qfile.h>
59 #include <qfileinfo.h>
60 #include <qdir.h>
61 #include <qapplication.h>
62 #include "qtextcontrol_p.h"
63 #include "qfont_p.h"
64 #include "private/qtextedit_p.h"
65 #include "private/qdataurl_p.h"
66 
67 #include "qtextdocument_p.h"
68 #include <private/qprinter_p.h>
69 #include <private/qabstracttextdocumentlayout_p.h>
70 
71 #include <limits.h>
72 
74 
75 Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n);
76 
89 {
90  if (text.isEmpty())
91  return false;
92  int start = 0;
93 
94  while (start < text.length() && text.at(start).isSpace())
95  ++start;
96 
97  // skip a leading <?xml ... ?> as for example with xhtml
98  if (text.mid(start, 5) == QLatin1String("<?xml")) {
99  while (start < text.length()) {
100  if (text.at(start) == QLatin1Char('?')
101  && start + 2 < text.length()
102  && text.at(start + 1) == QLatin1Char('>')) {
103  start += 2;
104  break;
105  }
106  ++start;
107  }
108 
109  while (start < text.length() && text.at(start).isSpace())
110  ++start;
111  }
112 
113  if (text.mid(start, 5).toLower() == QLatin1String("<!doc"))
114  return true;
115  int open = start;
116  while (open < text.length() && text.at(open) != QLatin1Char('<')
117  && text.at(open) != QLatin1Char('\n')) {
118  if (text.at(open) == QLatin1Char('&') && text.mid(open+1,3) == QLatin1String("lt;"))
119  return true; // support desperate attempt of user to see <...>
120  ++open;
121  }
122  if (open < text.length() && text.at(open) == QLatin1Char('<')) {
123  const int close = text.indexOf(QLatin1Char('>'), open);
124  if (close > -1) {
125  QString tag;
126  for (int i = open+1; i < close; ++i) {
127  if (text[i].isDigit() || text[i].isLetter())
128  tag += text[i];
129  else if (!tag.isEmpty() && text[i].isSpace())
130  break;
131  else if (!tag.isEmpty() && text[i] == QLatin1Char('/') && i + 1 == close)
132  break;
133  else if (!text[i].isSpace() && (!tag.isEmpty() || text[i] != QLatin1Char('!')))
134  return false; // that's not a tag
135  }
136 #ifndef QT_NO_TEXTHTMLPARSER
137  return QTextHtmlParser::lookupElement(tag.toLower()) != -1;
138 #else
139  return false;
140 #endif // QT_NO_TEXTHTMLPARSER
141  }
142  }
143  return false;
144 }
145 
160 {
161  QString rich;
162  rich.reserve(int(plain.length() * qreal(1.1)));
163  for (int i = 0; i < plain.length(); ++i) {
164  if (plain.at(i) == QLatin1Char('<'))
165  rich += QLatin1String("&lt;");
166  else if (plain.at(i) == QLatin1Char('>'))
167  rich += QLatin1String("&gt;");
168  else if (plain.at(i) == QLatin1Char('&'))
169  rich += QLatin1String("&amp;");
170  else if (plain.at(i) == QLatin1Char('"'))
171  rich += QLatin1String("&quot;");
172  else
173  rich += plain.at(i);
174  }
175  return rich;
176 }
177 
194 {
195  int col = 0;
196  QString rich;
197  rich += QLatin1String("<p>");
198  for (int i = 0; i < plain.length(); ++i) {
199  if (plain[i] == QLatin1Char('\n')){
200  int c = 1;
201  while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) {
202  i++;
203  c++;
204  }
205  if (c == 1)
206  rich += QLatin1String("<br>\n");
207  else {
208  rich += QLatin1String("</p>\n");
209  while (--c > 1)
210  rich += QLatin1String("<br>\n");
211  rich += QLatin1String("<p>");
212  }
213  col = 0;
214  } else {
215  if (mode == Qt::WhiteSpacePre && plain[i] == QLatin1Char('\t')){
216  rich += QChar(0x00a0U);
217  ++col;
218  while (col % 8) {
219  rich += QChar(0x00a0U);
220  ++col;
221  }
222  }
223  else if (mode == Qt::WhiteSpacePre && plain[i].isSpace())
224  rich += QChar(0x00a0U);
225  else if (plain[i] == QLatin1Char('<'))
226  rich += QLatin1String("&lt;");
227  else if (plain[i] == QLatin1Char('>'))
228  rich += QLatin1String("&gt;");
229  else if (plain[i] == QLatin1Char('&'))
230  rich += QLatin1String("&amp;");
231  else
232  rich += plain[i];
233  ++col;
234  }
235  }
236  if (col != 0)
237  rich += QLatin1String("</p>");
238  return rich;
239 }
240 
241 #ifndef QT_NO_TEXTCODEC
242 
251 {
252  return QTextCodec::codecForHtml(ba);
253 }
254 #endif
255 
344  : QObject(*new QTextDocumentPrivate, parent)
345 {
347  d->init();
348 }
349 
355  : QObject(*new QTextDocumentPrivate, parent)
356 {
358  d->init();
359  QTextCursor(this).insertText(text);
360 }
361 
366  : QObject(dd, parent)
367 {
369  d->init();
370 }
371 
376 {
377 }
378 
379 
385 {
386  Q_D(const QTextDocument);
387  QTextDocument *doc = new QTextDocument(parent);
389  doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat());
390  QTextDocumentPrivate *priv = doc->d_func();
391  priv->title = d->title;
392  priv->url = d->url;
393  priv->pageSize = d->pageSize;
394  priv->indentWidth = d->indentWidth;
395  priv->defaultTextOption = d->defaultTextOption;
396  priv->setDefaultFont(d->defaultFont());
397  priv->resources = d->resources;
398  priv->cachedResources.clear();
399 #ifndef QT_NO_CSSPARSER
400  priv->defaultStyleSheet = d->defaultStyleSheet;
401  priv->parsedDefaultStyleSheet = d->parsedDefaultStyleSheet;
402 #endif
403  return doc;
404 }
405 
410 {
411  Q_D(const QTextDocument);
412  /* because if we're empty we still have one single paragraph as
413  * one single fragment */
414  return d->length() <= 1;
415 }
416 
421 {
423  d->clear();
424  d->resources.clear();
425 }
426 
442 {
444  const int pos = d->undoRedo(true);
445  if (cursor && pos >= 0) {
446  *cursor = QTextCursor(this);
447  cursor->setPosition(pos);
448  }
449 }
450 
463 {
465  const int pos = d->undoRedo(false);
466  if (cursor && pos >= 0) {
467  *cursor = QTextCursor(this);
468  cursor->setPosition(pos);
469  }
470 }
471 
494 {
496  d->clearUndoRedoStacks(stacksToClear, true);
497 }
498 
504 {
506  d->undoRedo(true);
507 }
508 
518 {
520  d->undoRedo(false);
521 }
522 
532 {
534  d->appendUndoItem(item);
535 }
536 
548 {
550  d->enableUndoRedo(enable);
551 }
552 
554 {
555  Q_D(const QTextDocument);
556  return d->isUndoRedoEnabled();
557 }
558 
584 {
585  Q_D(const QTextDocument);
586  return d->maximumBlockCount;
587 }
588 
590 {
592  d->maximumBlockCount = maximum;
593  d->ensureMaximumBlockCount();
594  setUndoRedoEnabled(false);
595 }
596 
608 {
609  Q_D(const QTextDocument);
610  return d->defaultTextOption;
611 }
612 
622 {
624  d->defaultTextOption = option;
625  if (d->lout)
626  d->lout->documentChanged(0, 0, d->length());
627 }
628 
639 {
640  Q_D(const QTextDocument);
641  return d->defaultCursorMoveStyle;
642 }
643 
653 {
655  d->defaultCursorMoveStyle = style;
656 }
657 
668 void QTextDocument::markContentsDirty(int from, int length)
669 {
671  d->documentChange(from, length);
672  if (!d->inContentsChange) {
673  if (d->lout) {
674  d->lout->documentChanged(d->docChangeFrom, d->docChangeOldLength, d->docChangeLength);
675  d->docChangeFrom = -1;
676  }
677  }
678 }
679 
700 {
702  if (b == d->defaultTextOption.useDesignMetrics())
703  return;
704  d->defaultTextOption.setUseDesignMetrics(b);
705  if (d->lout)
706  d->lout->documentChanged(0, 0, d->length());
707 }
708 
710 {
711  Q_D(const QTextDocument);
712  return d->defaultTextOption.useDesignMetrics();
713 }
714 
725 {
726  p->save();
728  if (rect.isValid()) {
729  p->setClipRect(rect);
730  ctx.clip = rect;
731  }
732  documentLayout()->draw(p, ctx);
733  p->restore();
734 }
735 
761 {
763  QSizeF sz = d->pageSize;
764  sz.setWidth(width);
765  sz.setHeight(-1);
766  setPageSize(sz);
767 }
768 
770 {
771  Q_D(const QTextDocument);
772  return d->pageSize.width();
773 }
774 
787 {
788  if (QTextDocumentLayout *lout = qobject_cast<QTextDocumentLayout *>(documentLayout()))
789  return lout->idealWidth();
790  return textWidth();
791 }
792 
803 {
804  Q_D(const QTextDocument);
805  return d->documentMargin;
806 }
807 
809 {
811  if (d->documentMargin != margin) {
812  d->documentMargin = margin;
813 
814  QTextFrame* root = rootFrame();
816  format.setMargin(margin);
817  root->setFrameFormat(format);
818 
819  if (d->lout)
820  d->lout->documentChanged(0, 0, d->length());
821  }
822 }
823 
824 
838 {
839  Q_D(const QTextDocument);
840  return d->indentWidth;
841 }
842 
843 
858 {
860  if (d->indentWidth != width) {
861  d->indentWidth = width;
862  if (d->lout)
863  d->lout->documentChanged(0, 0, d->length());
864  }
865 }
866 
867 
868 
869 
881 {
882  // Pull this private function in from qglobal.cpp
883  QFont f = defaultFont();
884  QFontMetrics fm(f);
885  int mw = fm.width(QLatin1Char('x')) * 80;
886  int w = mw;
887  setTextWidth(w);
889  if (size.width() != 0) {
890  w = qt_int_sqrt((uint)(5 * size.height() * size.width() / 3));
891  setTextWidth(qMin(w, mw));
892 
893  size = documentLayout()->documentSize();
894  if (w*3 < 5*size.height()) {
895  w = qt_int_sqrt((uint)(2 * size.height() * size.width()));
896  setTextWidth(qMin(w, mw));
897  }
898  }
900 }
901 
923 {
924  return documentLayout()->documentSize();
925 }
926 
941 int QTextDocument::blockCount() const
942 {
943  Q_D(const QTextDocument);
944  return d->blockMap().numNodes();
945 }
946 
947 
960 {
961  Q_D(const QTextDocument);
962  return d->blockMap().length(2);
963 }
964 
976 {
977  Q_D(const QTextDocument);
978  return d->length();
979 }
980 
993 {
994  Q_D(const QTextDocument);
995  if (pos < 0 || pos >= d->length())
996  return QChar();
997  QTextDocumentPrivate::FragmentIterator fragIt = d->find(pos);
998  const QTextFragmentData * const frag = fragIt.value();
999  const int offsetInFragment = qMax(0, pos - fragIt.position());
1000  return d->text.at(frag->stringPosition + offsetInFragment);
1001 }
1002 
1003 
1022 #ifndef QT_NO_CSSPARSER
1024 {
1025  Q_D(QTextDocument);
1026  d->defaultStyleSheet = sheet;
1027  QCss::Parser parser(sheet);
1028  d->parsedDefaultStyleSheet = QCss::StyleSheet();
1029  d->parsedDefaultStyleSheet.origin = QCss::StyleSheetOrigin_UserAgent;
1030  parser.parse(&d->parsedDefaultStyleSheet);
1031 }
1032 
1034 {
1035  Q_D(const QTextDocument);
1036  return d->defaultStyleSheet;
1037 }
1038 #endif // QT_NO_CSSPARSER
1039 
1142 {
1143  Q_D(const QTextDocument);
1144  return d->isUndoAvailable();
1145 }
1146 
1153 {
1154  Q_D(const QTextDocument);
1155  return d->isRedoAvailable();
1156 }
1157 
1168 {
1169  Q_D(const QTextDocument);
1170  return d->availableUndoSteps();
1171 }
1172 
1183 {
1184  Q_D(const QTextDocument);
1185  return d->availableRedoSteps();
1186 }
1187 
1201 {
1202  Q_D(const QTextDocument);
1203  return d->revision;
1204 }
1205 
1206 
1207 
1215 {
1216  Q_D(QTextDocument);
1217  d->setLayout(layout);
1218 }
1219 
1224 {
1225  Q_D(const QTextDocument);
1226  if (!d->lout) {
1227  QTextDocument *that = const_cast<QTextDocument *>(this);
1228  that->d_func()->setLayout(new QTextDocumentLayout(that));
1229  }
1230  return d->lout;
1231 }
1232 
1233 
1241 {
1242  Q_D(const QTextDocument);
1243  switch (info) {
1244  case DocumentTitle:
1245  return d->title;
1246  case DocumentUrl:
1247  return d->url;
1248  }
1249  return QString();
1250 }
1251 
1259 {
1260  Q_D(QTextDocument);
1261  switch (info) {
1262  case DocumentTitle:
1263  d->title = string;
1264  break;
1265  case DocumentUrl:
1266  d->url = string;
1267  break;
1268  }
1269 }
1270 
1278 {
1279  Q_D(const QTextDocument);
1280  QString txt = d->plainText();
1281 
1282  QChar *uc = txt.data();
1283  QChar *e = uc + txt.size();
1284 
1285  for (; uc != e; ++uc) {
1286  switch (uc->unicode()) {
1287  case 0xfdd0: // QTextBeginningOfFrame
1288  case 0xfdd1: // QTextEndOfFrame
1290  case QChar::LineSeparator:
1291  *uc = QLatin1Char('\n');
1292  break;
1293  case QChar::Nbsp:
1294  *uc = QLatin1Char(' ');
1295  break;
1296  default:
1297  ;
1298  }
1299  }
1300  return txt;
1301 }
1302 
1310 {
1311  Q_D(QTextDocument);
1312  bool previousState = d->isUndoRedoEnabled();
1313  d->enableUndoRedo(false);
1314  d->beginEditBlock();
1315  d->clear();
1316  QTextCursor(this).insertText(text);
1317  d->endEditBlock();
1318  d->enableUndoRedo(previousState);
1319 }
1320 
1336 #ifndef QT_NO_TEXTHTMLPARSER
1337 
1339 {
1340  Q_D(QTextDocument);
1341  bool previousState = d->isUndoRedoEnabled();
1342  d->enableUndoRedo(false);
1343  d->beginEditBlock();
1344  d->clear();
1346  d->endEditBlock();
1347  d->enableUndoRedo(previousState);
1348 }
1349 
1350 #endif // QT_NO_TEXTHTMLPARSER
1351 
1402 QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags options) const
1403 {
1404  QRegExp expr(subString);
1407 
1408  return find(expr, from, options);
1409 }
1410 
1431 QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &from, FindFlags options) const
1432 {
1433  int pos = 0;
1434  if (!from.isNull()) {
1435  if (options & QTextDocument::FindBackward)
1436  pos = from.selectionStart();
1437  else
1438  pos = from.selectionEnd();
1439  }
1440  QRegExp expr(subString);
1443 
1444  return find(expr, pos, options);
1445 }
1446 
1447 
1448 static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset,
1449  QTextDocument::FindFlags options, QTextCursor &cursor)
1450 {
1451  const QRegExp expr(expression);
1452  QString text = block.text();
1453  text.replace(QChar::Nbsp, QLatin1Char(' '));
1454 
1455  int idx = -1;
1456  while (offset >=0 && offset <= text.length()) {
1457  idx = (options & QTextDocument::FindBackward) ?
1458  expr.lastIndexIn(text, offset) : expr.indexIn(text, offset);
1459  if (idx == -1)
1460  return false;
1461 
1462  if (options & QTextDocument::FindWholeWords) {
1463  const int start = idx;
1464  const int end = start + expr.matchedLength();
1465  if ((start != 0 && text.at(start - 1).isLetterOrNumber())
1466  || (end != text.length() && text.at(end).isLetterOrNumber())) {
1467  //if this is not a whole word, continue the search in the string
1468  offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1;
1469  idx = -1;
1470  continue;
1471  }
1472  }
1473  //we have a hit, return the cursor for that.
1474  break;
1475  }
1476  if (idx == -1)
1477  return false;
1478  cursor = QTextCursor(block.docHandle(), block.position() + idx);
1479  cursor.setPosition(cursor.position() + expr.matchedLength(), QTextCursor::KeepAnchor);
1480  return true;
1481 }
1482 
1503 QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags options) const
1504 {
1505  Q_D(const QTextDocument);
1506 
1507  if (expr.isEmpty())
1508  return QTextCursor();
1509 
1510  int pos = from;
1511  //the cursor is positioned between characters, so for a backward search
1512  //do not include the character given in the position.
1513  if (options & FindBackward) {
1514  --pos ;
1515  if(pos < 0)
1516  return QTextCursor();
1517  }
1518 
1519  QTextCursor cursor;
1520  QTextBlock block = d->blocksFind(pos);
1521 
1522  if (!(options & FindBackward)) {
1523  int blockOffset = qMax(0, pos - block.position());
1524  while (block.isValid()) {
1525  if (findInBlock(block, expr, blockOffset, options, cursor))
1526  return cursor;
1527  blockOffset = 0;
1528  block = block.next();
1529  }
1530  } else {
1531  int blockOffset = pos - block.position();
1532  while (block.isValid()) {
1533  if (findInBlock(block, expr, blockOffset, options, cursor))
1534  return cursor;
1535  block = block.previous();
1536  blockOffset = block.length() - 1;
1537  }
1538  }
1539 
1540  return QTextCursor();
1541 }
1542 
1564 QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &from, FindFlags options) const
1565 {
1566  int pos = 0;
1567  if (!from.isNull()) {
1568  if (options & QTextDocument::FindBackward)
1569  pos = from.selectionStart();
1570  else
1571  pos = from.selectionEnd();
1572  }
1573  return find(expr, pos, options);
1574 }
1575 
1576 
1587 {
1588  QTextObject *obj = 0;
1589  if (f.isListFormat())
1590  obj = new QTextList(this);
1591  else if (f.isTableFormat())
1592  obj = new QTextTable(this);
1593  else if (f.isFrameFormat())
1594  obj = new QTextFrame(this);
1595 
1596  return obj;
1597 }
1598 
1608 {
1609  Q_D(const QTextDocument);
1610  return d->frameAt(pos);
1611 }
1612 
1617 {
1618  Q_D(const QTextDocument);
1619  return d->rootFrame();
1620 }
1621 
1625 QTextObject *QTextDocument::object(int objectIndex) const
1626 {
1627  Q_D(const QTextDocument);
1628  return d->objectForIndex(objectIndex);
1629 }
1630 
1635 {
1636  Q_D(const QTextDocument);
1637  return d->objectForFormat(f);
1638 }
1639 
1640 
1645 {
1646  Q_D(const QTextDocument);
1647  return QTextBlock(docHandle(), d->blockMap().findNode(pos));
1648 }
1649 
1660 {
1661  Q_D(const QTextDocument);
1662  return QTextBlock(docHandle(), d->blockMap().findNode(blockNumber, 1));
1663 }
1664 
1675 {
1676  Q_D(const QTextDocument);
1677  return QTextBlock(docHandle(), d->blockMap().findNode(lineNumber, 2));
1678 }
1679 
1686 {
1687  Q_D(const QTextDocument);
1688  return QTextBlock(docHandle(), d->blockMap().begin().n);
1689 }
1690 
1704 {
1705  return QTextBlock(docHandle(), 0);
1706 }
1707 
1716 {
1717  Q_D(const QTextDocument);
1718  return QTextBlock(docHandle(), d->blockMap().begin().n);
1719 }
1720 
1729 {
1730  Q_D(const QTextDocument);
1731  return QTextBlock(docHandle(), d->blockMap().last().n);
1732 }
1733 
1748 {
1749  Q_D(QTextDocument);
1750  d->pageSize = size;
1751  if (d->lout)
1752  d->lout->documentChanged(0, 0, d->length());
1753 }
1754 
1756 {
1757  Q_D(const QTextDocument);
1758  return d->pageSize;
1759 }
1760 
1765 {
1766  return documentLayout()->pageCount();
1767 }
1768 
1773 {
1774  Q_D(QTextDocument);
1775  d->setDefaultFont(font);
1776  if (d->lout)
1777  d->lout->documentChanged(0, 0, d->length());
1778 }
1779 
1784 {
1785  Q_D(const QTextDocument);
1786  return d->defaultFont();
1787 }
1788 
1819 {
1820  return docHandle()->isModified();
1821 }
1822 
1824 {
1825  docHandle()->setModified(m);
1826 }
1827 
1828 #ifndef QT_NO_PRINTER
1829 static void printPage(int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos)
1830 {
1831  painter->save();
1832  painter->translate(body.left(), body.top() - (index - 1) * body.height());
1833  QRectF view(0, (index - 1) * body.height(), body.width(), body.height());
1834 
1837 
1838  painter->setClipRect(view);
1839  ctx.clip = view;
1840 
1841  // don't use the system palette text as default text color, on HP/UX
1842  // for example that's white, and white text on white paper doesn't
1843  // look that nice
1845 
1846  layout->draw(painter, ctx);
1847 
1848  if (!pageNumberPos.isNull()) {
1849  painter->setClipping(false);
1850  painter->setFont(QFont(doc->defaultFont()));
1851  const QString pageString = QString::number(index);
1852 
1853  painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().width(pageString)),
1854  qRound(pageNumberPos.y() + view.top()),
1855  pageString);
1856  }
1857 
1858  painter->restore();
1859 }
1860 
1884 void QTextDocument::print(QPrinter *printer) const
1885 {
1886  Q_D(const QTextDocument);
1887 
1888  if (!printer || !printer->isValid())
1889  return;
1890 
1891  if (!d->title.isEmpty())
1892  printer->setDocName(d->title);
1893 
1894  bool documentPaginated = d->pageSize.isValid() && !d->pageSize.isNull()
1895  && d->pageSize.height() != INT_MAX;
1896 
1897  if (!documentPaginated && !printer->fullPage() && !printer->d_func()->hasCustomPageMargins)
1898  printer->setPageMargins(23.53, 23.53, 23.53, 23.53, QPrinter::Millimeter);
1899 
1900  QPainter p(printer);
1901 
1902  // Check that there is a valid device to print to.
1903  if (!p.isActive())
1904  return;
1905 
1906  const QTextDocument *doc = this;
1908  (void)doc->documentLayout(); // make sure that there is a layout
1909 
1910  QRectF body = QRectF(QPointF(0, 0), d->pageSize);
1911  QPointF pageNumberPos;
1912 
1913  if (documentPaginated) {
1914  qreal sourceDpiX = qt_defaultDpi();
1915  qreal sourceDpiY = sourceDpiX;
1916 
1917  QPaintDevice *dev = doc->documentLayout()->paintDevice();
1918  if (dev) {
1919  sourceDpiX = dev->logicalDpiX();
1920  sourceDpiY = dev->logicalDpiY();
1921  }
1922 
1923  const qreal dpiScaleX = qreal(printer->logicalDpiX()) / sourceDpiX;
1924  const qreal dpiScaleY = qreal(printer->logicalDpiY()) / sourceDpiY;
1925 
1926  // scale to dpi
1927  p.scale(dpiScaleX, dpiScaleY);
1928 
1929  QSizeF scaledPageSize = d->pageSize;
1930  scaledPageSize.rwidth() *= dpiScaleX;
1931  scaledPageSize.rheight() *= dpiScaleY;
1932 
1933  const QSizeF printerPageSize(printer->pageRect().size());
1934 
1935  // scale to page
1936  p.scale(printerPageSize.width() / scaledPageSize.width(),
1937  printerPageSize.height() / scaledPageSize.height());
1938  } else {
1939  doc = clone(const_cast<QTextDocument *>(this));
1940  clonedDoc.reset(const_cast<QTextDocument *>(doc));
1941 
1942  for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock();
1943  srcBlock.isValid() && dstBlock.isValid();
1944  srcBlock = srcBlock.next(), dstBlock = dstBlock.next()) {
1945  dstBlock.layout()->setAdditionalFormats(srcBlock.layout()->additionalFormats());
1946  }
1947 
1949  layout->setPaintDevice(p.device());
1950 
1951  // copy the custom object handlers
1952  layout->d_func()->handlers = documentLayout()->d_func()->handlers;
1953 
1954  int dpiy = p.device()->logicalDpiY();
1955  int margin = 0;
1956  if (printer->fullPage() && !printer->d_func()->hasCustomPageMargins) {
1957  // for compatibility
1958  margin = (int) ((2/2.54)*dpiy); // 2 cm margins
1959  QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
1960  fmt.setMargin(margin);
1961  doc->rootFrame()->setFrameFormat(fmt);
1962  }
1963 
1964  QRectF pageRect(printer->pageRect());
1965  body = QRectF(0, 0, pageRect.width(), pageRect.height());
1966  pageNumberPos = QPointF(body.width() - margin,
1967  body.height() - margin
1968  + QFontMetrics(doc->defaultFont(), p.device()).ascent()
1969  + 5 * dpiy / 72.0);
1970  clonedDoc->setPageSize(body.size());
1971  }
1972 
1973  int docCopies;
1974  int pageCopies;
1975  if (printer->collateCopies() == true){
1976  docCopies = 1;
1977  pageCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
1978  } else {
1979  docCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
1980  pageCopies = 1;
1981  }
1982 
1983  int fromPage = printer->fromPage();
1984  int toPage = printer->toPage();
1985  bool ascending = true;
1986 
1987  if (fromPage == 0 && toPage == 0) {
1988  fromPage = 1;
1989  toPage = doc->pageCount();
1990  }
1991  // paranoia check
1992  fromPage = qMax(1, fromPage);
1993  toPage = qMin(doc->pageCount(), toPage);
1994 
1995  if (toPage < fromPage) {
1996  // if the user entered a page range outside the actual number
1997  // of printable pages, just return
1998  return;
1999  }
2000 
2001  if (printer->pageOrder() == QPrinter::LastPageFirst) {
2002  int tmp = fromPage;
2003  fromPage = toPage;
2004  toPage = tmp;
2005  ascending = false;
2006  }
2007 
2008  for (int i = 0; i < docCopies; ++i) {
2009 
2010  int page = fromPage;
2011  while (true) {
2012  for (int j = 0; j < pageCopies; ++j) {
2013  if (printer->printerState() == QPrinter::Aborted
2014  || printer->printerState() == QPrinter::Error)
2015  return;
2016  printPage(page, &p, doc, body, pageNumberPos);
2017  if (j < pageCopies - 1)
2018  printer->newPage();
2019  }
2020 
2021  if (page == toPage)
2022  break;
2023 
2024  if (ascending)
2025  ++page;
2026  else
2027  --page;
2028 
2029  printer->newPage();
2030  }
2031 
2032  if ( i < docCopies - 1)
2033  printer->newPage();
2034  }
2035 }
2036 #endif
2037 
2079 {
2080  Q_D(const QTextDocument);
2081  QVariant r = d->resources.value(name);
2082  if (!r.isValid()) {
2083  r = d->cachedResources.value(name);
2084  if (!r.isValid())
2085  r = const_cast<QTextDocument *>(this)->loadResource(type, name);
2086  }
2087  return r;
2088 }
2089 
2109 {
2110  Q_UNUSED(type);
2111  Q_D(QTextDocument);
2112  d->resources.insert(name, resource);
2113 }
2114 
2132 {
2133  Q_D(QTextDocument);
2134  QVariant r;
2135 
2137  if (doc) {
2138  r = doc->loadResource(type, name);
2139  }
2140 #ifndef QT_NO_TEXTEDIT
2141  else if (QTextEdit *edit = qobject_cast<QTextEdit *>(parent())) {
2142  QUrl resolvedName = edit->d_func()->resolveUrl(name);
2143  r = edit->loadResource(type, resolvedName);
2144  }
2145 #endif
2146 #ifndef QT_NO_TEXTCONTROL
2147  else if (QTextControl *control = qobject_cast<QTextControl *>(parent())) {
2148  r = control->loadResource(type, name);
2149  }
2150 #endif
2151 
2152  // handle data: URLs
2153  if (r.isNull() && name.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0)
2154  r = qDecodeDataUrl(name).second;
2155 
2156  // if resource was not loaded try to load it here
2157  if (!doc && r.isNull() && name.isRelative()) {
2158  QUrl currentURL = d->url;
2159  QUrl resourceUrl = name;
2160 
2161  // For the second case QUrl can merge "#someanchor" with "foo.html"
2162  // correctly to "foo.html#someanchor"
2163  if (!(currentURL.isRelative()
2164  || (currentURL.scheme() == QLatin1String("file")
2165  && !QFileInfo(currentURL.toLocalFile()).isAbsolute()))
2166  || (name.hasFragment() && name.path().isEmpty())) {
2167  resourceUrl = currentURL.resolved(name);
2168  } else {
2169  // this is our last resort when current url and new url are both relative
2170  // we try to resolve against the current working directory in the local
2171  // file system.
2172  QFileInfo fi(currentURL.toLocalFile());
2173  if (fi.exists()) {
2174  resourceUrl =
2175  QUrl::fromLocalFile(fi.absolutePath() + QDir::separator()).resolved(name);
2176  } else if (currentURL.isEmpty()) {
2177  resourceUrl.setScheme(QLatin1String("file"));
2178  }
2179  }
2180 
2181  QString s = resourceUrl.toLocalFile();
2182  QFile f(s);
2183  if (!s.isEmpty() && f.open(QFile::ReadOnly)) {
2184  r = f.readAll();
2185  f.close();
2186  }
2187  }
2188 
2189  if (!r.isNull()) {
2190  if (type == ImageResource && r.type() == QVariant::ByteArray) {
2191  if (qApp->thread() != QThread::currentThread()) {
2192  // must use images in non-GUI threads
2193  QImage image;
2194  image.loadFromData(r.toByteArray());
2195  if (!image.isNull())
2196  r = image;
2197  } else {
2198  QPixmap pm;
2199  pm.loadFromData(r.toByteArray());
2200  if (!pm.isNull())
2201  r = pm;
2202  }
2203  }
2204  d->cachedResources.insert(name, r);
2205  }
2206  return r;
2207 }
2208 
2209 static QTextFormat formatDifference(const QTextFormat &from, const QTextFormat &to)
2210 {
2211  QTextFormat diff = to;
2212 
2213  const QMap<int, QVariant> props = to.properties();
2214  for (QMap<int, QVariant>::ConstIterator it = props.begin(), end = props.end();
2215  it != end; ++it)
2216  if (it.value() == from.property(it.key()))
2217  diff.clearProperty(it.key());
2218 
2219  return diff;
2220 }
2221 
2223  : doc(_doc), fragmentMarkers(false)
2224 {
2225  const QFont defaultFont = doc->defaultFont();
2226  defaultCharFormat.setFont(defaultFont);
2227  // don't export those for the default font since we cannot turn them off with CSS
2232 }
2233 
2240 {
2241  html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
2242  "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
2243  "<html><head><meta name=\"qrichtext\" content=\"1\" />");
2244  html.reserve(doc->docHandle()->length());
2245 
2246  fragmentMarkers = (mode == ExportFragment);
2247 
2248  if (!encoding.isEmpty())
2249  html += QString::fromLatin1("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%1\" />").arg(QString::fromAscii(encoding));
2250 
2252  if (!title.isEmpty())
2253  html += QString::fromLatin1("<title>") + title + QString::fromLatin1("</title>");
2254  html += QLatin1String("<style type=\"text/css\">\n");
2255  html += QLatin1String("p, li { white-space: pre-wrap; }\n");
2256  html += QLatin1String("</style>");
2257  html += QLatin1String("</head><body");
2258 
2259  if (mode == ExportEntireDocument) {
2260  html += QLatin1String(" style=\"");
2261 
2263 
2265  html += QLatin1String(" font-size:");
2267  html += QLatin1String("pt;");
2269  html += QLatin1String(" font-size:");
2271  html += QLatin1String("px;");
2272  }
2273 
2274  html += QLatin1String(" font-weight:");
2276  html += QLatin1Char(';');
2277 
2278  html += QLatin1String(" font-style:");
2279  html += (defaultCharFormat.fontItalic() ? QLatin1String("italic") : QLatin1String("normal"));
2280  html += QLatin1Char(';');
2281 
2282  // do not set text-decoration on the default font since those values are /always/ propagated
2283  // and cannot be turned off with CSS
2284 
2285  html += QLatin1Char('\"');
2286 
2287  const QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
2289 
2290  } else {
2292  }
2293  html += QLatin1Char('>');
2294 
2295  QTextFrameFormat rootFmt = doc->rootFrame()->frameFormat();
2297 
2298  QTextFrameFormat defaultFmt;
2299  defaultFmt.setMargin(doc->documentMargin());
2300 
2301  if (rootFmt == defaultFmt)
2302  emitFrame(doc->rootFrame()->begin());
2303  else
2305 
2306  html += QLatin1String("</body></html>");
2307  return html;
2308 }
2309 
2310 void QTextHtmlExporter::emitAttribute(const char *attribute, const QString &value)
2311 {
2312  html += QLatin1Char(' ');
2313  html += QLatin1String(attribute);
2314  html += QLatin1String("=\"");
2315  html += Qt::escape(value);
2316  html += QLatin1Char('"');
2317 }
2318 
2320 {
2321  bool attributesEmitted = false;
2322 
2323  {
2324  const QString family = format.fontFamily();
2325  if (!family.isEmpty() && family != defaultCharFormat.fontFamily()) {
2326  emitFontFamily(family);
2327  attributesEmitted = true;
2328  }
2329  }
2330 
2332  && format.fontPointSize() != defaultCharFormat.fontPointSize()) {
2333  html += QLatin1String(" font-size:");
2334  html += QString::number(format.fontPointSize());
2335  html += QLatin1String("pt;");
2336  attributesEmitted = true;
2337  } else if (format.hasProperty(QTextFormat::FontSizeAdjustment)) {
2338  static const char * const sizeNames[] = {
2339  "small", "medium", "large", "x-large", "xx-large"
2340  };
2341  const char *name = 0;
2342  const int idx = format.intProperty(QTextFormat::FontSizeAdjustment) + 1;
2343  if (idx >= 0 && idx <= 4) {
2344  name = sizeNames[idx];
2345  }
2346  if (name) {
2347  html += QLatin1String(" font-size:");
2348  html += QLatin1String(name);
2349  html += QLatin1Char(';');
2350  attributesEmitted = true;
2351  }
2352  } else if (format.hasProperty(QTextFormat::FontPixelSize)) {
2353  html += QLatin1String(" font-size:");
2355  html += QLatin1String("px;");
2356  attributesEmitted = true;
2357  }
2358 
2360  && format.fontWeight() != defaultCharFormat.fontWeight()) {
2361  html += QLatin1String(" font-weight:");
2362  html += QString::number(format.fontWeight() * 8);
2363  html += QLatin1Char(';');
2364  attributesEmitted = true;
2365  }
2366 
2368  && format.fontItalic() != defaultCharFormat.fontItalic()) {
2369  html += QLatin1String(" font-style:");
2370  html += (format.fontItalic() ? QLatin1String("italic") : QLatin1String("normal"));
2371  html += QLatin1Char(';');
2372  attributesEmitted = true;
2373  }
2374 
2375  QLatin1String decorationTag(" text-decoration:");
2376  html += decorationTag;
2377  bool hasDecoration = false;
2378  bool atLeastOneDecorationSet = false;
2379 
2381  && format.fontUnderline() != defaultCharFormat.fontUnderline()) {
2382  hasDecoration = true;
2383  if (format.fontUnderline()) {
2384  html += QLatin1String(" underline");
2385  atLeastOneDecorationSet = true;
2386  }
2387  }
2388 
2390  && format.fontOverline() != defaultCharFormat.fontOverline()) {
2391  hasDecoration = true;
2392  if (format.fontOverline()) {
2393  html += QLatin1String(" overline");
2394  atLeastOneDecorationSet = true;
2395  }
2396  }
2397 
2399  && format.fontStrikeOut() != defaultCharFormat.fontStrikeOut()) {
2400  hasDecoration = true;
2401  if (format.fontStrikeOut()) {
2402  html += QLatin1String(" line-through");
2403  atLeastOneDecorationSet = true;
2404  }
2405  }
2406 
2407  if (hasDecoration) {
2408  if (!atLeastOneDecorationSet)
2409  html += QLatin1String("none");
2410  html += QLatin1Char(';');
2411  attributesEmitted = true;
2412  } else {
2413  html.chop(qstrlen(decorationTag.latin1()));
2414  }
2415 
2416  if (format.foreground() != defaultCharFormat.foreground()
2417  && format.foreground().style() != Qt::NoBrush) {
2418  html += QLatin1String(" color:");
2419  html += format.foreground().color().name();
2420  html += QLatin1Char(';');
2421  attributesEmitted = true;
2422  }
2423 
2424  if (format.background() != defaultCharFormat.background()
2425  && format.background().style() == Qt::SolidPattern) {
2426  html += QLatin1String(" background-color:");
2427  html += format.background().color().name();
2428  html += QLatin1Char(';');
2429  attributesEmitted = true;
2430  }
2431 
2434  {
2435  html += QLatin1String(" vertical-align:");
2436 
2438  if (valign == QTextCharFormat::AlignSubScript)
2439  html += QLatin1String("sub");
2440  else if (valign == QTextCharFormat::AlignSuperScript)
2441  html += QLatin1String("super");
2442  else if (valign == QTextCharFormat::AlignMiddle)
2443  html += QLatin1String("middle");
2444  else if (valign == QTextCharFormat::AlignTop)
2445  html += QLatin1String("top");
2446  else if (valign == QTextCharFormat::AlignBottom)
2447  html += QLatin1String("bottom");
2448 
2449  html += QLatin1Char(';');
2450  attributesEmitted = true;
2451  }
2452 
2453  if (format.fontCapitalization() != QFont::MixedCase) {
2454  const QFont::Capitalization caps = format.fontCapitalization();
2455  if (caps == QFont::AllUppercase)
2456  html += QLatin1String(" text-transform:uppercase;");
2457  else if (caps == QFont::AllLowercase)
2458  html += QLatin1String(" text-transform:lowercase;");
2459  else if (caps == QFont::SmallCaps)
2460  html += QLatin1String(" font-variant:small-caps;");
2461  attributesEmitted = true;
2462  }
2463 
2464  if (format.fontWordSpacing() != 0.0) {
2465  html += QLatin1String(" word-spacing:");
2466  html += QString::number(format.fontWordSpacing());
2467  html += QLatin1String("px;");
2468  attributesEmitted = true;
2469  }
2470 
2471  return attributesEmitted;
2472 }
2473 
2474 void QTextHtmlExporter::emitTextLength(const char *attribute, const QTextLength &length)
2475 {
2476  if (length.type() == QTextLength::VariableLength) // default
2477  return;
2478 
2479  html += QLatin1Char(' ');
2480  html += QLatin1String(attribute);
2481  html += QLatin1String("=\"");
2482  html += QString::number(length.rawValue());
2483 
2484  if (length.type() == QTextLength::PercentageLength)
2485  html += QLatin1String("%\"");
2486  else
2487  html += QLatin1Char('\"');
2488 }
2489 
2490 void QTextHtmlExporter::emitAlignment(Qt::Alignment align)
2491 {
2492  if (align & Qt::AlignLeft)
2493  return;
2494  else if (align & Qt::AlignRight)
2495  html += QLatin1String(" align=\"right\"");
2496  else if (align & Qt::AlignHCenter)
2497  html += QLatin1String(" align=\"center\"");
2498  else if (align & Qt::AlignJustify)
2499  html += QLatin1String(" align=\"justify\"");
2500 }
2501 
2503 {
2504  if (pos == QTextFrameFormat::InFlow)
2505  return;
2506 
2507  if (mode == EmitStyleTag)
2508  html += QLatin1String(" style=\"float:");
2509  else
2510  html += QLatin1String(" float:");
2511 
2512  if (pos == QTextFrameFormat::FloatLeft)
2513  html += QLatin1String(" left;");
2514  else if (pos == QTextFrameFormat::FloatRight)
2515  html += QLatin1String(" right;");
2516  else
2517  Q_ASSERT_X(0, "QTextHtmlExporter::emitFloatStyle()", "pos should be a valid enum type");
2518 
2519  if (mode == EmitStyleTag)
2520  html += QLatin1Char('\"');
2521 }
2522 
2524 {
2526 
2527  html += QLatin1String(" border-style:");
2528 
2529  switch (style) {
2531  html += QLatin1String("none");
2532  break;
2534  html += QLatin1String("dotted");
2535  break;
2537  html += QLatin1String("dashed");
2538  break;
2540  html += QLatin1String("solid");
2541  break;
2543  html += QLatin1String("double");
2544  break;
2546  html += QLatin1String("dot-dash");
2547  break;
2549  html += QLatin1String("dot-dot-dash");
2550  break;
2552  html += QLatin1String("groove");
2553  break;
2555  html += QLatin1String("ridge");
2556  break;
2558  html += QLatin1String("inset");
2559  break;
2561  html += QLatin1String("outset");
2562  break;
2563  default:
2564  Q_ASSERT(false);
2565  break;
2566  };
2567 
2568  html += QLatin1Char(';');
2569 }
2570 
2571 void QTextHtmlExporter::emitPageBreakPolicy(QTextFormat::PageBreakFlags policy)
2572 {
2574  html += QLatin1String(" page-break-before:always;");
2575 
2577  html += QLatin1String(" page-break-after:always;");
2578 }
2579 
2581 {
2582  html += QLatin1String(" font-family:");
2583 
2584  QLatin1String quote("\'");
2585  if (family.contains(QLatin1Char('\'')))
2586  quote = QLatin1String("&quot;");
2587 
2588  html += quote;
2589  html += Qt::escape(family);
2590  html += quote;
2591  html += QLatin1Char(';');
2592 }
2593 
2594 void QTextHtmlExporter::emitMargins(const QString &top, const QString &bottom, const QString &left, const QString &right)
2595 {
2596  html += QLatin1String(" margin-top:");
2597  html += top;
2598  html += QLatin1String("px;");
2599 
2600  html += QLatin1String(" margin-bottom:");
2601  html += bottom;
2602  html += QLatin1String("px;");
2603 
2604  html += QLatin1String(" margin-left:");
2605  html += left;
2606  html += QLatin1String("px;");
2607 
2608  html += QLatin1String(" margin-right:");
2609  html += right;
2610  html += QLatin1String("px;");
2611 }
2612 
2614 {
2615  const QTextCharFormat format = fragment.charFormat();
2616 
2617  bool closeAnchor = false;
2618 
2619  if (format.isAnchor()) {
2620  const QString name = format.anchorName();
2621  if (!name.isEmpty()) {
2622  html += QLatin1String("<a name=\"");
2623  html += Qt::escape(name);
2624  html += QLatin1String("\"></a>");
2625  }
2626  const QString href = format.anchorHref();
2627  if (!href.isEmpty()) {
2628  html += QLatin1String("<a href=\"");
2629  html += Qt::escape(href);
2630  html += QLatin1String("\">");
2631  closeAnchor = true;
2632  }
2633  }
2634 
2635  QString txt = fragment.text();
2636  const bool isObject = txt.contains(QChar::ObjectReplacementCharacter);
2637  const bool isImage = isObject && format.isImageFormat();
2638 
2639  QLatin1String styleTag("<span style=\"");
2640  html += styleTag;
2641 
2642  bool attributesEmitted = false;
2643  if (!isImage)
2644  attributesEmitted = emitCharFormatStyle(format);
2645  if (attributesEmitted)
2646  html += QLatin1String("\">");
2647  else
2648  html.chop(qstrlen(styleTag.latin1()));
2649 
2650  if (isObject) {
2651  for (int i = 0; isImage && i < txt.length(); ++i) {
2652  QTextImageFormat imgFmt = format.toImageFormat();
2653 
2654  html += QLatin1String("<img");
2655 
2656  if (imgFmt.hasProperty(QTextFormat::ImageName))
2657  emitAttribute("src", imgFmt.name());
2658 
2660  emitAttribute("width", QString::number(imgFmt.width()));
2661 
2663  emitAttribute("height", QString::number(imgFmt.height()));
2664 
2666  html += QLatin1String(" style=\"vertical-align: middle;\"");
2667  else if (imgFmt.verticalAlignment() == QTextCharFormat::AlignTop)
2668  html += QLatin1String(" style=\"vertical-align: top;\"");
2669 
2670  if (QTextFrame *imageFrame = qobject_cast<QTextFrame *>(doc->objectForFormat(imgFmt)))
2671  emitFloatStyle(imageFrame->frameFormat().position());
2672 
2673  html += QLatin1String(" />");
2674  }
2675  } else {
2677 
2678  txt = Qt::escape(txt);
2679 
2680  // split for [\n{LineSeparator}]
2681  QString forcedLineBreakRegExp = QString::fromLatin1("[\\na]");
2682  forcedLineBreakRegExp[3] = QChar::LineSeparator;
2683 
2684  const QStringList lines = txt.split(QRegExp(forcedLineBreakRegExp));
2685  for (int i = 0; i < lines.count(); ++i) {
2686  if (i > 0)
2687  html += QLatin1String("<br />"); // space on purpose for compatibility with Netscape, Lynx & Co.
2688  html += lines.at(i);
2689  }
2690  }
2691 
2692  if (attributesEmitted)
2693  html += QLatin1String("</span>");
2694 
2695  if (closeAnchor)
2696  html += QLatin1String("</a>");
2697 }
2698 
2699 static bool isOrderedList(int style)
2700 {
2705  ;
2706 }
2707 
2709 {
2711  emitAlignment(format.alignment());
2712 
2713  // assume default to not bloat the html too much
2714  // html += QLatin1String(" dir='ltr'");
2715  if (block.textDirection() == Qt::RightToLeft)
2716  html += QLatin1String(" dir='rtl'");
2717 
2718  QLatin1String style(" style=\"");
2719  html += style;
2720 
2721  const bool emptyBlock = block.begin().atEnd();
2722  if (emptyBlock) {
2723  html += QLatin1String("-qt-paragraph-type:empty;");
2724  }
2725 
2727  QString::number(format.bottomMargin()),
2728  QString::number(format.leftMargin()),
2729  QString::number(format.rightMargin()));
2730 
2731  html += QLatin1String(" -qt-block-indent:");
2732  html += QString::number(format.indent());
2733  html += QLatin1Char(';');
2734 
2735  html += QLatin1String(" text-indent:");
2736  html += QString::number(format.textIndent());
2737  html += QLatin1String("px;");
2738 
2739  if (block.userState() != -1) {
2740  html += QLatin1String(" -qt-user-state:");
2741  html += QString::number(block.userState());
2742  html += QLatin1Char(';');
2743  }
2744 
2746 
2748  if (emptyBlock) { // only print character properties when we don't expect them to be repeated by actual text in the parag
2749  const QTextCharFormat blockCharFmt = block.charFormat();
2750  diff = formatDifference(defaultCharFormat, blockCharFmt).toCharFormat();
2751  }
2752 
2755  QBrush bg = format.background();
2756  if (bg.style() != Qt::NoBrush)
2758  }
2759 
2760  if (!diff.properties().isEmpty())
2761  emitCharFormatStyle(diff);
2762 
2763  html += QLatin1Char('"');
2764 
2765 }
2766 
2768 {
2769  if (block.begin().atEnd()) {
2770  // ### HACK, remove once QTextFrame::Iterator is fixed
2771  int p = block.position();
2772  if (p > 0)
2773  --p;
2775  QChar ch = doc->docHandle()->buffer().at(frag->stringPosition);
2776  if (ch == QTextBeginningOfFrame
2777  || ch == QTextEndOfFrame)
2778  return;
2779  }
2780 
2781  html += QLatin1Char('\n');
2782 
2783  // save and later restore, in case we 'change' the default format by
2784  // emitting block char format information
2785  QTextCharFormat oldDefaultCharFormat = defaultCharFormat;
2786 
2787  QTextList *list = block.textList();
2788  if (list) {
2789  if (list->itemNumber(block) == 0) { // first item? emit <ul> or appropriate
2790  const QTextListFormat format = list->format();
2791  const int style = format.style();
2792  switch (style) {
2793  case QTextListFormat::ListDecimal: html += QLatin1String("<ol"); break;
2794  case QTextListFormat::ListDisc: html += QLatin1String("<ul"); break;
2795  case QTextListFormat::ListCircle: html += QLatin1String("<ul type=\"circle\""); break;
2796  case QTextListFormat::ListSquare: html += QLatin1String("<ul type=\"square\""); break;
2797  case QTextListFormat::ListLowerAlpha: html += QLatin1String("<ol type=\"a\""); break;
2798  case QTextListFormat::ListUpperAlpha: html += QLatin1String("<ol type=\"A\""); break;
2799  case QTextListFormat::ListLowerRoman: html += QLatin1String("<ol type=\"i\""); break;
2800  case QTextListFormat::ListUpperRoman: html += QLatin1String("<ol type=\"I\""); break;
2801  default: html += QLatin1String("<ul"); // ### should not happen
2802  }
2803 
2804  QString styleString = QString::fromLatin1("margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;");
2805 
2806  if (format.hasProperty(QTextFormat::ListIndent)) {
2807  styleString += QLatin1String(" -qt-list-indent: ");
2808  styleString += QString::number(format.indent());
2809  styleString += QLatin1Char(';');
2810  }
2811 
2813  QString numberPrefix = format.numberPrefix();
2814  numberPrefix.replace(QLatin1Char('"'), QLatin1String("\\22"));
2815  numberPrefix.replace(QLatin1Char('\''), QLatin1String("\\27")); // FIXME: There's a problem in the CSS parser the prevents this from being correctly restored
2816  styleString += QLatin1String(" -qt-list-number-prefix: ");
2817  styleString += QLatin1Char('\'');
2818  styleString += numberPrefix;
2819  styleString += QLatin1Char('\'');
2820  styleString += QLatin1Char(';');
2821  }
2822 
2824  if (format.numberSuffix() != QLatin1String(".")) { // this is our default
2825  QString numberSuffix = format.numberSuffix();
2826  numberSuffix.replace(QLatin1Char('"'), QLatin1String("\\22"));
2827  numberSuffix.replace(QLatin1Char('\''), QLatin1String("\\27")); // see above
2828  styleString += QLatin1String(" -qt-list-number-suffix: ");
2829  styleString += QLatin1Char('\'');
2830  styleString += numberSuffix;
2831  styleString += QLatin1Char('\'');
2832  styleString += QLatin1Char(';');
2833  }
2834  }
2835 
2836  html += QLatin1String(" style=\"");
2837  html += styleString;
2838  html += QLatin1String("\">");
2839  }
2840 
2841  html += QLatin1String("<li");
2842 
2843  const QTextCharFormat blockFmt = formatDifference(defaultCharFormat, block.charFormat()).toCharFormat();
2844  if (!blockFmt.properties().isEmpty()) {
2845  html += QLatin1String(" style=\"");
2846  emitCharFormatStyle(blockFmt);
2847  html += QLatin1Char('\"');
2848 
2850  }
2851  }
2852 
2853  const QTextBlockFormat blockFormat = block.blockFormat();
2855  html += QLatin1String("<hr");
2856 
2858  if (width.type() != QTextLength::VariableLength)
2859  emitTextLength("width", width);
2860  else
2861  html += QLatin1Char(' ');
2862 
2863  html += QLatin1String("/>");
2864  return;
2865  }
2866 
2867  const bool pre = blockFormat.nonBreakableLines();
2868  if (pre) {
2869  if (list)
2870  html += QLatin1Char('>');
2871  html += QLatin1String("<pre");
2872  } else if (!list) {
2873  html += QLatin1String("<p");
2874  }
2875 
2876  emitBlockAttributes(block);
2877 
2878  html += QLatin1Char('>');
2879  if (block.begin().atEnd())
2880  html += QLatin1String("<br />");
2881 
2882  QTextBlock::Iterator it = block.begin();
2883  if (fragmentMarkers && !it.atEnd() && block == doc->begin())
2884  html += QLatin1String("<!--StartFragment-->");
2885 
2886  for (; !it.atEnd(); ++it)
2887  emitFragment(it.fragment());
2888 
2889  if (fragmentMarkers && block.position() + block.length() == doc->docHandle()->length())
2890  html += QLatin1String("<!--EndFragment-->");
2891 
2892  if (pre)
2893  html += QLatin1String("</pre>");
2894  else if (list)
2895  html += QLatin1String("</li>");
2896  else
2897  html += QLatin1String("</p>");
2898 
2899  if (list) {
2900  if (list->itemNumber(block) == list->count() - 1) { // last item? close list
2901  if (isOrderedList(list->format().style()))
2902  html += QLatin1String("</ol>");
2903  else
2904  html += QLatin1String("</ul>");
2905  }
2906  }
2907 
2908  defaultCharFormat = oldDefaultCharFormat;
2909 }
2910 
2911 extern bool qHasPixmapTexture(const QBrush& brush);
2912 
2914 {
2915  QString url;
2916  if (!doc)
2917  return url;
2918 
2919  if (QTextDocument *parent = qobject_cast<QTextDocument *>(doc->parent()))
2920  return findUrlForImage(parent, cacheKey, isPixmap);
2921 
2922  if (doc && doc->docHandle()) {
2925  for (; it != priv->cachedResources.constEnd(); ++it) {
2926 
2927  const QVariant &v = it.value();
2928  if (v.type() == QVariant::Image && !isPixmap) {
2929  if (qvariant_cast<QImage>(v).cacheKey() == cacheKey)
2930  break;
2931  }
2932 
2933  if (v.type() == QVariant::Pixmap && isPixmap) {
2934  if (qvariant_cast<QPixmap>(v).cacheKey() == cacheKey)
2935  break;
2936  }
2937  }
2938 
2939  if (it != priv->cachedResources.constEnd())
2940  url = it.key().toString();
2941  }
2942 
2943  return url;
2944 }
2945 
2947 {
2948  if (!priv)
2949  return;
2950 
2951  cachedResources.unite(priv->cachedResources);
2952 }
2953 
2955 {
2958  emitAttribute("background", url);
2959  } else {
2960  const QBrush &brush = format.background();
2961  if (brush.style() == Qt::SolidPattern) {
2962  emitAttribute("bgcolor", brush.color().name());
2963  } else if (brush.style() == Qt::TexturePattern) {
2964  const bool isPixmap = qHasPixmapTexture(brush);
2965  const qint64 cacheKey = isPixmap ? brush.texture().cacheKey() : brush.textureImage().cacheKey();
2966 
2967  const QString url = findUrlForImage(doc, cacheKey, isPixmap);
2968 
2969  if (!url.isEmpty())
2970  emitAttribute("background", url);
2971  }
2972  }
2973 }
2974 
2976 {
2977  QTextTableFormat format = table->format();
2978 
2979  html += QLatin1String("\n<table");
2980 
2982  emitAttribute("border", QString::number(format.border()));
2983 
2984  emitFrameStyle(format, TableFrame);
2985 
2986  emitAlignment(format.alignment());
2987  emitTextLength("width", format.width());
2988 
2990  emitAttribute("cellspacing", QString::number(format.cellSpacing()));
2992  emitAttribute("cellpadding", QString::number(format.cellPadding()));
2993 
2994  emitBackgroundAttribute(format);
2995 
2996  html += QLatin1Char('>');
2997 
2998  const int rows = table->rows();
2999  const int columns = table->columns();
3000 
3001  QVector<QTextLength> columnWidths = format.columnWidthConstraints();
3002  if (columnWidths.isEmpty()) {
3003  columnWidths.resize(columns);
3004  columnWidths.fill(QTextLength());
3005  }
3006  Q_ASSERT(columnWidths.count() == columns);
3007 
3008  QVarLengthArray<bool> widthEmittedForColumn(columns);
3009  for (int i = 0; i < columns; ++i)
3010  widthEmittedForColumn[i] = false;
3011 
3012  const int headerRowCount = qMin(format.headerRowCount(), rows);
3013  if (headerRowCount > 0)
3014  html += QLatin1String("<thead>");
3015 
3016  for (int row = 0; row < rows; ++row) {
3017  html += QLatin1String("\n<tr>");
3018 
3019  for (int col = 0; col < columns; ++col) {
3020  const QTextTableCell cell = table->cellAt(row, col);
3021 
3022  // for col/rowspans
3023  if (cell.row() != row)
3024  continue;
3025 
3026  if (cell.column() != col)
3027  continue;
3028 
3029  html += QLatin1String("\n<td");
3030 
3031  if (!widthEmittedForColumn[col] && cell.columnSpan() == 1) {
3032  emitTextLength("width", columnWidths.at(col));
3033  widthEmittedForColumn[col] = true;
3034  }
3035 
3036  if (cell.columnSpan() > 1)
3037  emitAttribute("colspan", QString::number(cell.columnSpan()));
3038 
3039  if (cell.rowSpan() > 1)
3040  emitAttribute("rowspan", QString::number(cell.rowSpan()));
3041 
3042  const QTextTableCellFormat cellFormat = cell.format().toTableCellFormat();
3043  emitBackgroundAttribute(cellFormat);
3044 
3045  QTextCharFormat oldDefaultCharFormat = defaultCharFormat;
3046 
3048 
3049  QString styleString;
3050  if (valign >= QTextCharFormat::AlignMiddle && valign <= QTextCharFormat::AlignBottom) {
3051  styleString += QLatin1String(" vertical-align:");
3052  switch (valign) {
3054  styleString += QLatin1String("middle");
3055  break;
3057  styleString += QLatin1String("top");
3058  break;
3060  styleString += QLatin1String("bottom");
3061  break;
3062  default:
3063  break;
3064  }
3065  styleString += QLatin1Char(';');
3066 
3067  QTextCharFormat temp;
3068  temp.setVerticalAlignment(valign);
3069  defaultCharFormat.merge(temp);
3070  }
3071 
3073  styleString += QLatin1String(" padding-left:") + QString::number(cellFormat.leftPadding()) + QLatin1Char(';');
3075  styleString += QLatin1String(" padding-right:") + QString::number(cellFormat.rightPadding()) + QLatin1Char(';');
3077  styleString += QLatin1String(" padding-top:") + QString::number(cellFormat.topPadding()) + QLatin1Char(';');
3079  styleString += QLatin1String(" padding-bottom:") + QString::number(cellFormat.bottomPadding()) + QLatin1Char(';');
3080 
3081  if (!styleString.isEmpty())
3082  html += QLatin1String(" style=\"") + styleString + QLatin1Char('\"');
3083 
3084  html += QLatin1Char('>');
3085 
3086  emitFrame(cell.begin());
3087 
3088  html += QLatin1String("</td>");
3089 
3090  defaultCharFormat = oldDefaultCharFormat;
3091  }
3092 
3093  html += QLatin1String("</tr>");
3094  if (headerRowCount > 0 && row == headerRowCount - 1)
3095  html += QLatin1String("</thead>");
3096  }
3097 
3098  html += QLatin1String("</table>");
3099 }
3100 
3102 {
3103  if (!frameIt.atEnd()) {
3104  QTextFrame::Iterator next = frameIt;
3105  ++next;
3106  if (next.atEnd()
3107  && frameIt.currentFrame() == 0
3108  && frameIt.parentFrame() != doc->rootFrame()
3109  && frameIt.currentBlock().begin().atEnd())
3110  return;
3111  }
3112 
3113  for (QTextFrame::Iterator it = frameIt;
3114  !it.atEnd(); ++it) {
3115  if (QTextFrame *f = it.currentFrame()) {
3116  if (QTextTable *table = qobject_cast<QTextTable *>(f)) {
3117  emitTable(table);
3118  } else {
3119  emitTextFrame(f);
3120  }
3121  } else if (it.currentBlock().isValid()) {
3122  emitBlock(it.currentBlock());
3123  }
3124  }
3125 }
3126 
3128 {
3129  FrameType frameType = f->parentFrame() ? TextFrame : RootFrame;
3130 
3131  html += QLatin1String("\n<table");
3133 
3135  emitAttribute("border", QString::number(format.border()));
3136 
3137  emitFrameStyle(format, frameType);
3138 
3139  emitTextLength("width", format.width());
3140  emitTextLength("height", format.height());
3141 
3142  // root frame's bcolor goes in the <body> tag
3143  if (frameType != RootFrame)
3144  emitBackgroundAttribute(format);
3145 
3146  html += QLatin1Char('>');
3147  html += QLatin1String("\n<tr>\n<td style=\"border: none;\">");
3148  emitFrame(f->begin());
3149  html += QLatin1String("</td></tr></table>");
3150 }
3151 
3153 {
3154  QLatin1String styleAttribute(" style=\"");
3155  html += styleAttribute;
3156  const int originalHtmlLength = html.length();
3157 
3158  if (frameType == TextFrame)
3159  html += QLatin1String("-qt-table-type: frame;");
3160  else if (frameType == RootFrame)
3161  html += QLatin1String("-qt-table-type: root;");
3162 
3163  const QTextFrameFormat defaultFormat;
3164 
3167 
3168  if (format.borderBrush() != defaultFormat.borderBrush()) {
3169  html += QLatin1String(" border-color:");
3170  html += format.borderBrush().color().name();
3171  html += QLatin1Char(';');
3172  }
3173 
3174  if (format.borderStyle() != defaultFormat.borderStyle())
3175  emitBorderStyle(format.borderStyle());
3176 
3183  QString::number(format.bottomMargin()),
3184  QString::number(format.leftMargin()),
3185  QString::number(format.rightMargin()));
3186 
3187  if (html.length() == originalHtmlLength) // nothing emitted?
3188  html.chop(qstrlen(styleAttribute.latin1()));
3189  else
3190  html += QLatin1Char('\"');
3191 }
3192 
3209 #ifndef QT_NO_TEXTHTMLPARSER
3211 {
3212  return QTextHtmlExporter(this).toHtml(encoding);
3213 }
3214 #endif // QT_NO_TEXTHTMLPARSER
3215 
3220 {
3221  Q_D(const QTextDocument);
3222  return d->formatCollection()->formats;
3223 }
3224 
3225 
3235 {
3236  Q_D(const QTextDocument);
3237  return const_cast<QTextDocumentPrivate *>(d);
3238 }
3239 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
bool fullPage() const
Returns true if the origin of the printer&#39;s coordinate system is at the corner of the page and false ...
Definition: qprinter.cpp:1542
int columns() const
Returns the number of columns in the table.
double d
Definition: qnumeric_p.h:62
qreal cellSpacing() const
Returns the table&#39;s cell spacing.
Definition: qtextformat.h:862
QString findUrlForImage(const QTextDocument *doc, qint64 cacheKey, bool isPixmap)
qreal rightPadding() const
Gets the right padding of the table cell.
Definition: qtextformat.h:959
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
QString text() const
Returns the block&#39;s contents as plain text.
int type
Definition: qmetatype.cpp:239
QTextCharFormat defaultCharFormat
int toPage() const
Returns the number of the last page in a range of pages to be printed (the "to page" setting)...
Definition: qprinter.cpp:2196
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
bool isFrameFormat() const
Returns true if this text format is a FrameFormat; otherwise returns false.
Definition: qtextformat.h:321
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
Definition: qglobal.cpp:2478
void setPatternSyntax(PatternSyntax syntax)
Sets the syntax mode for the regular expression.
Definition: qregexp.cpp:4032
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
PrinterState printerState() const
Returns the current state of the printer.
Definition: qprinter.cpp:1990
QRect pageRect() const
Returns the page&#39;s rectangle; this is usually smaller than the paperRect() since the page normally ha...
Definition: qprinter.cpp:1800
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
int lineCount() const
Returns the number of lines of this document (if the layout supports this).
int count() const
Returns the number of items in the list.
Definition: qtextlist.cpp:139
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns 0...
Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode=WhiteSpacePre)
Converts the plain text string plain to an HTML-formatted paragraph while preserving most of its look...
int lastIndexIn(const QString &str, int offset=-1, CaretMode caretMode=CaretAtZero) const
Attempts to find a match backwards in str from position offset.
Definition: qregexp.cpp:4167
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
bool fontStrikeOut() const
Returns true if the text format&#39;s font is struck out (has a horizontal line drawn through it); otherw...
Definition: qtextformat.h:443
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
int headerRowCount() const
Returns the number of rows in the table that define the header.
Definition: qtextformat.h:877
static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset, QTextDocument::FindFlags options, QTextCursor &cursor)
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
QTextBlock begin() const
Returns the document&#39;s first text block.
#define it(className, varName)
int logicalDpiY() const
Definition: qpaintdevice.h:96
bool isEmpty() const
Returns true if the document is empty; otherwise returns false.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
Type type() const
Returns the type of this length object.
Definition: qtextformat.h:93
void adjustSize()
Adjusts the document to a reasonable size.
Position
This enum describes how a frame is located relative to the surrounding text.
Definition: qtextformat.h:734
QTextFrame::iterator begin() const
Returns a frame iterator pointing to the beginning of the table&#39;s cell.
Definition: qtexttable.cpp:306
qreal width() const
Returns the width.
Definition: qsize.h:284
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QTextTableCellFormat toTableCellFormat() const
Returns this format as a table cell format.
int fromPage() const
Returns the number of the first page in a range of pages to be printed (the "from page" setting)...
Definition: qprinter.cpp:2168
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QSizeF size() const
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool atEnd() const
Returns true if the current item is the last item in the text block.
Definition: qtextobject.h:264
QTextHtmlExporter(const QTextDocument *_doc)
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
PageBreakFlags pageBreakPolicy() const
Returns the currently set page break policy for the paragraph.
Definition: qtextformat.h:608
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
void setModified(bool m=true)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal height() const
Returns the height.
Definition: qsize.h:287
void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit)
This function sets the left, top, right and bottom page margins for this printer. ...
Definition: qprinter.cpp:1831
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
int availableUndoSteps() const
Returns the number of available undo steps.
void emitAlignment(Qt::Alignment alignment)
T2 second
Definition: qpair.h:66
void setVerticalAlignment(VerticalAlignment alignment)
Sets the vertical alignment used for the characters with this format to the alignment specified...
Definition: qtextformat.h:484
static QTextCodec * codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
void setFont(const QFont &font)
Sets the text format&#39;s font.
int matchedLength() const
Returns the length of the last matched string, or -1 if there was no match.
Definition: qregexp.cpp:4193
bool useDesignMetrics() const
const QTextDocument * doc
bool isModified() const
QString text() const
Returns the text fragment&#39;s as plain text.
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString anchorName() const
This function is deprecated.
void setDefaultFont(const QFont &f)
void setPageSize(const QSizeF &size)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define QTextBeginningOfFrame
void setIndentWidth(qreal width)
Sets the width used for text list and text block indenting.
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
QChar characterAt(int pos) const
Returns the character at position pos, or a null character if the position is out of range...
void print(QPrinter *printer) const
Prints the document to the given printer.
qreal leftMargin() const
Returns the width of the frame&#39;s left margin in pixels.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
qreal height() const
Returns the height of the rectangle occupied by the image.
Definition: qtextformat.h:710
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QFont defaultFont
the default font used to display the document&#39;s text
qreal topMargin() const
Returns the paragraph&#39;s top margin.
Definition: qtextformat.h:566
void setWidth(qreal w)
Sets the width to the given width.
Definition: qsize.h:290
QPalette palette
the default color that is used for the text, when no color is specified.
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
qreal rightMargin() const
Returns the paragraph&#39;s right margin.
Definition: qtextformat.h:581
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Capitalization
Rendering option for text this font applies to.
Definition: qfont.h:129
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Qt::Alignment alignment() const
Returns the paragraph&#39;s alignment.
Definition: qtextformat.h:561
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QTextObject * objectForFormat(const QTextFormat &) const
Returns the text object associated with the format f.
void markContentsDirty(int from, int length)
Marks the contents specified by the given position and length as "dirty", informing the document that...
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
QString toPlainText() const
Returns the plain text contained in the document.
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
QTextOption defaultTextOption
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
void setMetaInformation(MetaInformation info, const QString &)
Sets the document&#39;s meta information of the type specified by info to the given string.
void emitBlock(const QTextBlock &block)
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int rowSpan() const
Returns the number of rows this cell spans.
Definition: qtexttable.cpp:218
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
int position() const
Returns the index of the block&#39;s first character within the document.
QTextBlock end() const
This function returns a block to test for the end of the document while iterating over it...
void emitTextFrame(const QTextFrame *frame)
Position position() const
Returns the positioning policy for frames with this frame format.
Definition: qtextformat.h:758
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
int logicalDpiX() const
Definition: qpaintdevice.h:95
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
VerticalAlignment
This enum describes the ways that adjacent characters can be vertically aligned.
Definition: qtextformat.h:375
Qt::Alignment alignment() const
Returns the table&#39;s alignment.
Definition: qtextformat.h:872
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
QTextCharFormat charFormat() const
Returns the text fragment&#39;s character format.
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
FragmentIterator find(int pos) const
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
QFontMetrics fontMetrics() const
Returns the font metrics for the painter if the painter is active.
Definition: qpainter.cpp:2077
Style style() const
Returns the list format&#39;s style.
Definition: qtextformat.h:662
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal topMargin() const
Returns the width of the frame&#39;s top margin in pixels.
bool fontOverline() const
Returns true if the text format&#39;s font is overlined; otherwise returns false.
Definition: qtextformat.h:438
QTextCharFormat format() const
Returns the cell&#39;s character format.
Definition: qtexttable.cpp:153
QTextTableFormat format() const
Returns the table&#39;s format.
Definition: qtexttable.h:133
int column() const
Returns the number of the column in the table that contains this cell.
Definition: qtexttable.cpp:201
void emitBackgroundAttribute(const QTextFormat &format)
int revision() const
Returns the document&#39;s revision (if undo is enabled).
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
qreal bottomMargin() const
Returns the width of the frame&#39;s bottom margin in pixels.
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
virtual int pageCount() const =0
Returns the number of pages contained in the layout.
QString numberSuffix() const
Returns the list format&#39;s number suffix.
Definition: qtextformat.h:674
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isListFormat() const
Returns true if this text format is a ListFormat; otherwise returns false.
Definition: qtextformat.h:320
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QTextFrame * parentFrame() const
Returns the frame&#39;s parent frame.
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define qApp
virtual QSizeF documentSize() const =0
Returns the total size of the document&#39;s layout.
static int lookupElement(const QString &element)
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isUndoRedoEnabled() const
const char * layout
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
qreal idealWidth() const
Returns the ideal width of the text document.
virtual QVariant loadResource(int type, const QUrl &name)
Loads data of the specified type from the resource with the given name.
QString defaultStyleSheet() const
bool isValid() const
Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostSc...
Definition: qprinter.cpp:895
int fontWeight() const
Returns the text format&#39;s font weight.
Definition: qtextformat.h:413
void appendUndoItem(QAbstractUndoItem *)
Appends a custom undo item to the undo stack.
QMap< QUrl, QVariant > cachedResources
bool qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:223
void emitTable(const QTextTable *table)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
static Bigint * diff(Bigint *a, Bigint *b)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QCss::StyleSheet parsedDefaultStyleSheet
void setMaximumBlockCount(int maximum)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
static bool isOrderedList(int style)
int blockCount() const
QString toHtml(const QByteArray &encoding, ExportMode mode=ExportEntireDocument)
Returns the document in HTML format.
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
static bool isDigit(ushort ch)
void insertFragment(const QTextDocumentFragment &fragment)
Inserts the text fragment at the current position().
int pageCount() const
returns the number of pages in this document.
void setUseDesignMetrics(bool b)
QRectF clip
a hint to the layout specifying the area around paragraphs, frames or text require painting...
__int64 qint64
Definition: qglobal.h:942
bool isTableFormat() const
Returns true if this text format is a TableFormat; otherwise returns false.
Definition: qtextformat.h:323
int maximumBlockCount() const
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
bool loadFromData(const uchar *buf, uint len, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
Loads a pixmap from the len first bytes of the given binary data.
Definition: qpixmap.cpp:979
int itemNumber(const QTextBlock &) const
Returns the index of the list item that corresponds to the given block.
Definition: qtextlist.cpp:185
void emitFloatStyle(QTextFrameFormat::Position pos, StyleMode mode=EmitStyleTag)
bool supportsMultipleCopies() const
Returns true if the printer supports printing multiple copies of the same document in one job; otherw...
Definition: qprinter.cpp:1453
void emitPageBreakPolicy(QTextFormat::PageBreakFlags policy)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
QTextDocument * clone(QObject *parent=0) const
Creates a new QTextDocument that is a copy of this text document.
bool isUndoAvailable() const
Returns true if undo is available; otherwise returns false.
QTextObject * object(int objectIndex) const
Returns the text object associated with the given objectIndex.
qreal textIndent() const
Returns the paragraph&#39;s text indent.
Definition: qtextformat.h:586
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
Definition: qtextobject.h:251
QTextBlock findBlockByNumber(int blockNumber) const
Returns the text block with the specified blockNumber.
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block&#39;s character format.
static void printPage(int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
void emitFontFamily(const QString &family)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
virtual QTextObject * createObject(const QTextFormat &f)
Creates and returns a new document object (a QTextObject), based on the given format.
bool newPage()
Tells the printer to eject the current page and to continue printing on a new page.
Definition: qprinter.cpp:1962
MetaInformation
This enum describes the different types of meta information that can be added to a document...
qreal indentWidth() const
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
Definition: qtextobject.h:144
QTextLength height() const
Returns the height of the frame&#39;s border rectangle.
Definition: qtextformat.h:803
QTextBlock findBlockByLineNumber(int blockNumber) const
Returns the text block that contains the specified lineNumber.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int userState() const
Returns the integer value previously set with setUserState() or -1.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QVector< QTextFormat > allFormats() const
Returns a vector of text formats for all the formats used in the document.
int characterCount() const
Returns the number of characters of this document.
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
bool isEmpty() const
Returns true if the pattern string is empty; otherwise returns false.
Definition: qregexp.cpp:3925
uint qstrlen(const char *str)
Definition: qbytearray.h:79
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
void undo()
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
void drawContents(QPainter *painter, const QRectF &rect=QRectF())
Draws the content of the document with painter p, clipped to rect.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
void emitFrame(QTextFrame::Iterator frameIt)
QTextLength width() const
Returns the width of the frame&#39;s border rectangle.
Definition: qtextformat.h:798
QTextImageFormat toImageFormat() const
Returns this format as an image format.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
bool nonBreakableLines() const
Returns true if the lines in the paragraph are non-breakable; otherwise returns false.
Definition: qtextformat.h:603
QString numberPrefix() const
Returns the list format&#39;s number prefix.
Definition: qtextformat.h:670
int compare(const QString &s) const
Definition: qstring.cpp:5037
QTextDocument(QObject *parent=0)
Constructs an empty QTextDocument with the given parent.
void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style)
Sets the default cursor movement style to the given style.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
void setTextWidth(qreal width)
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Definition: qpainter.cpp:2517
CursorMoveStyle
This enum describes the movement style available to text cursors.
Definition: qnamespace.h:1790
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QTextCursor find(const QString &subString, int from=0, FindFlags options=0) const
Finds the next occurrence of the string, subString, in the document.
bool collateCopies() const
Returns true if collation is turned on when multiple copies is selected.
Definition: qprinter.cpp:1473
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
QString buffer() const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
void mergeCachedResources(const QTextDocumentPrivate *priv)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
qreal bottomMargin() const
Returns the paragraph&#39;s bottom margin.
Definition: qtextformat.h:571
qreal documentMargin() const
void emitBorderStyle(QTextFrameFormat::BorderStyle style)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
#define ctx
Definition: qgl.cpp:6094
qreal fontWordSpacing() const
Returns the current word spacing value.
Definition: qtextformat.h:429
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
QSizeF pageSize() const
int rows() const
Returns the number of rows in the table.
QString metaInformation(MetaInformation info) const
Returns meta information about the document of the type specified by info.
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
qreal rightMargin() const
Returns the width of the frame&#39;s right margin in pixels.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
QBrush borderBrush() const
Returns the brush used for the frame&#39;s border.
Definition: qtextformat.h:767
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
void emitMargins(const QString &top, const QString &bottom, const QString &left, const QString &right)
QTextBlock lastBlock() const
Returns the document&#39;s last (valid) text block.
static const QMetaObjectPrivate * priv(const uint *data)
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
QPaintDevice * paintDevice() const
Returns the paint device used to render the document&#39;s layout.
void addResource(int type, const QUrl &name, const QVariant &resource)
Adds the resource resource to the resource cache, using type and name as identifiers.
void setUndoRedoEnabled(bool enable)
WhiteSpaceMode
Definition: qtextdocument.h:79
bool hasFragment() const
Returns true if this URL contains a fragment (i.
Definition: qurl.cpp:5773
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
void setDocumentMargin(qreal margin)
Qt::CursorMoveStyle defaultCursorMoveStyle() const
The default cursor movement style is used by all QTextCursor objects created from the document...
Qt::LayoutDirection textDirection() const
Returns the resolved text direction.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
void emitTextLength(const char *attribute, const QTextLength &length)
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
The QTextTableCellFormat class provides formatting information for table cells in a QTextDocument...
Definition: qtextformat.h:898
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int copyCount() const
Returns the number of copies that will be printed.
Definition: qprinter.cpp:1430
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setDefaultStyleSheet(const QString &sheet)
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
void setHeight(qreal h)
Sets the height to the given height.
Definition: qsize.h:293
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
~QTextDocument()
Destroys the document.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document&#39;s layout to the given device.
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
Definition: qtextformat.h:842
void setMargin(qreal margin)
Sets the frame&#39;s margin in pixels.
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
QTextCharFormat toCharFormat() const
Returns this format as a character format.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
void setCaseSensitivity(Qt::CaseSensitivity cs)
Sets case sensitive matching to cs.
Definition: qregexp.cpp:3998
QTextFrame * parentFrame() const
Returns the parent frame of the current frame.
Definition: qtextobject.h:160
bool parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
QTextFrame * frameAt(int pos) const
Returns the frame that contains the text cursor position pos.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
PageBreakFlags pageBreakPolicy() const
Returns the currently set page break policy for the frame/table.
Definition: qtextformat.h:808
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
bool atEnd() const
Returns true if the current item is the last item in the text frame.
Definition: qtextobject.h:165
qreal rawValue() const
Returns the constraint value that is specific for the type of the length.
Definition: qtextformat.h:104
void setDocName(const QString &)
Sets the document name to name.
Definition: qprinter.cpp:1052
void redo()
Redoes the last editing operation on the document if redo is available.
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
QVariant resource(int type, const QUrl &name) const
Returns data of the specified type from the resource with the given name.
qreal fontPointSize() const
Returns the font size used to display text in this format.
Definition: qtextformat.h:408
void emitAttribute(const char *attribute, const QString &value)
void emitBlockAttributes(const QTextBlock &block)
qreal topPadding() const
Gets the top padding of the table cell.
Definition: qtextformat.h:929
bool isImageFormat() const
Returns true if this text format is an image format; otherwise returns false.
Definition: qtextformat.h:322
int intProperty(int propertyId) const
Returns the value of the property specified by propertyId.
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
void emitFrameStyle(const QTextFrameFormat &format, FrameType frameType)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
qreal border() const
Returns the width of the border in pixels.
Definition: qtextformat.h:762
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
qreal textWidth() const
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QTextFragment fragment() const
Returns the text fragment the iterator currently points to.
qreal cellPadding() const
Returns the table&#39;s cell padding.
Definition: qtextformat.h:867
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:64
QMap< QUrl, QVariant > resources
qreal & rheight()
Returns a reference to the height.
Definition: qsize.h:302
qreal leftPadding() const
Gets the left padding of the table cell.
Definition: qtextformat.h:949
QTextOption defaultTextOption() const
the default text option will be set on all QTextLayout in the document.
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
QImage textureImage() const
Returns the custom brush pattern, or a null image if no custom brush pattern has been set...
Definition: qbrush.cpp:829
bool fontItalic() const
Returns true if the text format&#39;s font is italic; otherwise returns false.
Definition: qtextformat.h:417
QString fontFamily() const
Returns the text format&#39;s font family.
Definition: qtextformat.h:403
virtual void clear()
Clears the document.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
qreal bottomPadding() const
Gets the bottom padding of the table cell.
Definition: qtextformat.h:939
QTextBlock currentBlock() const
Returns the current block the iterator points to.
BorderStyle
This enum describes different border styles for the text frame.
Definition: qtextformat.h:742
static QTextFormat formatDifference(const QTextFormat &from, const QTextFormat &to)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
int availableRedoSteps() const
Returns the number of available redo steps.
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool emitCharFormatStyle(const QTextCharFormat &format)
qreal leftMargin() const
Returns the paragraph&#39;s left margin.
Definition: qtextformat.h:576
QString name() const
Returns the name of the color in the format "#RRGGBB"; i.e.
Definition: qcolor.cpp:529
#define INT_MAX
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
qreal & rwidth()
Returns a reference to the width.
Definition: qsize.h:299
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
QFont::Capitalization fontCapitalization() const
Returns the current capitalization type of the font.
Definition: qtextformat.h:421
PageOrder pageOrder() const
Returns the current page order.
Definition: qprinter.cpp:1286
QVector< QTextLength > columnWidthConstraints() const
Returns a list of constraints used by this table format to control the appearance of columns in a tab...
Definition: qtextformat.h:856
QString toHtml(const QByteArray &encoding=QByteArray()) const
Returns a string containing an HTML representation of the document.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282
void clear()
Removes all items from the map.
Definition: qmap.h:444
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
QString name() const
Returns the name of the image.
Definition: qtextformat.h:702
bool fontUnderline() const
Returns true if the text format&#39;s font is underlined; otherwise returns false.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
Definition: qtextedit.h:70
Q_CORE_EXPORT QPair< QString, QByteArray > qDecodeDataUrl(const QUrl &uri)
Decode a data: URL into its mimetype and payload.
Definition: qdataurl.cpp:57
int open(const char *, int,...)
#define text
Definition: qobjectdefs.h:80
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
Definition: qimage.cpp:5275
void clearUndoRedoStacks(Stacks historyToClear=UndoAndRedoStacks)
Clears the stacks specified by stacksToClear.
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
iterator begin() const
Returns an iterator pointing to the first document element inside the frame.
bool isRedoAvailable() const
Returns true if redo is available; otherwise returns false.
qreal width() const
Returns the width of the rectangle occupied by the image.
Definition: qtextformat.h:706
void setDocumentLayout(QAbstractTextDocumentLayout *layout)
Sets the document to use the given layout.
#define QTextEndOfFrame
BorderStyle borderStyle() const
Returns the style of the frame&#39;s border.
Definition: qtextformat.h:772
void emitFragment(const QTextFragment &fragment)
Q_GUI_EXPORT QTextCodec * codecForHtml(const QByteArray &ba)
This function is defined in the <QTextDocument> header file.
QFont defaultFont() const
QTextListFormat format() const
Returns the list&#39;s format.
Definition: qtextlist.h:80
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
QTextLength lengthProperty(int propertyId) const
Returns the value of the property given by propertyId.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
QTextBlock firstBlock() const
Returns the document&#39;s first text block.