#include <qabstracttextdocumentlayout.h>
Inheritance diagram for QAbstractTextDocumentLayout:


The standard layout provided by Qt can handle simple word processing including inline layouts, lists and tables.
Some applications (e.g. a word processor or a DTP application) might need more features than the ones provided by Qt's layout engine, in which case you can subclass QAbstractTextDocumentLayout to provide your own custom layout behavior for your text documents.
Definition at line 42 of file qabstracttextdocumentlayout.h.
Signals | |
| void | update (const QRectF &=QRectF(0., 0., 1000000000., 1000000000.)) |
| void | documentSizeChanged (const QSizeF &newSize) |
| void | pageCountChanged (int newPages) |
Public Member Functions | |
| QAbstractTextDocumentLayout (QTextDocument *doc) | |
| ~QAbstractTextDocumentLayout () | |
| virtual void | draw (QPainter *painter, const PaintContext &context)=0 |
| virtual int | hitTest (const QPointF &point, Qt::HitTestAccuracy accuracy) const =0 |
| QString | anchorAt (const QPointF &pos) const |
| virtual int | pageCount () const=0 |
| virtual QSizeF | documentSize () const=0 |
| virtual QRectF | frameBoundingRect (QTextFrame *frame) const=0 |
| virtual QRectF | blockBoundingRect (const QTextBlock &block) const=0 |
| void | setPaintDevice (QPaintDevice *device) |
| QPaintDevice * | paintDevice () const |
| QTextDocument * | document () const |
| void | registerHandler (int objectType, QObject *component) |
| QTextObjectInterface * | handlerForObject (int objectType) const |
Protected Member Functions | |
| QAbstractTextDocumentLayout (QAbstractTextDocumentLayoutPrivate &, QTextDocument *) | |
| virtual void | documentChanged (int from, int charsRemoved, int charsAdded)=0 |
| virtual void | resizeInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format) |
| virtual void | positionInlineObject (QTextInlineObject item, int posInDocument, const QTextFormat &format) |
| virtual void | drawInlineObject (QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format) |
| int | formatIndex (int pos) |
| QTextCharFormat | format (int pos) |
Private Member Functions | |
| Q_PRIVATE_SLOT (d_func(), void _q_handlerDestroyed(QObject *obj)) Q_PRIVATE_SLOT(d_func() | |
| int | _q_dynamicPageCountSlot ()) Q_PRIVATE_SLOT(d_func() |
Friends | |
| class | QTextDocument |
| class | QTextDocumentPrivate |
| class | QTextEngine |
| class | QTextLayout |
| class | QTextLine |
Classes | |
| class | PaintContext |
| The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters of a painter context. More... | |
| class | Selection |
| the position within the document, where the cursor line should be drawn.the default color that is used for the text, when no color is specified in the text.a hint to the layout avoiding that paragraphs, frames or text that are clearly outside the specified rectangle, are drawnthe collection of selections that will be rendered when passing this painter context to QAbstractTextDocumentLayout's draw() function.The QAbstractTextDocumentLayout::Selection class is a convenience class defining the parameters of a selection. More... | |
| QAbstractTextDocumentLayout::QAbstractTextDocumentLayout | ( | QTextDocument * | document | ) | [explicit] |
the format of the selectionthe selection's cursor
Creates a new text document layout for the given document.
Definition at line 222 of file qabstracttextdocumentlayout.cpp.
00223 : QObject(*new QAbstractTextDocumentLayoutPrivate, document) 00224 { 00225 }
| QAbstractTextDocumentLayout::~QAbstractTextDocumentLayout | ( | ) |
| QAbstractTextDocumentLayout::QAbstractTextDocumentLayout | ( | QAbstractTextDocumentLayoutPrivate & | , | |
| QTextDocument * | ||||
| ) | [protected] |
| void QAbstractTextDocumentLayout::draw | ( | QPainter * | painter, | |
| const PaintContext & | context | |||
| ) | [pure virtual] |
Draws the layout on the given painter with the given context.
Referenced by DocumentShape::DocumentShape(), QTextDocument::drawContents(), ArthurFrame::paintDescription(), QWhatsThat::paintEvent(), and PreviewView::paintPage().
| int QAbstractTextDocumentLayout::hitTest | ( | const QPointF & | point, | |
| Qt::HitTestAccuracy | accuracy | |||
| ) | const [pure virtual] |
Returns the cursor postion for the given point with the accuracy specified. Returns -1 to indicate failure if no valid cursor position was found.
Referenced by anchorAt(), QTextControlPrivate::dragMoveEvent(), QTextControlPrivate::mouseMoveEvent(), QTextControlPrivate::mousePressEvent(), and QTextControlPrivate::setCursorPosition().
Returns the reference of the anchor at the given position, or an empty string if no anchor exists at that point.
Definition at line 410 of file qabstracttextdocumentlayout.cpp.
References QTextCharFormat::anchorHref(), QTextFormatCollection::charFormat(), Qt::ExactHit, QTextDocumentPrivate::find(), QTextDocumentPrivate::formatCollection(), hitTest(), and QObject::parent().
Referenced by QLabelPrivate::createStandardContextMenu(), QWhatsThat::mouseMoveEvent(), QWhatsThat::mousePressEvent(), and QWhatsThat::mouseReleaseEvent().
00411 { 00412 int cursorPos = hitTest(pos, Qt::ExactHit); 00413 if (cursorPos == -1) 00414 return QString(); 00415 00416 QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle(); 00417 QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos); 00418 QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format); 00419 return fmt.anchorHref(); 00420 }
Here is the call graph for this function:

