Qt 4.8
Functions
qtextdocument.cpp File Reference
#include "qtextdocument.h"
#include <qtextformat.h>
#include "qtextdocumentlayout_p.h"
#include "qtextdocumentfragment.h"
#include "qtextdocumentfragment_p.h"
#include "qtexttable.h"
#include "qtextlist.h"
#include <qdebug.h>
#include <qregexp.h>
#include <qvarlengtharray.h>
#include <qtextcodec.h>
#include <qthread.h>
#include "qtexthtmlparser_p.h"
#include "qpainter.h"
#include "qprinter.h"
#include "qtextedit.h"
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qapplication.h>
#include "qtextcontrol_p.h"
#include "qfont_p.h"
#include "private/qtextedit_p.h"
#include "private/qdataurl_p.h"
#include "qtextdocument_p.h"
#include <private/qprinter_p.h>
#include <private/qabstracttextdocumentlayout_p.h>
#include <limits.h>

Go to the source code of this file.

Functions

static bool findInBlock (const QTextBlock &block, const QRegExp &expression, int offset, QTextDocument::FindFlags options, QTextCursor &cursor)
 
static QTextFormat formatDifference (const QTextFormat &from, const QTextFormat &to)
 
static bool isOrderedList (int style)
 
static void printPage (int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos)
 
bool qHasPixmapTexture (const QBrush &brush)
 
Q_CORE_EXPORT unsigned int qt_int_sqrt (unsigned int n)
 

Function Documentation

◆ findInBlock()

static bool findInBlock ( const QTextBlock block,
const QRegExp expression,
int  offset,
QTextDocument::FindFlags  options,
QTextCursor cursor 
)
static

Definition at line 1448 of file qtextdocument.cpp.

Referenced by QTextDocument::find().

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 }
QString text() const
Returns the block&#39;s contents as plain text.
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
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
int position() const
Returns the index of the block&#39;s first character within the document.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int position() const
Returns the absolute position of the cursor within the document.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define text
Definition: qobjectdefs.h:80
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681

◆ formatDifference()

static QTextFormat formatDifference ( const QTextFormat from,
const QTextFormat to 
)
static

Definition at line 2209 of file qtextdocument.cpp.

Referenced by QTextHtmlExporter::emitBlock(), and QTextHtmlExporter::emitBlockAttributes().

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 }
#define it(className, varName)
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
static Bigint * diff(Bigint *a, Bigint *b)
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
static const KeyPair *const end
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ isOrderedList()

static bool isOrderedList ( int  style)
static

◆ printPage()

static void printPage ( int  index,
QPainter painter,
const QTextDocument doc,
const QRectF body,
const QPointF pageNumberPos 
)
static

Definition at line 1829 of file qtextdocument.cpp.

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 }
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
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
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
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFont defaultFont
the default font used to display the document&#39;s text
QPalette palette
the default color that is used for the text, when no color is specified.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
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
QFontMetrics fontMetrics() const
Returns the font metrics for the painter if the painter is active.
Definition: qpainter.cpp:2077
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const char * layout
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF clip
a hint to the layout specifying the area around paragraphs, frames or text require painting...
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Definition: qpainter.cpp:2517
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
#define ctx
Definition: qgl.cpp:6094
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
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
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ qHasPixmapTexture()

bool qHasPixmapTexture ( const QBrush brush)

Definition at line 223 of file qbrush.cpp.

Referenced by QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitBlock(), QGL2PaintEngineExPrivate::setBrush(), QSpanData::setup(), and QGL2PaintEngineExPrivate::updateBrushUniforms().

224 {
225  if (brush.style() != Qt::TexturePattern)
226  return false;
227  QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data());
228  return tx_data->m_has_pixmap_texture;
229 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
bool m_has_pixmap_texture
Definition: qbrush.cpp:218

◆ qt_int_sqrt()

Q_CORE_EXPORT unsigned int qt_int_sqrt ( unsigned int  n)

Definition at line 2478 of file qglobal.cpp.

Referenced by QTextDocument::adjustSize(), and qt_int_sqrt().

2479 {
2480  // n must be in the range 0...UINT_MAX/2-1
2481  if (n >= (UINT_MAX>>2)) {
2482  unsigned int r = 2 * qt_int_sqrt(n / 4);
2483  unsigned int r2 = r + 1;
2484  return (n >= r2 * r2) ? r2 : r;
2485  }
2486  uint h, p= 0, q= 1, r= n;
2487  while (q <= n)
2488  q <<= 2;
2489  while (q != 1) {
2490  q >>= 2;
2491  h= p + q;
2492  p >>= 1;
2493  if (r >= h) {
2494  p += q;
2495  r -= h;
2496  }
2497  }
2498  return p;
2499 }
unsigned int uint
Definition: qglobal.h:996
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
Definition: qglobal.cpp:2478