Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QStaticTextPrivate Class Reference

#include <qstatictext_p.h>

Public Functions

void init ()
 
void invalidate ()
 
void paintText (const QPointF &pos, QPainter *p)
 
 QStaticTextPrivate ()
 
 QStaticTextPrivate (const QStaticTextPrivate &other)
 
 ~QStaticTextPrivate ()
 

Static Public Functions

static QStaticTextPrivateget (const QStaticText *q)
 

Public Variables

QSizeF actualSize
 
QCharcharPool
 
QFont font
 
glyph_tglyphPool
 
int itemCount
 
QStaticTextItemitems
 
QTransform matrix
 
unsigned char needsRelayout: 1
 
QPointF position
 
QFixedPointpositionPool
 
QAtomicInt ref
 
QString text
 
unsigned char textFormat: 2
 
QTextOption textOption
 
qreal textWidth
 
unsigned char untransformedCoordinates: 1
 
unsigned char useBackendOptimizations: 1
 

Detailed Description

Definition at line 158 of file qstatictext_p.h.

Constructors and Destructors

◆ QStaticTextPrivate() [1/2]

QStaticTextPrivate::QStaticTextPrivate ( )

Definition at line 401 of file qstatictext.cpp.

402  : textWidth(-1.0), items(0), itemCount(0), glyphPool(0), positionPool(0), charPool(0),
405 {
406 }
QFixedPoint * positionPool
unsigned char untransformedCoordinates
QStaticTextItem * items
unsigned char textFormat
unsigned char useBackendOptimizations
unsigned char needsRelayout

◆ QStaticTextPrivate() [2/2]

QStaticTextPrivate::QStaticTextPrivate ( const QStaticTextPrivate other)

Definition at line 408 of file qstatictext.cpp.

409  : text(other.text), font(other.font), textWidth(other.textWidth), matrix(other.matrix),
413 {
414 }
QFixedPoint * positionPool
unsigned char untransformedCoordinates
QStaticTextItem * items
QTextOption textOption
unsigned char textFormat
unsigned char useBackendOptimizations
unsigned char needsRelayout

◆ ~QStaticTextPrivate()

QStaticTextPrivate::~QStaticTextPrivate ( )

Definition at line 416 of file qstatictext.cpp.

417 {
418  delete[] items;
419  delete[] glyphPool;
420  delete[] positionPool;
421  delete[] charPool;
422 }
QFixedPoint * positionPool
QStaticTextItem * items

Functions

◆ get()

QStaticTextPrivate * QStaticTextPrivate::get ( const QStaticText q)
static

Definition at line 424 of file qstatictext.cpp.

Referenced by QPainter::drawStaticText().

425 {
426  return q->data.data();
427 }
QExplicitlySharedDataPointer< QStaticTextPrivate > data
Definition: qstatictext.h:99
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145

◆ init()

void QStaticTextPrivate::init ( )

Definition at line 677 of file qstatictext.cpp.

Referenced by QPainter::drawStaticText(), QStaticText::prepare(), and QStaticText::size().

