File indexing completed on 2025-01-18 10:07:56
0001
0002
0003
0004 #ifndef QABSTRACTTEXTDOCUMENTLAYOUT_H
0005 #define QABSTRACTTEXTDOCUMENTLAYOUT_H
0006
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtGui/qtextlayout.h>
0010 #include <QtGui/qtextdocument.h>
0011 #include <QtGui/qtextcursor.h>
0012 #include <QtGui/qpalette.h>
0013
0014 QT_BEGIN_NAMESPACE
0015
0016
0017 class QAbstractTextDocumentLayoutPrivate;
0018 class QTextBlock;
0019 class QTextObjectInterface;
0020 class QTextFrame;
0021
0022 class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
0023 {
0024 Q_OBJECT
0025 Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
0026
0027 public:
0028 explicit QAbstractTextDocumentLayout(QTextDocument *doc);
0029 ~QAbstractTextDocumentLayout();
0030
0031 struct Selection
0032 {
0033 QTextCursor cursor;
0034 QTextCharFormat format;
0035 };
0036
0037 struct PaintContext
0038 {
0039 PaintContext()
0040 : cursorPosition(-1)
0041 {}
0042 int cursorPosition;
0043 QPalette palette;
0044 QRectF clip;
0045 QList<Selection> selections;
0046 };
0047
0048 virtual void draw(QPainter *painter, const PaintContext &context) = 0;
0049 virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const = 0;
0050
0051 QString anchorAt(const QPointF& pos) const;
0052 QString imageAt(const QPointF &pos) const;
0053 QTextFormat formatAt(const QPointF &pos) const;
0054 QTextBlock blockWithMarkerAt(const QPointF &pos) const;
0055
0056 virtual int pageCount() const = 0;
0057 virtual QSizeF documentSize() const = 0;
0058
0059 virtual QRectF frameBoundingRect(QTextFrame *frame) const = 0;
0060 virtual QRectF blockBoundingRect(const QTextBlock &block) const = 0;
0061
0062 void setPaintDevice(QPaintDevice *device);
0063 QPaintDevice *paintDevice() const;
0064
0065 QTextDocument *document() const;
0066
0067 void registerHandler(int objectType, QObject *component);
0068 void unregisterHandler(int objectType, QObject *component = nullptr);
0069 QTextObjectInterface *handlerForObject(int objectType) const;
0070
0071 Q_SIGNALS:
0072 void update(const QRectF & = QRectF(0., 0., 1000000000., 1000000000.));
0073 void updateBlock(const QTextBlock &block);
0074 void documentSizeChanged(const QSizeF &newSize);
0075 void pageCountChanged(int newPages);
0076
0077 protected:
0078 QAbstractTextDocumentLayout(QAbstractTextDocumentLayoutPrivate &, QTextDocument *);
0079
0080 virtual void documentChanged(int from, int charsRemoved, int charsAdded) = 0;
0081
0082 virtual void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
0083 virtual void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
0084 virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format);
0085
0086 int formatIndex(int pos);
0087 QTextCharFormat format(int pos);
0088
0089 private:
0090 friend class QWidgetTextControl;
0091 friend class QTextDocument;
0092 friend class QTextDocumentPrivate;
0093 friend class QTextEngine;
0094 friend class QTextLayout;
0095 friend class QTextLine;
0096 Q_PRIVATE_SLOT(d_func(), int _q_dynamicPageCountSlot())
0097 Q_PRIVATE_SLOT(d_func(), QSizeF _q_dynamicDocumentSizeSlot())
0098 };
0099 Q_DECLARE_TYPEINFO(QAbstractTextDocumentLayout::Selection, Q_RELOCATABLE_TYPE);
0100 Q_DECLARE_TYPEINFO(QAbstractTextDocumentLayout::PaintContext, Q_RELOCATABLE_TYPE);
0101
0102 class Q_GUI_EXPORT QTextObjectInterface
0103 {
0104 public:
0105 virtual ~QTextObjectInterface();
0106 virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
0107 virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
0108 };
0109
0110 #ifndef Q_QDOC
0111 Q_DECLARE_INTERFACE(QTextObjectInterface, "org.qt-project.Qt.QTextObjectInterface")
0112 #endif
0113
0114 QT_END_NAMESPACE
0115
0116 #endif