Qt 4.8
Public Functions | Protected Functions | Private Functions | Properties | List of all members
QTextDocumentLayout Class Reference

#include <qtextdocumentlayout_p.h>

Inheritance diagram for QTextDocumentLayout:
QAbstractTextDocumentLayout QObject

Public Functions

virtual QRectF blockBoundingRect (const QTextBlock &block) const
 Returns the bounding rectangle of block. More...
 
bool contentHasAlignment () const
 
int cursorWidth () const
 
QSizeF documentSize () const
 Returns the total size of the document's layout. More...
 
void draw (QPainter *painter, const PaintContext &context)
 Draws the layout with the given painter using the given context. More...
 
QSizeF dynamicDocumentSize () const
 
int dynamicPageCount () const
 
void ensureLayouted (qreal)
 
virtual QRectF frameBoundingRect (QTextFrame *frame) const
 Returns the bounding rectangle of frame. More...
 
int hitTest (const QPointF &point, Qt::HitTestAccuracy accuracy) const
 Returns the cursor postion for the given point with the specified accuracy. More...
 
qreal idealWidth () const
 
int layoutStatus () const
 
int pageCount () const
 Returns the number of pages contained in the layout. More...
 
 QTextDocumentLayout (QTextDocument *doc)
 
void setCursorWidth (int width)
 
void setFixedColumnWidth (int width)
 
void setViewport (const QRectF &viewport)
 
- Public Functions inherited from QAbstractTextDocumentLayout
QString anchorAt (const QPointF &pos) const
 Returns the reference of the anchor the given position, or an empty string if no anchor exists at that point. More...
 
QTextDocumentdocument () const
 Returns the text document that this layout is operating on. More...
 
QTextObjectInterfacehandlerForObject (int objectType) const
 Returns a handler for objects of the given objectType. More...
 
QPaintDevicepaintDevice () const
 Returns the paint device used to render the document's layout. More...
 
 QAbstractTextDocumentLayout (QTextDocument *doc)
 Creates a new text document layout for the given document. More...
 
void registerHandler (int objectType, QObject *component)
 Registers the given component as a handler for items of the given objectType. More...
 
void setPaintDevice (QPaintDevice *device)
 Sets the paint device used for rendering the document's layout to the given device. More...
 
 ~QAbstractTextDocumentLayout ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void documentChanged (int from, int oldLength, int length)
 This function is called whenever the contents of the document change. More...
 
void drawInlineObject (QPainter *p, const QRectF &rect, QTextInlineObject item, int posInDocument, const QTextFormat &format)
 This function is called to draw the inline object, object, with the given painter within the rectangle specified by rect using the specified text format. More...
 
void positionInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format)
 Lays out the inline object item using the given text format. More...
 
void resizeInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format)
 Sets the size of the inline object item corresponding to the text format. More...
 
virtual void timerEvent (QTimerEvent *e)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QAbstractTextDocumentLayout
QTextCharFormat format (int pos)
 Returns the character format that is applicable at the given position. More...
 
int formatIndex (int pos)
 Returns the index of the format at position pos. More...
 
 QAbstractTextDocumentLayout (QAbstractTextDocumentLayoutPrivate &, QTextDocument *)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 

Private Functions

QRectF doLayout (int from, int oldLength, int length)
 
void layoutFinished ()
 

Properties

bool contentHasAlignment
 
int cursorWidth
 
qreal idealWidth
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractTextDocumentLayout
void documentSizeChanged (const QSizeF &newSize)
 This signal is emitted when the size of the document layout changes to newSize. More...
 
void pageCountChanged (int newPages)
 This signal is emitted when the number of pages in the layout changes; newPages is the updated page count. More...
 
