Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstracttextdocumentlayout.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QABSTRACTTEXTDOCUMENTLAYOUT_H
5#define QABSTRACTTEXTDOCUMENTLAYOUT_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qobject.h>
9#include <QtGui/qtextlayout.h>
10#include <QtGui/qtextdocument.h>
11#include <QtGui/qtextcursor.h>
12#include <QtGui/qpalette.h>
13
15
16
18class QTextBlock;
20class QTextFrame;
21
22class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
23{
25 Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
26
27public:
30
36
38 {
40 : cursorPosition(-1)
41 {}
45 QList<Selection> selections;
46 };
47
48 virtual void draw(QPainter *painter, const PaintContext &context) = 0;
49 virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const = 0;
50
51 QString anchorAt(const QPointF& pos) const;
52 QString imageAt(const QPointF &pos) const;
53 QTextFormat formatAt(const QPointF &pos) const;
54 QTextBlock blockWithMarkerAt(const QPointF &pos) const;
55
56 virtual int pageCount() const = 0;
57 virtual QSizeF documentSize() const = 0;
58
60 virtual QRectF blockBoundingRect(const QTextBlock &block) const = 0;
61
62 void setPaintDevice(QPaintDevice *device);
63 QPaintDevice *paintDevice() const;
64
65 QTextDocument *document() const;
66
67 void registerHandler(int objectType, QObject *component);
68 void unregisterHandler(int objectType, QObject *component = nullptr);
69 QTextObjectInterface *handlerForObject(int objectType) const;
70
72 void update(const QRectF & = QRectF(0., 0., 1000000000., 1000000000.));
73 void updateBlock(const QTextBlock &block);
74 void documentSizeChanged(const QSizeF &newSize);
75 void pageCountChanged(int newPages);
76
77protected:
79
80 virtual void documentChanged(int from, int charsRemoved, int charsAdded) = 0;
81
82 virtual void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
83 virtual void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
84 virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format);
85
86 int formatIndex(int pos);
88
89private:
90 friend class QWidgetTextControl;
91 friend class QTextDocument;
93 friend class QTextEngine;
94 friend class QTextLayout;
95 friend class QTextLine;
96 Q_PRIVATE_SLOT(d_func(), int _q_dynamicPageCountSlot())
97 Q_PRIVATE_SLOT(d_func(), QSizeF _q_dynamicDocumentSizeSlot())
98};
101
102class Q_GUI_EXPORT QTextObjectInterface
103{
104public:
105 virtual ~QTextObjectInterface();
106 virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
107 virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
108};
109
110#ifndef Q_QDOC
111Q_DECLARE_INTERFACE(QTextObjectInterface, "org.qt-project.Qt.QTextObjectInterface")
112#endif
113
115
116#endif // QABSTRACTTEXTDOCUMENTLAYOUT_H
IOBluetoothDevice * device
void pageCountChanged(int newPages)
This signal is emitted when the number of pages in the layout changes; newPages is the updated page c...
virtual QRectF frameBoundingRect(QTextFrame *frame) const =0
Returns the bounding rectangle of frame.
void documentSizeChanged(const QSizeF &newSize)
This signal is emitted when the size of the document layout changes to newSize.
virtual int pageCount() const =0
Returns the number of pages contained in the layout.
virtual QRectF blockBoundingRect(const QTextBlock &block) const =0
Returns the bounding rectangle of block.
void updateBlock(const QTextBlock &block)
virtual void documentChanged(int from, int charsRemoved, int charsAdded)=0
This function is called whenever the contents of the document change.
virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const =0
Returns the cursor position for the given point with the specified accuracy.
void update(const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
This signal is emitted when the rectangle rect has been updated.
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
virtual QSizeF documentSize() const =0
Returns the total size of the document's layout.
\inmodule QtCore
Definition qobject.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\reentrant
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
\reentrant \inmodule QtGui
\reentrant
Definition qtextformat.h:90
\reentrant
Definition qtextobject.h:81
\reentrant
Definition qtextlayout.h:70
\reentrant
The QTextObjectInterface class allows drawing of custom text objects in \l{QTextDocument}s.
virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)=0
Draws this text object using the specified painter.
virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)=0
The intrinsicSize() function returns the size of the text object represented by format in the given d...
rect
[4]
Combined button and popup list for selecting options.
HitTestAccuracy
Definition qnamespace.h:203
static void * context
#define Q_DECLARE_INTERFACE(IFace, IId)
Definition qobject.h:460
GLint GLsizei GLsizei GLenum format
static qreal component(const QPointF &point, unsigned int i)
#define Q_OBJECT
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
QGraphicsItem * item
QPainter painter(this)
[7]
QFrame frame
[0]
\variable QAbstractTextDocumentLayout::PaintContext::cursorPosition