1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QABSTRACTTEXTDOCUMENTLAYOUT_H
43 #define QABSTRACTTEXTDOCUMENTLAYOUT_H
45 #include <QtCore/qobject.h>
46 #include <QtGui/qtextlayout.h>
47 #include <QtGui/qtextdocument.h>
48 #include <QtGui/qtextcursor.h>
49 #include <QtGui/qpalette.h>
56 class QAbstractTextDocumentLayoutPrivate;
58 class QTextObjectInterface;
61 class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
64 Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
67 explicit QAbstractTextDocumentLayout(QTextDocument *doc);
68 ~QAbstractTextDocumentLayout();
73 QTextCharFormat format;
84 QVector<Selection> selections;
87 virtual void draw(QPainter *painter, const PaintContext &context) = 0;
88 virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const = 0;
89 QString anchorAt(const QPointF& pos) const;
91 virtual int pageCount() const = 0;
92 virtual QSizeF documentSize() const = 0;
94 virtual QRectF frameBoundingRect(QTextFrame *frame) const = 0;
95 virtual QRectF blockBoundingRect(const QTextBlock &block) const = 0;
97 void setPaintDevice(QPaintDevice *device);
98 QPaintDevice *paintDevice() const;
100 QTextDocument *document() const;
102 void registerHandler(int objectType, QObject *component);
103 QTextObjectInterface *handlerForObject(int objectType) const;
106 void update(const QRectF & = QRectF(0., 0., 1000000000., 1000000000.));
107 void updateBlock(const QTextBlock &block);
108 void documentSizeChanged(const QSizeF &newSize);
109 void pageCountChanged(int newPages);
112 QAbstractTextDocumentLayout(QAbstractTextDocumentLayoutPrivate &, QTextDocument *);
114 virtual void documentChanged(int from, int charsRemoved, int charsAdded) = 0;
116 virtual void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
117 virtual void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format);
118 virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format);
120 int formatIndex(int pos);
121 QTextCharFormat format(int pos);
124 friend class QWidgetTextControl;
125 friend class QTextDocument;
126 friend class QTextDocumentPrivate;
127 friend class QTextEngine;
128 friend class QTextLayout;
129 friend class QTextLine;
130 Q_PRIVATE_SLOT(d_func(), void _q_handlerDestroyed(QObject *obj))
131 Q_PRIVATE_SLOT(d_func(), int _q_dynamicPageCountSlot())
132 Q_PRIVATE_SLOT(d_func(), QSizeF _q_dynamicDocumentSizeSlot())
135 class Q_GUI_EXPORT QTextObjectInterface
138 virtual ~QTextObjectInterface() {}
139 virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
140 virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0;
143 Q_DECLARE_INTERFACE(QTextObjectInterface, "org.qt-project.Qt.QTextObjectInterface")
149 #endif // QABSTRACTTEXTDOCUMENTLAYOUT_H