Qt 4.8
Public Functions | Properties | List of all members
QDeclarativeTextLayout Class Reference

The QDeclarativeTextLayout class is a version of QStaticText that works with QTextLayouts. More...

#include <qdeclarativetextlayout_p.h>

Inheritance diagram for QDeclarativeTextLayout:
QTextLayout

Public Functions

void beginLayout ()
 
void clearLayout ()
 
void draw (QPainter *, const QPointF &=QPointF())
 
void prepare ()
 
 QDeclarativeTextLayout ()
 
 QDeclarativeTextLayout (const QString &)
 
 ~QDeclarativeTextLayout ()
 
- Public Functions inherited from QTextLayout
QList< FormatRangeadditionalFormats () const
 Returns the list of additional formats supported by the text layout. More...
 
void beginLayout ()
 Begins the layout process. More...
 
QRectF boundingRect () const
 The smallest rectangle that contains all the lines in the layout. More...
 
bool cacheEnabled () const
 Returns true if the complete layout information is cached; otherwise returns false. More...
 
void clearAdditionalFormats ()
 Clears the list of additional formats supported by the text layout. More...
 
void clearLayout ()
 Clears the line information in the layout. More...
 
QTextLine createLine ()
 Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise returns an invalid text line. More...
 
Qt::CursorMoveStyle cursorMoveStyle () const
 The cursor movement style of this QTextLayout. More...
 