| int QAbstractTextDocumentLayout::pageCount | ( | ) | const [pure virtual] |
Returns the number of pages required by the layout.
Referenced by QTextDocument::pageCount().
| QSizeF QAbstractTextDocumentLayout::documentSize | ( | ) | const [pure virtual] |
Returns the total size of the document. This is useful to display widgets since they can use to information to update their scroll bars correctly
Referenced by QTextDocument::adjustSize(), TransEditor::calculateFieldHeight(), EditorPage::calculateFieldHeight(), DocumentShape::DocumentShape(), QLabelPrivate::layoutRect(), and QTextDocument::size().
| QRectF QAbstractTextDocumentLayout::frameBoundingRect | ( | QTextFrame * | frame | ) | const [pure virtual] |
Returns the bounding rectacle of frame.
Returns the bounding rectangle of frame.
Referenced by QTextControlPrivate::selectionRect().
| QRectF QAbstractTextDocumentLayout::blockBoundingRect | ( | const QTextBlock & | block | ) | const [pure virtual] |
Returns the bounding rectangle of block.
Referenced by QTextControlPrivate::extendWordwiseSelection(), QAccessibleTextEdit::rect(), QTextControlPrivate::rectForPosition(), and QTextControlPrivate::selectionRect().
| void QAbstractTextDocumentLayout::setPaintDevice | ( | QPaintDevice * | device | ) |
Sets the paint device used for rendering the document's layout to the given device.
Definition at line 439 of file qabstracttextdocumentlayout.cpp.
References d.
Referenced by DocumentShape::DocumentShape(), QTextEditPrivate::init(), QTextDocument::print(), and PrintPreview::PrintPreview().
00440 { 00441 Q_D(QAbstractTextDocumentLayout); 00442 d->paintDevice = device; 00443 }
| QPaintDevice * QAbstractTextDocumentLayout::paintDevice | ( | ) | const |
Returns the paint device used to render the document's layout.
Definition at line 450 of file qabstracttextdocumentlayout.cpp.
References d.
Referenced by QTextEngine::font(), QTextEngine::fontEngine(), getPixmapSize(), QTextDocument::print(), and QScriptLine::setDefaultHeight().
00451 { 00452 Q_D(const QAbstractTextDocumentLayout); 00453 return d->paintDevice; 00454 }
| QTextDocument * QAbstractTextDocumentLayout::document | ( | ) | const |
Returns the text document that this layout is operating on.
Definition at line 399 of file qabstracttextdocumentlayout.cpp.
References QObject::parent().
Referenced by QTextDocumentLayout::blockBoundingRect(), QTextDocumentLayout::documentChanged(), QTextDocumentLayout::doLayout(), QTextDocumentLayout::draw(), drawInlineObject(), QTextDocumentLayout::drawInlineObject(), QTextDocumentLayout::dynamicDocumentSize(), QTextDocumentLayout::dynamicPageCount(), QTextDocumentLayout::hitTest(), QTextDocumentLayout::layoutStatus(), QTextDocumentLayout::positionInlineObject(), resizeInlineObject(), and QTextDocumentLayout::resizeInlineObject().
00400 { 00401 return qobject_cast<QTextDocument *>(parent()); 00402 }
Here is the call graph for this function:

