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

The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument. More...

#include <qplaintextedit.h>

Inheritance diagram for QPlainTextDocumentLayout:
QAbstractTextDocumentLayout QObject

Public Functions

QRectF blockBoundingRect (const QTextBlock &block) const
 Reimplemented Function More...
 
int cursorWidth () const
 
QSizeF documentSize () const
 Reimplemented Function More...
 
void draw (QPainter *, const PaintContext &)
 Reimplemented Function More...
 
void ensureBlockLayout (const QTextBlock &block) const
 Ensures that block has a valid layout. More...
 
QRectF frameBoundingRect (QTextFrame *) const
 Reimplemented Function More...
 
int hitTest (const QPointF &, Qt::HitTestAccuracy) const
 Reimplemented Function More...
 
int pageCount () const
 Reimplemented Function More...
 
 QPlainTextDocumentLayout (QTextDocument *document)
 Constructs a plain text document layout for the text document. More...
 
void requestUpdate ()
 Requests a complete update on all views. More...
 
void setCursorWidth (int width)
 
 ~QPlainTextDocumentLayout ()
 Destructs a plain text document layout. More...
 
- 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, int charsAdded)
 Reimplemented Function More...
 
- Protected Functions inherited from QAbstractTextDocumentLayout
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 rectangle specified by rect using the specified text format. More...
 
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...
 
virtual void positionInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format)
 Lays out the inline object item using the given text format. More...
 
 QAbstractTextDocumentLayout (QAbstractTextDocumentLayoutPrivate &, QTextDocument *)
 
virtual void resizeInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format)
 Sets the size of the inline object item corresponding to the text format. More...
 
- 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
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

qreal blockWidth (const QTextBlock &block)
 
void layoutBlock (const QTextBlock &block)
 
QPlainTextDocumentLayoutPrivatepriv () const
 
void setTextWidth (qreal newWidth)
 
qreal textWidth () const
 

Properties

int cursorWidth
 This property specifies the width of the cursor in pixels. More...
 

Friends

class QPlainTextEdit
 
class QPlainTextEditPrivate
 

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

The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.

Since
4.4

A QPlainTextDocumentLayout is required for text documents that can be display or edited in a QPlainTextEdit. See QTextDocument::setDocumentLayout().

QPlainTextDocumentLayout uses the QAbstractTextDocumentLayout API that QTextDocument requires, but redefines it partially in order to support plain text better. For instances, it does not operate on vertical pixels, but on paragraphs (called blocks) instead. The height of a document is identical to the number of paragraphs it contains. The layout also doesn't support tables or nested frames, or any sort of advanced text layout that goes beyond a list of paragraphs with syntax highlighting.

Definition at line 280 of file qplaintextedit.h.

Constructors and Destructors

◆ QPlainTextDocumentLayout()

QPlainTextDocumentLayout::QPlainTextDocumentLayout ( QTextDocument document)

Constructs a plain text document layout for the text document.

Definition at line 142 of file qplaintextedit.cpp.

144 }
QAbstractTextDocumentLayout(QTextDocument *doc)
Creates a new text document layout for the given document.

◆ ~QPlainTextDocumentLayout()

QPlainTextDocumentLayout::~QPlainTextDocumentLayout ( )

Destructs a plain text document layout.

Definition at line 148 of file qplaintextedit.cpp.

148 {}

Functions

◆ blockBoundingRect()

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

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 198 of file qplaintextedit.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QPlainTextEditControl::blockBoundingRect(), QPlainTextEdit::blockBoundingRect(), documentChanged(), QPlainTextEditControl::hitTest(), and QPlainTextEditPrivate::verticalOffset().