678 {
679  delete[] items;
680  delete[] glyphPool;
681  delete[] positionPool;
682  delete[] charPool;
683 
684  position = QPointF(0, 0);
685 
686  DrawTextItemDevice device(untransformedCoordinates, useBackendOptimizations);
687  {
688  QPainter painter(&device);
689  painter.setFont(font);
690  painter.setTransform(matrix);
691 
692  paintText(QPointF(0, 0), &painter);
693  }
694 
695  QVector<QStaticTextItem> deviceItems = device.items();
696  QVector<QFixedPoint> positions = device.positions();
697  QVector<glyph_t> glyphs = device.glyphs();
698  QVector<QChar> chars = device.chars();
699 
700  itemCount = deviceItems.size();
702 
703  glyphPool = new glyph_t[glyphs.size()];
704  memcpy(glyphPool, glyphs.constData(), glyphs.size() * sizeof(glyph_t));
705 
706  positionPool = new QFixedPoint[positions.size()];
707  memcpy(positionPool, positions.constData(), positions.size() * sizeof(QFixedPoint));
708 
709  charPool = new QChar[chars.size()];
710  memcpy(charPool, chars.constData(), chars.size() * sizeof(QChar));
711 
712  for (int i=0; i<itemCount; ++i) {
713  items[i] = deviceItems.at(i);
714 
717  items[i].chars = charPool + items[i].charOffset;
718  }
719 
720  needsRelayout = false;
721 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QFixedPoint * positionPool
QFixedPoint * glyphPositions
unsigned char untransformedCoordinates
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QStaticTextItem * items
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
unsigned char useBackendOptimizations
unsigned char needsRelayout
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
unsigned int glyph_t
void paintText(const QPointF &pos, QPainter *p)
glyph_t * glyphs

◆ invalidate()

void QStaticTextPrivate::invalidate ( )
inline

◆ paintText()

void QStaticTextPrivate::paintText ( const QPointF pos,
QPainter p 
)

Definition at line 611 of file qstatictext.cpp.

Referenced by QPainter::drawStaticText(), and init().

612 {
613  bool preferRichText = textFormat == Qt::RichText
615 
616  if (!preferRichText) {
617  QTextLayout textLayout;
618  textLayout.setText(text);
619  textLayout.setFont(font);
620  textLayout.setTextOption(textOption);
621 
622  qreal leading = QFontMetricsF(font).leading();
623  qreal height = -leading;
624 
625  textLayout.beginLayout();
626  while (1) {
627  QTextLine line = textLayout.createLine();
628  if (!line.isValid())
629  break;
630 
631  if (textWidth >= 0.0)
632  line.setLineWidth(textWidth);
633  height += leading;
634  line.setPosition(QPointF(0.0, height));
635  height += line.height();
636  }
637  textLayout.endLayout();
638 
639  actualSize = textLayout.boundingRect().size();
640  textLayout.draw(p, topLeftPosition);
641  } else {
642  QTextDocument document;
643 #ifndef QT_NO_CSSPARSER
644  QColor color = p->pen().color();
645  document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")
646  .arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))
647  .arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))
648  .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));
649 #endif
650  document.setDefaultFont(font);
651  document.setDocumentMargin(0.0);
652 #ifndef QT_NO_TEXTHTMLPARSER
653  document.setHtml(text);
654 #else
655  document.setPlainText(text);
656 #endif
657  if (textWidth >= 0.0)
658  document.setTextWidth(textWidth);
659  else
660  document.adjustSize();
662 
663  p->save();
664  p->translate(topLeftPosition);
666  ctx.palette.setColor(QPalette::Text, p->pen().color());
667  document.documentLayout()->draw(p, ctx);
668  p->restore();
669 
670  if (textWidth >= 0.0)
671  document.adjustSize(); // Find optimal size
672 
673  actualSize = document.size();
674  }
675 }
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 QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setText(const QString &string)
Sets the layout&#39;s text to the given string.
double qreal
Definition: qglobal.h:1193
void setPosition(const QPointF &pos)
Moves the line to position pos.
void adjustSize()
Adjusts the document to a reasonable size.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setFont(const QFont &f)
Sets the layout&#39;s font to the given font.
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
void setLineWidth(qreal width)
Lays out the line with the given width.
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
QPalette palette
the default color that is used for the text, when no color is specified.
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
QTextOption textOption
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
QSizeF size
Returns the actual size of the document.
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
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.
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
qreal leading() const
Returns the leading of the font.
void setTextWidth(qreal width)
unsigned char textFormat
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
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
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
#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...
void setDocumentMargin(qreal margin)
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setDefaultStyleSheet(const QString &sheet)
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
void endLayout()
Ends the layout process.
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
qreal height() const
Returns the line&#39;s height.
void beginLayout()
Begins the layout process.
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

Properties

◆ actualSize

QSizeF QStaticTextPrivate::actualSize

Definition at line 178 of file qstatictext_p.h.

Referenced by paintText(), and QStaticText::size().

◆ charPool

QChar* QStaticTextPrivate::charPool

Definition at line 187 of file qstatictext_p.h.

Referenced by init(), and ~QStaticTextPrivate().

◆ font

QFont QStaticTextPrivate::font

◆ glyphPool

glyph_t* QStaticTextPrivate::glyphPool

Definition at line 185 of file qstatictext_p.h.

Referenced by init(), and ~QStaticTextPrivate().

◆ itemCount

int QStaticTextPrivate::itemCount

Definition at line 183 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), and init().

◆ items

QStaticTextItem* QStaticTextPrivate::items

Definition at line 182 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), get(), init(), and ~QStaticTextPrivate().

◆ matrix

QTransform QStaticTextPrivate::matrix

Definition at line 181 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), get(), init(), and QStaticText::prepare().

◆ needsRelayout

unsigned char QStaticTextPrivate::needsRelayout

Definition at line 191 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), init(), and QStaticText::size().

◆ position

QPointF QStaticTextPrivate::position

Definition at line 179 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), get(), and init().

◆ positionPool

QFixedPoint* QStaticTextPrivate::positionPool

Definition at line 186 of file qstatictext_p.h.

Referenced by init(), and ~QStaticTextPrivate().

◆ ref

QAtomicInt QStaticTextPrivate::ref

Definition at line 173 of file qstatictext_p.h.

Referenced by QStaticText::detach(), and QStaticText::~QStaticText().

◆ text

QString QStaticTextPrivate::text

◆ textFormat

unsigned char QStaticTextPrivate::textFormat

Definition at line 193 of file qstatictext_p.h.

Referenced by paintText(), QStaticText::setTextFormat(), and QStaticText::textFormat().

◆ textOption

QTextOption QStaticTextPrivate::textOption

Definition at line 189 of file qstatictext_p.h.

Referenced by paintText(), QStaticText::setTextOption(), and QStaticText::textOption().

◆ textWidth

qreal QStaticTextPrivate::textWidth

◆ untransformedCoordinates

unsigned char QStaticTextPrivate::untransformedCoordinates

Definition at line 194 of file qstatictext_p.h.

Referenced by QPainter::drawStaticText(), get(), and init().

◆ useBackendOptimizations

unsigned char QStaticTextPrivate::useBackendOptimizations

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