| void QAbstractTextDocumentLayout::registerHandler | ( | int | formatType, | |
| QObject * | component | |||
| ) |
Registers the given component as a handler for items of the given formatType.
Definition at line 246 of file qabstracttextdocumentlayout.cpp.
References QObject::connect(), d, QObject::destroyed(), h, SIGNAL, and SLOT.
Referenced by QTextDocumentLayout::QTextDocumentLayout().
00247 { 00248 Q_D(QAbstractTextDocumentLayout); 00249 00250 QTextObjectInterface *iface = qobject_cast<QTextObjectInterface *>(component); 00251 if (!iface) 00252 return; // ### print error message on terminal? 00253 00254 connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(_q_handlerDestroyed(QObject*))); 00255 00256 QTextObjectHandler h; 00257 h.iface = iface; 00258 h.component = component; 00259 d->handlers.insert(formatType, h); 00260 }
Here is the call graph for this function:

| QTextObjectInterface * QAbstractTextDocumentLayout::handlerForObject | ( | int | objectType | ) | const |
Returns a handler for objects of the given objectType.
Definition at line 265 of file qabstracttextdocumentlayout.cpp.
00266 { 00267 Q_D(const QAbstractTextDocumentLayout); 00268 00269 QTextObjectHandler handler = d->handlers.value(objectType); 00270 if (!handler.component) 00271 return 0; 00272 00273 return handler.iface; 00274 }
| void QAbstractTextDocumentLayout::update | ( | const QRectF & | rect = QRectF(0., 0., 1000000000., 1000000000.) |
) | [signal] |
This signal is emitted when the rectangle rect has been updated.
Referenced by QTextDocumentLayout::documentChanged().
| void QAbstractTextDocumentLayout::documentSizeChanged | ( | const QSizeF & | newSize | ) | [signal] |
This signal is emitted when the size of the document changes. The new size is specified by newSize.
This information is useful to widgets that display text documents since it enables them to update their scroll bars correctly.
Referenced by QTextDocumentLayout::documentChanged(), and QTextDocumentLayout::timerEvent().
| void QAbstractTextDocumentLayout::pageCountChanged | ( | int | newPages | ) | [signal] |
This signal is emitted when the number of pages in the layout changes; newPages is the updated page count.
Changes to the page count are due to the changes to the layout or the document content itself.
Referenced by QTextDocumentLayout::timerEvent().
| void QAbstractTextDocumentLayout::documentChanged | ( | int | position, | |
| int | charsRemoved, | |||
| int | charsAdded | |||
| ) | [protected, pure virtual] |
This function is called whenever the contents of the document change. A change occurs when text is inserted, removed, or a combination of the two types of operation. The change is specified by position, charsRemoved, and charsAdded corresponding to the starting character position of the change, the number of character 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 the combination of removal and insertion. For example, if the text "Hello" gets replaced by "Hi", charsRemoved would be 5 and charsAdded would be 2.
Referenced by QTextDocumentPrivate::clear(), QTextDocumentPrivate::endEditBlock(), and QTextDocumentPrivate::setLayout().
| void QAbstractTextDocumentLayout::resizeInlineObject | ( | QTextInlineObject | item, | |
| int | posInDocument, | |||
| const QTextFormat & | format | |||
| ) | [protected, virtual] |
Sets the size of the inline object item in accordance with the text format. posInDocument specifies the position of the object within the document.
Definition at line 281 of file qabstracttextdocumentlayout.cpp.
References d, document(), format(), handler, QTextCharFormat::isValid(), QTextFormat::objectType(), s, QTextInlineObject::setAscent(), QTextInlineObject::setDescent(), QTextInlineObject::setWidth(), and QTextFormat::toCharFormat().
Referenced by QTextEngine::shape().
00282 { 00283 Q_D(QAbstractTextDocumentLayout); 00284 00285 QTextCharFormat f = format.toCharFormat(); 00286 Q_ASSERT(f.isValid()); 00287 QTextObjectHandler handler = d->handlers.value(f.objectType()); 00288 if (!handler.component) 00289 return; 00290 00291 QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format); 00292 item.setWidth(s.width()); 00293 item.setAscent(s.height()); 00294 item.setDescent(0); 00295 }
Here is the call graph for this function:

| void QAbstractTextDocumentLayout::positionInlineObject | ( | QTextInlineObject | item, | |
| int | posInDocument, | |||
| const QTextFormat & | format | |||
| ) | [protected, virtual] |
Lays out the inline object item using the given text format. The base class implementation does nothing. posInDocument specifies the position of the object within the document.
Definition at line 304 of file qabstracttextdocumentlayout.cpp.
References format().
Referenced by QTextLine::layout_helper().
00305 { 00306 Q_UNUSED(item); 00307 Q_UNUSED(posInDocument); 00308 Q_UNUSED(format); 00309 }
Here is the call graph for this function:

