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
14QT_BEGIN_NAMESPACE
15
16
17class QAbstractTextDocumentLayoutPrivate;
18class QTextBlock;
19class QTextObjectInterface;
20class QTextFrame;
21
22class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
23{
24 Q_OBJECT
25 Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
26
27public:
28 explicit QAbstractTextDocumentLayout(QTextDocument *doc);
29 ~QAbstractTextDocumentLayout();
30
31 struct Selection
32 {
33 QTextCursor cursor;
34 QTextCharFormat format;
35 };
36
37 struct PaintContext
38 {
39 PaintContext()
40 : cursorPosition(-1)
41 {}
42 int cursorPosition;
43 QPalette palette;
44 QRectF clip;
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
59 virtual QRectF frameBoundingRect(QTextFrame *frame) const = 0;
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
71Q_SIGNALS:
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:
78 QAbstractTextDocumentLayout(QAbstractTextDocumentLayoutPrivate &, QTextDocument *);
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);
87 QTextCharFormat format(int pos);
88
89private:
90 friend class QWidgetTextControl;
91 friend class QTextDocument;
92 friend class QTextDocumentPrivate;
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};
99Q_DECLARE_TYPEINFO(QAbstractTextDocumentLayout::Selection, Q_RELOCATABLE_TYPE);
100Q_DECLARE_TYPEINFO(QAbstractTextDocumentLayout::PaintContext, Q_RELOCATABLE_TYPE);
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
114QT_END_NAMESPACE
115
116#endif // QABSTRACTTEXTDOCUMENTLAYOUT_H
117

source code of qtbase/src/gui/text/qabstracttextdocumentlayout.h