199 {
200  if (!block.isValid()) { return QRectF(); }
201  QTextLayout *tl = block.layout();
202  if (!tl->lineCount())
203  const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
204  QRectF br;
205  if (block.isVisible()) {
206  br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight());
207  if (tl->lineCount() == 1)
208  br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
209  qreal margin = document()->documentMargin();
210  br.adjust(0, 0, margin, 0);
211  if (!block.next().isValid())
212  br.adjust(0, 0, 0, margin);
213  }
214  return br;
215 
216 }
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
double qreal
Definition: qglobal.h:1193
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.
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
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...
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
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
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
void adjust(qreal x1, qreal y1, qreal x2, qreal y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:778
qreal documentMargin
The margin around the document.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
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. ...

◆ blockWidth()

qreal QPlainTextDocumentLayout::blockWidth ( const QTextBlock block)
private

Definition at line 429 of file qplaintextedit.cpp.

Referenced by documentChanged(), and layoutBlock().

430 {
431  QTextLayout *layout = block.layout();
432  if (!layout->lineCount())
433  return 0; // only for layouted blocks
434  qreal blockWidth = 0;
435  for (int i = 0; i < layout->lineCount(); ++i) {
436  QTextLine line = layout->lineAt(i);
437  blockWidth = qMax(line.naturalTextWidth() + 8, blockWidth);
438  }
439  return blockWidth;
440 }
double qreal
Definition: qglobal.h:1193
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const char * layout
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
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
int lineCount() const
Returns the number of lines in this text layout.
qreal blockWidth(const QTextBlock &block)
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ cursorWidth()

int QPlainTextDocumentLayout::cursorWidth ( ) const

Referenced by setCursorWidth().

◆ documentChanged()

void QPlainTextDocumentLayout::documentChanged ( int  from,
int  ,
int  charsAdded 
)
protectedvirtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 295 of file qplaintextedit.cpp.

296 {
298  QTextDocument *doc = document();
299  int newBlockCount = doc->blockCount();
300 
301  QTextBlock changeStartBlock = doc->findBlock(from);
302  QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsAdded - 1));
303 
304  if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
305  QTextBlock block = changeStartBlock;
306  int blockLineCount = block.layout()->lineCount();
307  if (block.isValid() && blockLineCount) {
308  QRectF oldBr = blockBoundingRect(block);
309  layoutBlock(block);
310  QRectF newBr = blockBoundingRect(block);
311  if (newBr.height() == oldBr.height()) {
312  if (!d->blockUpdate)
313  emit updateBlock(block);
314  return;
315  }
316  }
317  } else {
318  QTextBlock block = changeStartBlock;
319  do {
320  block.clearLayout();
321  if (block == changeEndBlock)
322  break;
323  block = block.next();
324  } while(block.isValid());
325  }
326 
327  if (newBlockCount != d->blockCount) {
328 
329  int changeEnd = changeEndBlock.blockNumber();
330  int blockDiff = newBlockCount - d->blockCount;
331  int oldChangeEnd = changeEnd - blockDiff;
332 
333  if (d->maximumWidthBlockNumber > oldChangeEnd)
334  d->maximumWidthBlockNumber += blockDiff;
335 
336  d->blockCount = newBlockCount;
337  if (d->blockCount == 1)
338  d->maximumWidth = blockWidth(doc->firstBlock());
339 
340  if (!d->blockDocumentSizeChanged)
342 
343  if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
344  if (!d->blockUpdate) {
345  QTextBlock b = changeStartBlock;
346  for(;;) {
347  emit updateBlock(b);
348  if (b == changeEndBlock)
349  break;
350  b = b.next();
351  }
352  }
353  return;
354  }
355  }
356 
357  if (!d->blockUpdate)
358  emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential
359 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
int blockCount
Returns the number of text blocks in the document.
void layoutBlock(const QTextBlock &block)
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
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 documentSize() const
Reimplemented Function
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void updateBlock(const QTextBlock &block)
This signal is emitted when the specified block has been updated.
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
#define emit
Definition: qobjectdefs.h:76
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.
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
QRectF blockBoundingRect(const QTextBlock &block) const
Reimplemented Function
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.
int lineCount() const
Returns the number of lines in this text layout.
qreal blockWidth(const QTextBlock &block)
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...
QTextBlock firstBlock() const
Returns the document&#39;s first text block.

◆ documentSize()

QSizeF QPlainTextDocumentLayout::documentSize ( ) const
virtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 180 of file qplaintextedit.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), documentChanged(), and layoutBlock().