| void QAbstractTextDocumentLayout::drawInlineObject | ( | QPainter * | painter, | |
| const QRectF & | rect, | |||
| QTextInlineObject | object, | |||
| int | posInDocument, | |||
| const QTextFormat & | format | |||
| ) | [protected, virtual] |
Called to draw the inline object object on the given painter within the rectangle specified by rect using the text format specified by format. posInDocument specifies the position of the object within the document.
Definition at line 321 of file qabstracttextdocumentlayout.cpp.
References QColor::blue, d, Qt::Dense4Pattern, document(), format(), QColor::green, handler, image, QPixmap::isNull(), QTextCharFormat::isValid(), QTextFormat::objectType(), p, QColor::red, QBrush::setTexture(), and QTextFormat::toCharFormat().
Referenced by QTextLine::draw(), and QTextDocumentLayout::drawInlineObject().
00323 { 00324 Q_UNUSED(item); 00325 Q_D(QAbstractTextDocumentLayout); 00326 00327 QTextCharFormat f = format.toCharFormat(); 00328 Q_ASSERT(f.isValid()); 00329 QTextObjectHandler handler = d->handlers.value(f.objectType()); 00330 if (!handler.component) 00331 return; 00332 00333 handler.iface->drawObject(p, rect, document(), posInDocument, format); 00334 00335 #if 0 00336 if (selType == QTextLayout::Highlight && item.engine()->pal) { 00337 #if defined (Q_WS_WIN) 00338 static QPixmap tile; 00339 if (tile.isNull()) { 00340 QImage image(128, 128, 32); 00341 image.fill((item.engine()->pal->highlight().color().rgb() & 0x00ffffff) | 0x7f000000); 00342 image.setAlphaBuffer(true); 00343 tile = QPixmap(image); 00344 } 00345 p->drawTiledPixmap(rect, tile); 00346 #elif defined (Q_WS_MAC) 00347 QColor hl = item.engine()->pal->highlight().color(); 00348 QBrush brush(QColor(hl.red(), hl.green(), hl.blue(), 127)); 00349 QPixmap texture = item.engine()->pal->highlight().texture(); 00350 if(!texture.isNull()) 00351 brush.setTexture(texture); 00352 p->fillRect(rect, brush); 00353 #else 00354 QBrush brush(item.engine()->pal->highlight().color(), Qt::Dense4Pattern); 00355 p->fillRect(rect, brush); 00356 #endif 00357 } 00358 #endif 00359 }
Here is the call graph for this function:

| int QAbstractTextDocumentLayout::formatIndex | ( | int | pos | ) | [protected] |
Definition at line 376 of file qabstracttextdocumentlayout.cpp.
References QTextDocumentPrivate::find(), and QObject::parent().
00377 { 00378 QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle(); 00379 return pieceTable->find(pos).value()->format; 00380 }
Here is the call graph for this function:

| QTextCharFormat QAbstractTextDocumentLayout::format | ( | int | position | ) | [protected] |
Returns the character format that is applicable at the given position.
Definition at line 387 of file qabstracttextdocumentlayout.cpp.
References QTextFormatCollection::charFormat(), QTextDocumentPrivate::find(), QTextDocumentPrivate::formatCollection(), and QObject::parent().
Referenced by drawInlineObject(), QTextDocumentLayout::drawInlineObject(), positionInlineObject(), QTextDocumentLayout::positionInlineObject(), resizeInlineObject(), and QTextDocumentLayout::resizeInlineObject().
00388 { 00389 QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle(); 00390 int idx = pieceTable->find(pos).value()->format; 00391 return pieceTable->formatCollection()->charFormat(idx); 00392 }
Here is the call graph for this function:

| QAbstractTextDocumentLayout::Q_PRIVATE_SLOT | ( | d_func() | , | |
| void | _q_handlerDestroyed(QObject *obj) | |||
| ) | [private] |
| int QAbstractTextDocumentLayout::_q_dynamicPageCountSlot | ( | ) | [private] |
friend class QTextDocument [friend] |
Definition at line 104 of file qabstracttextdocumentlayout.h.
friend class QTextDocumentPrivate [friend] |
Definition at line 105 of file qabstracttextdocumentlayout.h.
friend class QTextEngine [friend] |
Definition at line 106 of file qabstracttextdocumentlayout.h.
friend class QTextLayout [friend] |
Definition at line 107 of file qabstracttextdocumentlayout.h.
friend class QTextLine [friend] |
Definition at line 108 of file qabstracttextdocumentlayout.h.
1.5.1