void draw (QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
 Draws the whole layout on the painter p at the position specified by pos. More...
 
void drawCursor (QPainter *p, const QPointF &pos, int cursorPosition) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws a text cursor with the current pen at the given position using the painter specified. More...
 
void drawCursor (QPainter *p, const QPointF &pos, int cursorPosition, int width) const
 Draws a text cursor with the current pen and the specified width at the given position using the painter specified. More...
 
void endLayout ()
 Ends the layout process. More...
 
QTextEngineengine () const
 
QFont font () const
 Returns the current font that is used for the layout, or a default font if none is set. More...
 
QList< QGlyphRunglyphRuns () const
 Returns the glyph indexes and positions for all glyphs in this QTextLayout. More...
 
bool isValidCursorPosition (int pos) const
 / Returns true if position pos is a valid cursor position. More...
 
int leftCursorPosition (int oldPos) const
 Returns the cursor position to the left of oldPos, next to it. More...
 
QTextLine lineAt (int i) const
 Returns the {i}-th line of text in this text layout. More...
 
int lineCount () const
 Returns the number of lines in this text layout. More...
 
QTextLine lineForTextPosition (int pos) const
 Returns the line that contains the cursor position specified by pos. More...
 
qreal maximumWidth () const
 The maximum width the layout could expand to; this is essentially the width of the entire text. More...
 
qreal minimumWidth () const
 The minimum width the layout needs. More...
 
int nextCursorPosition (int oldPos, CursorMode mode=SkipCharacters) const
 Returns the next valid cursor position after oldPos that respects the given cursor mode. More...
 
QPointF position () const
 The global position of the layout. More...
 
int preeditAreaPosition () const
 Returns the position of the area in the text layout that will be processed before editing occurs. More...
 
QString preeditAreaText () const
 Returns the text that is inserted in the layout before editing occurs. More...
 
int previousCursorPosition (int oldPos, CursorMode mode=SkipCharacters) const
 Returns the first valid cursor position before oldPos that respects the given cursor mode. More...
 
 QTextLayout ()
 Constructs an empty text layout. More...
 
 QTextLayout (const QString &text)
 Constructs a text layout to lay out the given text. More...
 
 QTextLayout (const QString &text, const QFont &font, QPaintDevice *paintdevice=0)
 Constructs a text layout to lay out the given text with the specified font. More...
 
 QTextLayout (const QTextBlock &b)
 Constructs a text layout to lay out the given block. More...
 
int rightCursorPosition (int oldPos) const
 Returns the cursor position to the right of oldPos, next to it. More...
 
void setAdditionalFormats (const QList< FormatRange > &overrides)
 Sets the additional formats supported by the text layout to formatList. More...
 
void setCacheEnabled (bool enable)
 Enables caching of the complete layout information if enable is true; otherwise disables layout caching. More...
 
void setCursorMoveStyle (Qt::CursorMoveStyle style)
 Set the cursor movement style. More...
 
void setFlags (int flags)
 
void setFont (const QFont &f)
 Sets the layout's font to the given font. More...
 
void setPosition (const QPointF &p)
 Moves the text layout to point p. More...
 
void setPreeditArea (int position, const QString &text)
 Sets the position and text of the area in the layout that is processed before editing occurs. More...
 
void setText (const QString &string)
 Sets the layout's text to the given string. More...
 
void setTextOption (const QTextOption &option)
 Sets the text option structure that controls the layout process to the given option. More...
 
QString text () const
 Returns the layout's text. More...
 
QTextOption textOption () const
 Returns the current text option used to control the layout process. More...
 
 ~QTextLayout ()
 Destructs the layout. More...
 

Properties

QDeclarativeTextLayoutPrivated
 

Additional Inherited Members

- Public Types inherited from QTextLayout
enum  CursorMode { SkipCharacters, SkipWords }
 

Detailed Description

The QDeclarativeTextLayout class is a version of QStaticText that works with QTextLayouts.

Warning
This function is not part of the public interface.

This class is basically a copy of the QStaticText code, but it is adapted to source its text from QTextLayout.

It is also considerably faster to create a QDeclarativeTextLayout than a QStaticText because it uses a single, shared QPainter instance. QStaticText by comparison creates a new QPainter per instance. As a consequence this means that QDeclarativeTextLayout is not re-enterant. Adding a lock around the shared painter solves this, and only introduces a minor performance penalty, but is unnecessary for QDeclarativeTextLayout's current use (QDeclarativeText is already tied to the GUI thread).

Definition at line 54 of file qdeclarativetextlayout_p.h.

Constructors and Destructors

◆ QDeclarativeTextLayout() [1/2]

QDeclarativeTextLayout::QDeclarativeTextLayout ( )

Definition at line 268 of file qdeclarativetextlayout.cpp.

269 : d(0)
270 {
271 }
QDeclarativeTextLayoutPrivate * d

◆ QDeclarativeTextLayout() [2/2]

QDeclarativeTextLayout::QDeclarativeTextLayout ( const QString text)

Definition at line 273 of file qdeclarativetextlayout.cpp.

274 : QTextLayout(text), d(0)
275 {
276 }
QTextLayout()
Constructs an empty text layout.
QDeclarativeTextLayoutPrivate * d

◆ ~QDeclarativeTextLayout()

QDeclarativeTextLayout::~QDeclarativeTextLayout ( )

Definition at line 278 of file qdeclarativetextlayout.cpp.

279 {
280  if (d) delete d;
281 }
QDeclarativeTextLayoutPrivate * d

Functions

◆ beginLayout()

void QDeclarativeTextLayout::beginLayout ( )

Definition at line 283 of file qdeclarativetextlayout.cpp.

284 {
285  if (d && d->cached) {
286  d->cached = false;
287  d->items.clear();
288  d->positions.clear();
289  d->glyphs.clear();
290  d->chars.clear();
291  d->position = QPointF();
292  }
294 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QVector< QStaticTextItem > items
QDeclarativeTextLayoutPrivate * d
void beginLayout()
Begins the layout process.

◆ clearLayout()

void QDeclarativeTextLayout::clearLayout ( )

Definition at line 296 of file qdeclarativetextlayout.cpp.

297 {
298  if (d && d->cached) {
299  d->cached = false;
300  d->items.clear();
301  d->positions.clear();
302  d->glyphs.clear();
303  d->chars.clear();
304  d->position = QPointF();
305  }
307 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QVector< QStaticTextItem > items
void clearLayout()
Clears the line information in the layout.
QDeclarativeTextLayoutPrivate * d

◆ draw()

void QDeclarativeTextLayout::draw ( QPainter painter,
const QPointF p = QPointF() 
)

Definition at line 342 of file qdeclarativetextlayout.cpp.

343 {
345 
346  bool paintEngineSupportsTransformations = priv->extended &&
347  (priv->extended->type() == QPaintEngine::OpenGL2 ||
348  priv->extended->type() == QPaintEngine::OpenVG ||
349  priv->extended->type() == QPaintEngine::OpenGL);
350 
351  if (!paintEngineSupportsTransformations || !priv->state->matrix.isAffine()) {
352  QTextLayout::draw(painter, p);
353  return;
354  }
355 
356  prepare();
357 
358  int itemCount = d->items.count();
359 
360  if (p != d->position) {
361  QFixed fx = QFixed::fromReal(p.x());
362  QFixed fy = QFixed::fromReal(p.y());
363  QFixed oldX = QFixed::fromReal(d->position.x());
364  QFixed oldY = QFixed::fromReal(d->position.y());
365  for (int item = 0; item < itemCount; ++item) {
366  QStaticTextItem &textItem = d->items[item];
367 
368  for (int ii = 0; ii < textItem.numGlyphs; ++ii) {
369  textItem.glyphPositions[ii].x += fx - oldX;
370  textItem.glyphPositions[ii].y += fy - oldY;
371  }
372  textItem.userDataNeedsUpdate = true;
373  }
374 
375  d->position = p;
376  }
377 
378  QPen oldPen = priv->state->pen;
379  QColor currentColor = oldPen.color();
380  QColor defaultColor = currentColor;
381  for (int ii = 0; ii < itemCount; ++ii) {
382  QStaticTextItem &item = d->items[ii];
383  if (item.color.isValid() && currentColor != item.color) {
384  // up-edge of a <font color="">text</font> tag
385  // we set the painter pen to the text item's specified color.
386  painter->setPen(item.color);
387  currentColor = item.color;
388  } else if (!item.color.isValid() && currentColor != defaultColor) {
389  // down-edge of a <font color="">text</font> tag
390  // we reset the painter pen back to the default color.
391  currentColor = defaultColor;
392  painter->setPen(currentColor);
393  }
394  priv->extended->drawStaticTextItem(&item);
395 
397  item.numGlyphs, item.fontEngine(), painter->font(),
398  QTextCharFormat());
399  }
400  if (currentColor != oldPen.color())
401  painter->setPen(oldPen);
402 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QPaintEngineEx * extended
Definition: qpainter_p.h:263
QFontEngine * fontEngine() const
QFixedPoint * glyphPositions
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QPainterState * state
Definition: qpainter_p.h:204
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
QTransform matrix
Definition: qpainter_p.h:161
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QFixed y
Definition: qfixed_p.h:191
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
QFixed x
Definition: qfixed_p.h:190
bool isAffine() const
Returns true if the matrix represent an affine transformation, otherwise returns false.
Definition: qtransform.h:200
QVector< QStaticTextItem > items
static QPainterPrivate * get(QPainter *painter)
Definition: qpainter_p.h:249
virtual void drawStaticTextItem(QStaticTextItem *)
Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, const QFixedPoint *positions, int glyphCount, QFontEngine *fontEngine, const QFont &font, const QTextCharFormat &charFormat)
Definition: qpainter.cpp:6820
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
static const QMetaObjectPrivate * priv(const uint *data)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QDeclarativeTextLayoutPrivate * d
glyph_t * glyphs

◆ prepare()

void QDeclarativeTextLayout::prepare ( )

Definition at line 309 of file qdeclarativetextlayout.cpp.

Referenced by draw().

310 {
311  if (!d || !d->cached) {
312 
313  if (!d)
315 
316  InertTextPainter *itp = inertTextPainter();
317  itp->device.begin(d);
318  QTextLayout::draw(&itp->painter, QPointF(0, 0));
319 
320  glyph_t *glyphPool = d->glyphs.data();
321  QFixedPoint *positionPool = d->positions.data();
322  QChar *charPool = d->chars.data();
323 
324  int itemCount = d->items.count();
325  for (int ii = 0; ii < itemCount; ++ii) {
326  QStaticTextItem &item = d->items[ii];
327  item.glyphs = glyphPool + item.glyphOffset;
328  item.glyphPositions = positionPool + item.positionOffset;
329  item.chars = charPool + item.charOffset;
330  }
331 
332  d->cached = true;
333  }
334 }
QFixedPoint * glyphPositions
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
QVector< QStaticTextItem > items
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
QDeclarativeTextLayoutPrivate * d
unsigned int glyph_t
glyph_t * glyphs

Properties

◆ d

QDeclarativeTextLayoutPrivate* QDeclarativeTextLayout::d
private

The documentation for this class was generated from the following files: