Qt 4.8
Classes | Macros | Functions
qtextdocumentlayout.cpp File Reference
#include "qtextdocumentlayout_p.h"
#include "qtextdocument_p.h"
#include "qtextimagehandler_p.h"
#include "qtexttable.h"
#include "qtextlist.h"
#include "qtextengine_p.h"
#include "private/qcssutil_p.h"
#include "qabstracttextdocumentlayout_p.h"
#include "qcssparser_p.h"
#include <qpainter.h>
#include <qmath.h>
#include <qrect.h>
#include <qpalette.h>
#include <qdebug.h>
#include <qvarlengtharray.h>
#include <limits.h>
#include <qstyle.h>
#include <qbasictimer.h>
#include "private/qfunctions_p.h"
#include "moc_qtextdocumentlayout_p.cpp"

Go to the source code of this file.

Classes

struct  QCheckPoint
 
class  QTextDocumentLayoutPrivate
 
class  QTextFrameData
 
struct  QTextLayoutStruct
 
class  QTextTableData
 

Macros

#define DEC_INDENT   do {} while(0)
 
#define INC_INDENT   do {} while(0)
 
#define LDEBUG   if(0) qDebug()
 

Functions

static void adjustContextSelectionsForCell (QAbstractTextDocumentLayout::PaintContext &cell_context, const QTextTableCell &cell, int r, int c, const int *selectedTableCells)
 
static QTextFrameDatacreateData (QTextFrame *f)
 
static QTextFrameDatadata (QTextFrame *f)
 
static void fillBackground (QPainter *p, const QRectF &rect, QBrush brush, const QPointF &origin, QRectF gradientRect=QRectF())
 
static QFixed firstChildPos (const QTextFrame *f)
 
static QFixed flowPosition (const QTextFrame::iterator it)
 
static void getLineHeightParams (const QTextBlockFormat &blockFormat, const QTextLine &line, qreal scaling, QFixed *lineAdjustment, QFixed *lineBreakHeight, QFixed *lineHeight)
 
static bool isEmptyBlockAfterTable (const QTextBlock &block, const QTextFrame *previousFrame)
 
static bool isEmptyBlockBeforeTable (const QTextBlock &block, const QTextBlockFormat &format, const QTextFrame::Iterator &nextIt)
 
static bool isEmptyBlockBeforeTable (QTextFrame::Iterator it)
 
static bool isFrameFromInlineObject (QTextFrame *f)
 
static bool isLineSeparatorBlockAfterTable (const QTextBlock &block, const QTextFrame *previousFrame)
 
static void markFrames (QTextFrame *current, int from, int oldLength, int length)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QCheckPoint &checkPoint, QFixed y)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QCheckPoint &checkPoint, int pos)
 
 Q_DECLARE_TYPEINFO (QCheckPoint, Q_PRIMITIVE_TYPE)
 

Macro Definition Documentation

◆ DEC_INDENT

#define DEC_INDENT   do {} while(0)

Definition at line 73 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::hitTest().

◆ INC_INDENT

#define INC_INDENT   do {} while(0)

Definition at line 72 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::hitTest().

◆ LDEBUG

#define LDEBUG   if(0) qDebug()

Function Documentation

◆ adjustContextSelectionsForCell()

static void adjustContextSelectionsForCell ( QAbstractTextDocumentLayout::PaintContext cell_context,
const QTextTableCell cell,
int  r,
int  c,
const int *  selectedTableCells 
)
static

Definition at line 896 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFrame().

900 {
901  for (int i = 0; i < cell_context.selections.size(); ++i) {
902  int row_start = selectedTableCells[i * 4];
903  int col_start = selectedTableCells[i * 4 + 1];
904  int num_rows = selectedTableCells[i * 4 + 2];
905  int num_cols = selectedTableCells[i * 4 + 3];
906 
907  if (row_start != -1) {
908  if (r >= row_start && r < row_start + num_rows
909  && c >= col_start && c < col_start + num_cols)
910  {
911  int firstPosition = cell.firstPosition();
912  int lastPosition = cell.lastPosition();
913 
914  // make sure empty cells are still selected
915  if (firstPosition == lastPosition)
916  ++lastPosition;
917 
918  cell_context.selections[i].cursor.setPosition(firstPosition);
919  cell_context.selections[i].cursor.setPosition(lastPosition, QTextCursor::KeepAnchor);
920  } else {
921  cell_context.selections[i].cursor.clearSelection();
922  }
923  }
924 
925  // FullWidthSelection is not useful for tables
926  cell_context.selections[i].format.clearProperty(QTextFormat::FullWidthSelection);
927  }
928 }
unsigned char c[8]
Definition: qnumeric_p.h:62
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
Definition: qtexttable.cpp:273
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
Definition: qtexttable.cpp:287
QVector< Selection > selections
the collection of selections that will be rendered when passing this paint context to QAbstractTextDo...

◆ createData()

static QTextFrameData* createData ( QTextFrame f)
static

Definition at line 237 of file qtextdocumentlayout.cpp.

Referenced by data().

238 {
240  if (qobject_cast<QTextTable *>(f))
241  data = new QTextTableData;
242  else
243  data = new QTextFrameData;
244  f->setLayoutData(data);
245  return data;
246 }
static QTextFrameData * data(QTextFrame *f)
void setLayoutData(QTextFrameLayoutData *data)

◆ data()

static QTextFrameData* data ( QTextFrame f)
inlinestatic

◆ fillBackground()

static void fillBackground ( QPainter p,
const QRectF rect,
QBrush  brush,
const QPointF origin,
QRectF  gradientRect = QRectF() 
)
static

Definition at line 402 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QTextDocumentLayoutPrivate::drawTableCell(), and QGraphicsWidget::paintWindowFrame().

403 {
404  p->save();
405  if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
406  if (!gradientRect.isNull()) {
407  QTransform m;
408  m.translate(gradientRect.left(), gradientRect.top());
409  m.scale(gradientRect.width(), gradientRect.height());
410  brush.setTransform(m);
411  const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode);
412  }
413  } else {
414  p->setBrushOrigin(origin);
415  }
416  p->fillRect(rect, brush);
417  p->restore();
418 }
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:968
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
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ firstChildPos()

static QFixed firstChildPos ( const QTextFrame f)
static

Definition at line 1494 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutFlow().

1495 {
1496  return flowPosition(f->begin());
1497 }
static QFixed flowPosition(const QTextFrame::iterator it)
iterator begin() const
Returns an iterator pointing to the first document element inside the frame.

◆ flowPosition()

static QFixed flowPosition ( const QTextFrame::iterator  it)
static

Definition at line 1477 of file qtextdocumentlayout.cpp.

Referenced by QIconModeViewBase::doDynamicLayout(), QListModeViewBase::doStaticLayout(), firstChildPos(), and QTextDocumentLayoutPrivate::layoutTable().

1478 {
1479  if (it.atEnd())
1480  return 0;
1481 
1482  if (it.currentFrame()) {
1483  return data(it.currentFrame())->position.y;
1484  } else {
1485  QTextBlock block = it.currentBlock();
1486  QTextLayout *layout = block.layout();
1487  if (layout->lineCount() == 0)
1488  return QFixed::fromReal(layout->position().y());
1489  else
1490  return QFixed::fromReal(layout->position().y() + layout->lineAt(0).y());
1491  }
1492 }
QPointF position() const
The global position of the layout.
qreal y() const
Returns the line&#39;s y position.
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
static QTextFrameData * data(QTextFrame *f)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool atEnd() const
Returns true if the current item is the last item in the text frame.
Definition: qtextobject.h:165
QTextBlock currentBlock() const
Returns the current block the iterator points to.
int lineCount() const
Returns the number of lines in this text layout.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ getLineHeightParams()

static void getLineHeightParams ( const QTextBlockFormat blockFormat,
const QTextLine line,
qreal  scaling,
QFixed lineAdjustment,
QFixed lineBreakHeight,
QFixed lineHeight 
)
inlinestatic

Definition at line 2520 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutBlock().

2522 {
2523  *lineHeight = QFixed::fromReal(blockFormat.lineHeight(line.height(), scaling));
2524 
2526  *lineBreakHeight = *lineHeight;
2527  if (blockFormat.lineHeightType() == QTextBlockFormat::FixedHeight)
2528  *lineAdjustment = QFixed::fromReal(line.ascent() + qMax(line.leading(), qreal(0.0))) - ((*lineHeight * 4) / 5);
2529  else
2530  *lineAdjustment = QFixed::fromReal(line.height()) - *lineHeight;
2531  }
2532  else {
2533  *lineBreakHeight = QFixed::fromReal(line.height());
2534  *lineAdjustment = 0;
2535  }
2536 }
double qreal
Definition: qglobal.h:1193
qreal leading() const
Returns the line&#39;s leading.
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
qreal ascent() const
Returns the line&#39;s ascent.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal lineHeight(qreal scriptLineHeight, qreal scaling) const
Returns the height of the lines in the paragraph based on the height of the script line given by scri...
Definition: qtextformat.h:625
int lineHeightType() const
This returns the LineHeightType property of the paragraph.
Definition: qtextformat.h:598
qreal height() const
Returns the line&#39;s height.

◆ isEmptyBlockAfterTable()

static bool isEmptyBlockAfterTable ( const QTextBlock block,
const QTextFrame previousFrame 
)
inlinestatic

Definition at line 307 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFlow(), and QTextDocumentLayoutPrivate::layoutFlow().

308 {
309  return qobject_cast<const QTextTable *>(previousFrame)
310  && block.isValid()
311  && block.length() == 1
312  && previousFrame->lastPosition() == block.position() - 1
313  ;
314 }
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int position() const
Returns the index of the block&#39;s first character within the document.
int lastPosition() const
Returns the last document position inside the frame.
int length() const
Returns the length of the block in characters.
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208