181 {
183  return QSizeF(d->maximumWidth, document()->lineCount());
184 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
QTextDocument * document() const
Returns the text document that this layout is operating on.
#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

◆ draw()

void QPlainTextDocumentLayout::draw ( QPainter ,
const PaintContext  
)
virtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 154 of file qplaintextedit.cpp.

155 {
156 }

◆ ensureBlockLayout()

void QPlainTextDocumentLayout::ensureBlockLayout ( const QTextBlock block) const

Ensures that block has a valid layout.

Definition at line 221 of file qplaintextedit.cpp.

222 {
223  if (!block.isValid())
224  return;
225  QTextLayout *tl = block.layout();
226  if (!tl->lineCount())
227  const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
228 }
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
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. ...

◆ frameBoundingRect()

QRectF QPlainTextDocumentLayout::frameBoundingRect ( QTextFrame ) const
virtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 189 of file qplaintextedit.cpp.

190 {
192  return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(INT_MAX));
193 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
#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
#define INT_MAX

◆ hitTest()

int QPlainTextDocumentLayout::hitTest ( const QPointF ,
Qt::HitTestAccuracy   
) const
virtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 161 of file qplaintextedit.cpp.

162 {
163 // this function is used from
164 // QAbstractTextDocumentLayout::anchorAt(), but is not
165 // implementable in a plain text document layout, because the
166 // layout depends on the top block and top line which depends on
167 // the view
168  return -1;
169 }

◆ layoutBlock()

void QPlainTextDocumentLayout::layoutBlock ( const QTextBlock block)
private

Definition at line 362 of file qplaintextedit.cpp.

Referenced by documentChanged().

363 {
365  QTextDocument *doc = document();
366  qreal margin = doc->documentMargin();
367  qreal blockMaximumWidth = 0;
368 
369  qreal height = 0;
370  QTextLayout *tl = block.layout();
371  QTextOption option = doc->defaultTextOption();
372  tl->setTextOption(option);
373 
374  int extraMargin = 0;
376  QFontMetrics fm(block.charFormat().font());
377  extraMargin += fm.width(QChar(0x21B5));
378  }
379  tl->beginLayout();
380  qreal availableWidth = d->width;
381  if (availableWidth <= 0) {
382  availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0
383  }
384  availableWidth -= 2*margin + extraMargin;
385  while (1) {
386  QTextLine line = tl->createLine();
387  if (!line.isValid())
388  break;
389  line.setLeadingIncluded(true);
390  line.setLineWidth(availableWidth);
391  line.setPosition(QPointF(margin, height));
392  height += line.height();
393  blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin);
394  }
395  tl->endLayout();
396 
397  int previousLineCount = doc->lineCount();
398  const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0);
399  int lineCount = doc->lineCount();
400 
401  bool emitDocumentSizeChanged = previousLineCount != lineCount;
402  if (blockMaximumWidth > d->maximumWidth) {
403  // new longest line
404  d->maximumWidth = blockMaximumWidth;
405  d->maximumWidthBlockNumber = block.blockNumber();
406  emitDocumentSizeChanged = true;
407  } else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
408  // longest line shrinking
409  QTextBlock b = doc->firstBlock();
410  d->maximumWidth = 0;
411  QTextBlock maximumBlock;
412  while (b.isValid()) {
413  qreal blockMaximumWidth = blockWidth(b);
414  if (blockMaximumWidth > d->maximumWidth) {
415  d->maximumWidth = blockMaximumWidth;
416  maximumBlock = b;
417  }
418  b = b.next();
419  }
420  if (maximumBlock.isValid()) {
421  d->maximumWidthBlockNumber = maximumBlock.blockNumber();
422  emitDocumentSizeChanged = true;
423  }
424  }
425  if (emitDocumentSizeChanged && !d->blockDocumentSizeChanged)
427 }
double d
Definition: qnumeric_p.h:62
QFont font() const
Returns the font for this character format.
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
double qreal
Definition: qglobal.h:1193
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
int lineCount() const
Returns the number of lines of this document (if the layout supports this).
void setPosition(const QPointF &pos)
Moves the line to position pos.
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
QTextDocument * document() const
Returns the text document that this layout is operating on.
void setLineWidth(qreal width)
Lays out the line with the given width.
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
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
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 documentSize() const
Reimplemented Function
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
#define emit
Definition: qobjectdefs.h:76
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block&#39;s character format.
void setLeadingIncluded(bool included)
Includes positive leading into the line&#39;s height if included is true; otherwise does not include lead...
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
void endLayout()
Ends the layout process.
QTextOption defaultTextOption() const
the default text option will be set on all QTextLayout in the document.
#define INT_MAX
qreal height() const
Returns the line&#39;s height.
void beginLayout()
Begins the layout process.
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.
int lineCount() const
Returns the number of lines in this text layout.
qreal blockWidth(const QTextBlock &block)
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...
QTextBlock firstBlock() const
Returns the document&#39;s first text block.

◆ pageCount()

int QPlainTextDocumentLayout::pageCount ( ) const
virtual

Reimplemented Function

Implements QAbstractTextDocumentLayout.

Definition at line 174 of file qplaintextedit.cpp.

175 { return 1; }

◆ priv()

QPlainTextDocumentLayoutPrivate * QPlainTextDocumentLayout::priv ( ) const
private

Definition at line 250 of file qplaintextedit.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QPlainTextEditPrivate::append(), QPlainTextEditPrivate::relayoutDocument(), and QPlainTextEdit::setDocument().

251 {
253  return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
254 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ requestUpdate()

void QPlainTextDocumentLayout::requestUpdate ( )

Requests a complete update on all views.

Definition at line 261 of file qplaintextedit.cpp.

262 {
263  emit update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.));
264 }
QTextDocument * document() const
Returns the text document that this layout is operating on.
void update(const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
This signal is emitted when the rectangle rect has been updated.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76

◆ setCursorWidth()

void QPlainTextDocumentLayout::setCursorWidth ( int  width)

Definition at line 238 of file qplaintextedit.cpp.

239 {
241  d->cursorWidth = width;
242 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setTextWidth()

void QPlainTextDocumentLayout::setTextWidth ( qreal  newWidth)
private

Definition at line 267 of file qplaintextedit.cpp.

Referenced by QPlainTextEditPrivate::relayoutDocument().

268 {
270  d->width = d->maximumWidth = newWidth;
271  d->relayout();
272 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ textWidth()

qreal QPlainTextDocumentLayout::textWidth ( ) const
private

Definition at line 274 of file qplaintextedit.cpp.

Referenced by QPlainTextEditPrivate::relayoutDocument().

275 {
277  return d->width;
278 }
double d
Definition: qnumeric_p.h:62
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
#define Q_D(Class)
Definition: qglobal.h:2482

Friends and Related Functions

◆ QPlainTextEdit

friend class QPlainTextEdit
friend

Definition at line 318 of file qplaintextedit.h.

◆ QPlainTextEditPrivate

Definition at line 319 of file qplaintextedit.h.

Properties

◆ cursorWidth

int QPlainTextDocumentLayout::cursorWidth
private

This property specifies the width of the cursor in pixels.

The default value is 1.

Definition at line 284 of file qplaintextedit.h.


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