void update (const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
 This signal is emitted when the rectangle rect has been updated. More...
 
void updateBlock (const QTextBlock &block)
 This signal is emitted when the specified block has been updated. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 66 of file qtextdocumentlayout_p.h.

Constructors and Destructors

◆ QTextDocumentLayout()

QTextDocumentLayout::QTextDocumentLayout ( QTextDocument doc)
explicit

Definition at line 2806 of file qtextdocumentlayout.cpp.

2808 {
2810 }
void registerHandler(int objectType, QObject *component)
Registers the given component as a handler for items of the given objectType.
QAbstractTextDocumentLayout(QTextDocument *doc)
Creates a new text document layout for the given document.

Functions

◆ blockBoundingRect()

QRectF QTextDocumentLayout::blockBoundingRect ( const QTextBlock block) const
virtual

Returns the bounding rectangle of block.

Implements QAbstractTextDocumentLayout.

Definition at line 3181 of file qtextdocumentlayout.cpp.

3182 {
3183  Q_D(const QTextDocumentLayout);
3184  if (d->docPrivate->pageSize.isNull() || !block.isValid())
3185  return QRectF();
3186  d->ensureLayoutedByPosition(block.position() + block.length());
3187  QTextFrame *frame = d->document->frameAt(block.position());
3188  QPointF offset;
3189  const int blockPos = block.position();
3190 
3191  while (frame) {
3192  QTextFrameData *fd = data(frame);
3193  offset += fd->position.toPointF();
3194 
3195  if (QTextTable *table = qobject_cast<QTextTable *>(frame)) {
3196  QTextTableCell cell = table->cellAt(blockPos);
3197  if (cell.isValid())
3198  offset += static_cast<QTextTableData *>(fd)->cellPosition(cell).toPointF();
3199  }
3200 
3201  frame = frame->parentFrame();
3202  }
3203 
3204  const QTextLayout *layout = block.layout();
3205  QRectF rect = layout->boundingRect();
3206  rect.moveTopLeft(layout->position() + offset);
3207  return rect;
3208 }
double d
Definition: qnumeric_p.h:62
QPointF position() const
The global position of the layout.
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
#define Q_D(Class)
Definition: qglobal.h:2482
int position() const
Returns the index of the block&#39;s first character within the document.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QTextFrame * parentFrame() const
Returns the frame&#39;s parent frame.
const char * layout
void moveTopLeft(const QPointF &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:697
int length() const
Returns the length of the block in characters.
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QPointF toPointF() const
Definition: qfixed_p.h:194
static QTextFrameData * data(QTextFrame *f)
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
Definition: qtexttable.h:77
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ contentHasAlignment()

bool QTextDocumentLayout::contentHasAlignment ( ) const

Referenced by ensureLayouted().

◆ cursorWidth()

int QTextDocumentLayout::cursorWidth ( ) const

Referenced by setCursorWidth().

◆ documentChanged()

void QTextDocumentLayout::documentChanged ( int  position,
int  charsRemoved,
int  charsAdded 
)
protectedvirtual

This function is called whenever the contents of the document change.

A change occurs when text is inserted, removed, or a combination of these two. The change is specified by position, charsRemoved, and charsAdded corresponding to the starting character position of the change, the number of characters removed from the document, and the number of characters added.

For example, when inserting the text "Hello" into an empty document, charsRemoved would be 0 and charsAdded would be 5 (the length of the string).

Replacing text is a combination of removing and inserting. For example, if the text "Hello" gets replaced by "Hi", charsRemoved would be 5 and charsAdded would be 2.

For subclasses of QAbstractTextDocumentLayout, this is the central function where a large portion of the work to lay out and position document contents is done.

For example, in a subclass that only arranges blocks of text, an implementation of this function would have to do the following:

  • Determine the list of changed QTextBlock(s) using the parameters provided.
  • Each QTextBlock object's corresponding QTextLayout object needs to be processed. You can access the QTextBlock's layout using the QTextBlock::layout() function. This processing should take the document's page size into consideration.
  • If the total number of pages changed, the pageCountChanged() signal should be emitted.
  • If the total size changed, the documentSizeChanged() signal should be emitted.
  • The update() signal should be emitted to schedule a repaint of areas in the layout that require repainting.
See also
QTextLayout

Implements QAbstractTextDocumentLayout.

Definition at line 2873 of file qtextdocumentlayout.cpp.

2874 {
2876 
2877  QTextBlock blockIt = document()->findBlock(from);
2878  QTextBlock endIt = document()->findBlock(qMax(0, from + length - 1));
2879  if (endIt.isValid())
2880  endIt = endIt.next();
2881  for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
2882  blockIt.clearLayout();
2883 
2884  if (d->docPrivate->pageSize.isNull())
2885  return;
2886 
2887  QRectF updateRect;
2888 
2889  d->lazyLayoutStepSize = 1000;
2890  d->sizeChangedTimer.stop();
2891  d->insideDocumentChange = true;
2892 
2893  const int documentLength = d->docPrivate->length();
2894  const bool fullLayout = (oldLength == 0 && length == documentLength);
2895  const bool smallChange = documentLength > 0
2896  && (qMax(length, oldLength) * 100 / documentLength) < 5;
2897 
2898  // don't show incremental layout progress (avoid scroll bar flicker)
2899  // if we see only a small change in the document and we're either starting
2900  // a layout run or we're already in progress for that and we haven't seen
2901  // any bigger change previously (showLayoutProgress already false)
2902  if (smallChange
2903  && (d->currentLazyLayoutPosition == -1 || d->showLayoutProgress == false))
2904  d->showLayoutProgress = false;
2905  else
2906  d->showLayoutProgress = true;
2907 
2908  if (fullLayout) {
2909  d->contentHasAlignment = false;
2910  d->currentLazyLayoutPosition = 0;
2911  d->checkPoints.clear();
2912  d->layoutStep();
2913  } else {
2914  d->ensureLayoutedByPosition(from);
2915  updateRect = doLayout(from, oldLength, length);
2916  }
2917 
2918  if (!d->layoutTimer.isActive() && d->currentLazyLayoutPosition != -1)
2919  d->layoutTimer.start(10, this);
2920 
2921  d->insideDocumentChange = false;
2922 
2923  if (d->showLayoutProgress) {
2924  const QSizeF newSize = dynamicDocumentSize();
2925  if (newSize != d->lastReportedSize) {
2926  d->lastReportedSize = newSize;
2927  emit documentSizeChanged(newSize);
2928  }
2929  }
2930 
2931  if (!updateRect.isValid()) {
2932  // don't use the frame size, it might have shrunken
2933  updateRect = QRectF(QPointF(0, 0), QSizeF(qreal(INT_MAX), qreal(INT_MAX)));
2934  }
2935 
2936  emit update(updateRect);
2937 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QTextDocument * document() const
Returns the text document that this layout is operating on.
void clearLayout()
Clears the QTextLayout that is used to lay out and display the block&#39;s contents.
void documentSizeChanged(const QSizeF &newSize)
This signal is emitted when the size of the document layout changes to newSize.
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void update(const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
This signal is emitted when the rectangle rect has been updated.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
QSizeF dynamicDocumentSize() const
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76
QRectF doLayout(int from, int oldLength, int length)
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
if(void) toggleToolbarShown
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
#define INT_MAX

◆ documentSize()

QSizeF QTextDocumentLayout::documentSize ( ) const
virtual

Returns the total size of the document's layout.

This information can be used by display widgets to update their scroll bars correctly.

See also
documentSizeChanged(), QTextDocument::pageSize

Implements QAbstractTextDocumentLayout.

Definition at line 3093 of file qtextdocumentlayout.cpp.

3094 {
3095  Q_D(const QTextDocumentLayout);
3096  d->ensureLayoutFinished();
3097  return dynamicDocumentSize();
3098 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QSizeF dynamicDocumentSize() const

◆ doLayout()

QRectF QTextDocumentLayout::doLayout ( int  from,
int  oldLength,
int  length 
)
private

Definition at line 2939 of file qtextdocumentlayout.cpp.

Referenced by documentChanged(), and QTextDocumentLayoutPrivate::ensureLayoutedByPosition().

2940 {
2942 
2943 // qDebug("documentChange: from=%d, oldLength=%d, length=%d", from, oldLength, length);
2944 
2945  // mark all frames between f_start and f_end as dirty
2946  markFrames(d->docPrivate->rootFrame(), from, oldLength, length);
2947 
2948  QRectF updateRect;
2949 
2950  QTextFrame *root = d->docPrivate->rootFrame();
2951  if(data(root)->sizeDirty)
2952  updateRect = d->layoutFrame(root, from, from + length);
2953  data(root)->layoutDirty = false;
2954 
2955  if (d->currentLazyLayoutPosition == -1)
2956  layoutFinished();
2957  else if (d->showLayoutProgress)
2958  d->sizeChangedTimer.start(0, this);
2959 
2960  return updateRect;
2961 }
double d
Definition: qnumeric_p.h:62
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static QTextFrameData * data(QTextFrame *f)
static void markFrames(QTextFrame *current, int from, int oldLength, int length)

◆ draw()

void QTextDocumentLayout::draw ( QPainter painter,
const PaintContext context 
)
virtual

Draws the layout with the given painter using the given context.

Implements QAbstractTextDocumentLayout.

Definition at line 2813 of file qtextdocumentlayout.cpp.

2814 {
2816  QTextFrame *frame = d->document->rootFrame();
2817  QTextFrameData *fd = data(frame);
2818 
2819  if(fd->sizeDirty)
2820  return;
2821 
2822  if (context.clip.isValid()) {
2823  d->ensureLayouted(QFixed::fromReal(context.clip.bottom()));
2824  } else {
2825  d->ensureLayoutFinished();
2826  }
2827 
2828  QFixed width = fd->size.width;
2829  if (d->document->pageSize().width() == 0 && d->viewportRect.isValid()) {
2830  // we're in NoWrap mode, meaning the frame should expand to the viewport
2831  // so that backgrounds are drawn correctly
2832  fd->size.width = qMax(width, QFixed::fromReal(d->viewportRect.right()));
2833  }
2834 
2835  // Make sure we conform to the root frames bounds when drawing.
2836  d->clipRect = QRectF(fd->position.toPointF(), fd->size.toSizeF()).adjusted(fd->leftMargin.toReal(), 0, -fd->rightMargin.toReal(), 0);
2837  d->drawFrame(QPointF(), painter, context, frame);
2838  fd->size.width = width;
2839 }
double d
Definition: qnumeric_p.h:62
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QSizeF toSizeF() const
Definition: qfixed_p.h:209
QPointF toPointF() const
Definition: qfixed_p.h:194
static QTextFrameData * data(QTextFrame *f)
QFixed width
Definition: qfixed_p.h:207
qreal toReal() const
Definition: qfixed_p.h:77

◆ drawInlineObject()

void QTextDocumentLayout::drawInlineObject ( QPainter painter,
const QRectF rect,
QTextInlineObject  object,
int  posInDocument,
const QTextFormat format 
)
protectedvirtual

This function is called to draw the inline object, object, with the given painter within the rectangle specified by rect using the specified text format.

posInDocument specifies the position of the object within the document.

The default implementation calls drawObject() on the object handlers. This function is called only within Qt. Subclasses can reimplement this function to customize the drawing of inline objects.

See also
draw()

Reimplemented from QAbstractTextDocumentLayout.

Definition at line 3057 of file qtextdocumentlayout.cpp.

3059 {
3061  QTextCharFormat f = format.toCharFormat();
3062  Q_ASSERT(f.isValid());
3063  QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f));
3064  if (frame && frame->frameFormat().position() != QTextFrameFormat::InFlow)
3065  return; // don't draw floating frames from inline objects here but in drawFlow instead
3066 
3067 // qDebug() << "drawObject at" << r;
3068  QAbstractTextDocumentLayout::drawInlineObject(p, rect, item, posInDocument, format);
3069 }
double d
Definition: qnumeric_p.h:62
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format)
This function is called to draw the inline object, object, with the given painter within the rectangl...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QTextCharFormat toCharFormat() const
Returns this format as a character format.

◆ dynamicDocumentSize()

QSizeF QTextDocumentLayout::dynamicDocumentSize ( ) const

Definition at line 3080 of file qtextdocumentlayout.cpp.

Referenced by documentChanged(), documentSize(), dynamicPageCount(), QTextEditPrivate::relayoutDocument(), and timerEvent().

3081 {
3082  Q_D(const QTextDocumentLayout);
3083  return data(d->docPrivate->rootFrame())->size.toSizeF();
3084 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QTextFrameData * data(QTextFrame *f)

◆ dynamicPageCount()

int QTextDocumentLayout::dynamicPageCount ( ) const

Definition at line 3071 of file qtextdocumentlayout.cpp.

Referenced by pageCount(), and timerEvent().

3072 {
3073  Q_D(const QTextDocumentLayout);
3074  const QSizeF pgSize = d->document->pageSize();
3075  if (pgSize.height() < 0)
3076  return 1;
3077  return qCeil(dynamicDocumentSize().height() / pgSize.height());
3078 }
double d
Definition: qnumeric_p.h:62
int qCeil(qreal v)
Definition: qmath.h:63
qreal height() const
Returns the height.
Definition: qsize.h:287
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QSizeF dynamicDocumentSize() const

◆ ensureLayouted()

void QTextDocumentLayout::ensureLayouted ( qreal  y)

Definition at line 3252 of file qtextdocumentlayout.cpp.

Referenced by QTextEditPrivate::relayoutDocument().

3253 {
3254  d_func()->ensureLayouted(QFixed::fromReal(y));
3255 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70

◆ frameBoundingRect()

QRectF QTextDocumentLayout::frameBoundingRect ( QTextFrame frame) const
virtual

Returns the bounding rectangle of frame.

Implements QAbstractTextDocumentLayout.

Definition at line 3152 of file qtextdocumentlayout.cpp.

3153 {
3154  Q_D(const QTextDocumentLayout);
3155  if (d->docPrivate->pageSize.isNull())
3156  return QRectF();
3157  d->ensureLayoutFinished();
3158  return d->frameBoundingRectInternal(frame);
3159 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ hitTest()

int QTextDocumentLayout::hitTest ( const QPointF point,
Qt::HitTestAccuracy  accuracy 
) const
virtual

Returns the cursor postion for the given point with the specified accuracy.

Returns -1 if no valid cursor position was found.

Implements QAbstractTextDocumentLayout.

Definition at line 2963 of file qtextdocumentlayout.cpp.

2964 {
2965  Q_D(const QTextDocumentLayout);
2966  d->ensureLayouted(QFixed::fromReal(point.y()));
2967  QTextFrame *f = d->docPrivate->rootFrame();
2968  int position = 0;
2969  QTextLayout *l = 0;
2970  QFixedPoint pointf;
2971  pointf.x = QFixed::fromReal(point.x());
2972  pointf.y = QFixed::fromReal(point.y());
2973  QTextDocumentLayoutPrivate::HitPoint p = d->hitTest(f, pointf, &position, &l, accuracy);
2975  return -1;
2976 
2977  // ensure we stay within document bounds
2978  int lastPos = f->lastPosition();
2979  if (l && !l->preeditAreaText().isEmpty())
2980  lastPos += l->preeditAreaText().length();
2981  if (position > lastPos)
2982  position = lastPos;
2983  else if (position < 0)
2984  position = 0;
2985 
2986  return position;
2987 }
double d
Definition: qnumeric_p.h:62
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QFixed y
Definition: qfixed_p.h:191
int lastPosition() const
Returns the last document position inside the frame.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QFixed x
Definition: qfixed_p.h:190
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QFactoryLoader * l
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ idealWidth()

qreal QTextDocumentLayout::idealWidth ( ) const

Referenced by ensureLayouted().

◆ layoutFinished()

void QTextDocumentLayout::layoutFinished ( )
private

Definition at line 3242 of file qtextdocumentlayout.cpp.

Referenced by doLayout().

3243 {
3245  d->layoutTimer.stop();
3246  if (!d->insideDocumentChange)
3247  d->sizeChangedTimer.start(0, this);
3248  // reset
3249  d->showLayoutProgress = true;
3250 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ layoutStatus()

int QTextDocumentLayout::layoutStatus ( ) const

Definition at line 3210 of file qtextdocumentlayout.cpp.

3211 {
3212  Q_D(const QTextDocumentLayout);
3213  int pos = d->currentLazyLayoutPosition;
3214  if (pos == -1)
3215  return 100;
3216  return pos * 100 / d->document->docHandle()->length();
3217 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ pageCount()

int QTextDocumentLayout::pageCount ( ) const
virtual

Returns the number of pages contained in the layout.

See also
pageCountChanged()

Implements QAbstractTextDocumentLayout.

Definition at line 3086 of file qtextdocumentlayout.cpp.

3087 {
3088  Q_D(const QTextDocumentLayout);
3089  d->ensureLayoutFinished();
3090  return dynamicPageCount();
3091 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ positionInlineObject()

void QTextDocumentLayout::positionInlineObject ( QTextInlineObject  item,
int  posInDocument,
const QTextFormat format 
)
protectedvirtual

Lays out the inline object item using the given text format.

posInDocument specifies the position of the object within the document.

The default implementation does nothing. This function is called only within Qt. Subclasses can reimplement this function to customize the position of inline objects.

See also
drawInlineObject()

Reimplemented from QAbstractTextDocumentLayout.

Definition at line 3030 of file qtextdocumentlayout.cpp.

3031 {
3033  Q_UNUSED(posInDocument);
3034  if (item.width() != 0)
3035  // inline
3036  return;
3037 
3038  QTextCharFormat f = format.toCharFormat();
3039  Q_ASSERT(f.isValid());
3040  QTextObjectHandler handler = d->handlers.value(f.objectType());
3041  if (!handler.component)
3042  return;
3043 
3044  QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f));
3045  if (!frame)
3046  return;
3047 
3048  QTextBlock b = d->document->findBlock(frame->firstPosition());
3049  QTextLine line;
3050  if (b.position() <= frame->firstPosition() && b.position() + b.length() > frame->lastPosition())
3051  line = b.layout()->lineAt(b.layout()->lineCount()-1);
3052 // qDebug() << "layoutObject: line.isValid" << line.isValid() << b.position() << b.length() <<
3053 // frame->firstPosition() << frame->lastPosition();
3054  d->positionFloat(frame, line.isValid() ? &line : 0);
3055 }
double d
Definition: qnumeric_p.h:62
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int firstPosition() const
Returns the first document position inside the frame.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
int position() const
Returns the index of the block&#39;s first character within the document.
int objectType() const
Returns the text format&#39;s object type.
Definition: qtextformat.h:315
int lastPosition() const
Returns the last document position inside the frame.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int length() const
Returns the length of the block in characters.
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextCharFormat toCharFormat() const
Returns this format as a character format.
qreal width() const
Returns the inline object&#39;s width.
QImageIOHandler * handler
#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
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. ...

◆ resizeInlineObject()

void QTextDocumentLayout::resizeInlineObject ( QTextInlineObject  item,
int  posInDocument,
const QTextFormat format 
)
protectedvirtual

Sets the size of the inline object item corresponding to the text format.

posInDocument specifies the position of the object within the document.

The default implementation resizes the item to the size returned by the object handler's intrinsicSize() function. This function is called only within Qt. Subclasses can reimplement this function to customize the resizing of inline objects.

Reimplemented from QAbstractTextDocumentLayout.

Definition at line 2989 of file qtextdocumentlayout.cpp.

2990 {
2992  QTextCharFormat f = format.toCharFormat();
2993  Q_ASSERT(f.isValid());
2994  QTextObjectHandler handler = d->handlers.value(f.objectType());
2995  if (!handler.component)
2996  return;
2997 
2998  QSizeF intrinsic = handler.iface->intrinsicSize(d->document, posInDocument, format);
2999 
3001  QTextFrame *frame = qobject_cast<QTextFrame *>(d->document->objectForFormat(f));
3002  if (frame) {
3003  pos = frame->frameFormat().position();
3004  QTextFrameData *fd = data(frame);
3005  fd->sizeDirty = false;
3006  fd->size = QFixedSize::fromSizeF(intrinsic);
3007  fd->minimumWidth = fd->maximumWidth = fd->size.width;
3008  }
3009 
3010  QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0));
3011  item.setWidth(inlineSize.width());
3012 
3013  QFontMetrics m(f.font());
3014  switch (f.verticalAlignment())
3015  {
3017  item.setDescent(inlineSize.height() / 2);
3018  item.setAscent(inlineSize.height() / 2 - 1);
3019  break;
3021  item.setDescent(m.descent());
3022  item.setAscent(inlineSize.height() - m.descent() - 1);
3023  break;
3024  default:
3025  item.setDescent(0);
3026  item.setAscent(inlineSize.height() - 1);
3027  }
3028 }
double d
Definition: qnumeric_p.h:62
QFont font() const
Returns the font for this character format.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
Position
This enum describes how a frame is located relative to the surrounding text.
Definition: qtextformat.h:734
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setDescent(qreal d)
Sets the inline object&#39;s decent to d.
Position position() const
Returns the positioning policy for frames with this frame format.
Definition: qtextformat.h:758
int objectType() const
Returns the text format&#39;s object type.
Definition: qtextformat.h:315
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
void setWidth(qreal w)
Sets the inline object&#39;s width to w.
static QTextFrameData * data(QTextFrame *f)
void setAscent(qreal a)
Sets the inline object&#39;s ascent to a.
QFixed width
Definition: qfixed_p.h:207
static QFixedSize fromSizeF(const QSizeF &s)
Definition: qfixed_p.h:210
QTextCharFormat toCharFormat() const
Returns this format as a character format.
QImageIOHandler * handler
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131

◆ setCursorWidth()

void QTextDocumentLayout::setCursorWidth ( int  width)

Definition at line 3134 of file qtextdocumentlayout.cpp.

3135 {
3137  d->cursorWidth = width;
3138 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setFixedColumnWidth()

void QTextDocumentLayout::setFixedColumnWidth ( int  width)

Definition at line 3146 of file qtextdocumentlayout.cpp.

3147 {
3149  d->fixedColumnWidth = width;
3150 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setViewport()

void QTextDocumentLayout::setViewport ( const QRectF viewport)

Definition at line 2841 of file qtextdocumentlayout.cpp.

Referenced by QTextEditPrivate::paint(), and QGraphicsTextItem::paint().

2842 {
2844  d->viewportRect = viewport;
2845 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ timerEvent()

void QTextDocumentLayout::timerEvent ( QTimerEvent event)
protectedvirtual

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 3219 of file qtextdocumentlayout.cpp.

3220 {
3222  if (e->timerId() == d->layoutTimer.timerId()) {
3223  if (d->currentLazyLayoutPosition != -1)
3224  d->layoutStep();
3225  } else if (e->timerId() == d->sizeChangedTimer.timerId()) {
3226  d->lastReportedSize = dynamicDocumentSize();
3227  emit documentSizeChanged(d->lastReportedSize);
3228  d->sizeChangedTimer.stop();
3229 
3230  if (d->currentLazyLayoutPosition == -1) {
3231  const int newCount = dynamicPageCount();
3232  if (newCount != d->lastPageCount) {
3233  d->lastPageCount = newCount;
3234  emit pageCountChanged(newCount);
3235  }
3236  }
3237  } else {
3239  }
3240 }
double d
Definition: qnumeric_p.h:62
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
void documentSizeChanged(const QSizeF &newSize)
This signal is emitted when the size of the document layout changes to newSize.
#define Q_D(Class)
Definition: qglobal.h:2482
QSizeF dynamicDocumentSize() const
#define emit
Definition: qobjectdefs.h:76
void pageCountChanged(int newPages)
This signal is emitted when the number of pages in the layout changes; newPages is the updated page c...

Properties

◆ contentHasAlignment

bool QTextDocumentLayout::contentHasAlignment
private

Definition at line 72 of file qtextdocumentlayout_p.h.

◆ cursorWidth

int QTextDocumentLayout::cursorWidth
private

Definition at line 70 of file qtextdocumentlayout_p.h.

◆ idealWidth

qreal QTextDocumentLayout::idealWidth
private

Definition at line 71 of file qtextdocumentlayout_p.h.


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