◆ isEmptyBlockBeforeTable() [1/2]

static bool isEmptyBlockBeforeTable ( const QTextBlock block,
const QTextBlockFormat format,
const QTextFrame::Iterator nextIt 
)
inlinestatic

Definition at line 286 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFlow(), QTextDocumentLayoutPrivate::hitTest(), isEmptyBlockBeforeTable(), and QTextDocumentLayoutPrivate::layoutFlow().

287 {
288  return !nextIt.atEnd()
289  && qobject_cast<QTextTable *>(nextIt.currentFrame())
290  && block.isValid()
291  && block.length() == 1
294  && nextIt.currentFrame()->firstPosition() == block.position() + 1
295  ;
296 }
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int firstPosition() const
Returns the first document position inside the frame.
int position() const
Returns the index of the block&#39;s first character within the document.
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
int length() const
Returns the length of the block in characters.
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
bool atEnd() const
Returns true if the current item is the last item in the text frame.
Definition: qtextobject.h:165

◆ isEmptyBlockBeforeTable() [2/2]

static bool isEmptyBlockBeforeTable ( QTextFrame::Iterator  it)
inlinestatic

Definition at line 298 of file qtextdocumentlayout.cpp.

299 {
300  QTextFrame::Iterator next = it; ++next;
301  if (it.currentFrame())
302  return false;
303  QTextBlock block = it.currentBlock();
304  return isEmptyBlockBeforeTable(block, block.blockFormat(), next);
305 }
#define it(className, varName)
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
Definition: qtextobject.h:144
QTextBlock currentBlock() const
Returns the current block the iterator points to.
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
static bool isEmptyBlockBeforeTable(const QTextBlock &block, const QTextBlockFormat &format, const QTextFrame::Iterator &nextIt)

◆ isFrameFromInlineObject()

static bool isFrameFromInlineObject ( QTextFrame f)
static

Definition at line 256 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFlow(), QTextDocumentLayoutPrivate::hitTest(), and QTextDocumentLayoutPrivate::layoutFrame().

257 {
258  return f->firstPosition() > f->lastPosition();
259 }
int firstPosition() const
Returns the first document position inside the frame.
int lastPosition() const
Returns the last document position inside the frame.

◆ isLineSeparatorBlockAfterTable()

static bool isLineSeparatorBlockAfterTable ( const QTextBlock block,
const QTextFrame previousFrame 
)
inlinestatic

Definition at line 316 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutFlow().

317 {
318  return qobject_cast<const QTextTable *>(previousFrame)
319  && block.isValid()
320  && block.length() > 1
321  && block.text().at(0) == QChar::LineSeparator
322  && previousFrame->lastPosition() == block.position() - 1
323  ;
324 }
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
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int position() const
Returns the index of the block&#39;s first character within the document.
int lastPosition() const
Returns the last document position inside the frame.
int length() const
Returns the length of the block in characters.
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208

◆ markFrames()

static void markFrames ( QTextFrame current,
int  from,
int  oldLength,
int  length 
)
static

Definition at line 2847 of file qtextdocumentlayout.cpp.

Referenced by QTextDocumentLayout::doLayout().

2848 {
2849  int end = qMax(oldLength, length) + from;
2850 
2851  if (current->firstPosition() >= end || current->lastPosition() < from)
2852  return;
2853 
2854  QTextFrameData *fd = data(current);
2855  for (int i = 0; i < fd->floats.size(); ++i) {
2856  QTextFrame *f = fd->floats[i];
2857  if (!f) {
2858  // float got removed in editing operation
2859  fd->floats.removeAt(i);
2860  --i;
2861  }
2862  }
2863 
2864  fd->layoutDirty = true;
2865  fd->sizeDirty = true;
2866 
2867 // qDebug(" marking frame (%d--%d) as dirty", current->firstPosition(), current->lastPosition());
2868  QList<QTextFrame *> children = current->childFrames();
2869  for (int i = 0; i < children.size(); ++i)
2870  markFrames(children.at(i), from, oldLength, length);
2871 }
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
int firstPosition() const
Returns the first document position inside the frame.
QList< QPointer< QTextFrame > > floats
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int lastPosition() const
Returns the last document position inside the frame.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QTextFrame * > childFrames() const
Returns a (possibly empty) list of the frame&#39;s child frames.
static QTextFrameData * data(QTextFrame *f)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static const KeyPair *const end
static void markFrames(QTextFrame *current, int from, int oldLength, int length)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ operator<() [1/2]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QCheckPoint checkPoint,
QFixed  y 
)

Definition at line 392 of file qtextdocumentlayout.cpp.

393 {
394  return checkPoint.y < y;
395 }

◆ operator<() [2/2]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QCheckPoint checkPoint,
int  pos 
)

Definition at line 397 of file qtextdocumentlayout.cpp.

398 {
399  return checkPoint.positionInFrame < pos;
400 }

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QCheckPoint  ,
Q_PRIMITIVE_TYPE   
)