Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qabstracttextdocumentlayout.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QABSTRACTTEXTDOCUMENTLAYOUT_H
43 #define QABSTRACTTEXTDOCUMENTLAYOUT_H
44
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>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55
56 class QAbstractTextDocumentLayoutPrivate;
57 class QTextBlock;
58 class QTextObjectInterface;
59 class QTextFrame;
60
61 class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
62 {
63     Q_OBJECT
64     Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
65
66 public:
67     explicit QAbstractTextDocumentLayout(QTextDocument *doc);
68     ~QAbstractTextDocumentLayout();
69
70     struct Selection
71     {
72         QTextCursor cursor;
73         QTextCharFormat format;
74     };
75
76     struct PaintContext
77     {
78         PaintContext()
79             : cursorPosition(-1)
80             {}
81         int cursorPosition;
82         QPalette palette;
83         QRectF clip;
84         QVector<Selection> selections;
85     };
86
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;
90
91     virtual int pageCount() const = 0;
92     virtual QSizeF documentSize() const = 0;
93
94     virtual QRectF frameBoundingRect(QTextFrame *frame) const = 0;
95     virtual QRectF blockBoundingRect(const QTextBlock &block) const = 0;
96
97     void setPaintDevice(QPaintDevice *device);
98     QPaintDevice *paintDevice() const;
99
100     QTextDocument *document() const;
101
102     void registerHandler(int objectType, QObject *component);
103     QTextObjectInterface *handlerForObject(int objectType) const;
104
105 Q_SIGNALS:
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);
110
111 protected:
112     QAbstractTextDocumentLayout(QAbstractTextDocumentLayoutPrivate &, QTextDocument *);
113
114     virtual void documentChanged(int from, int charsRemoved, int charsAdded) = 0;
115
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);
119
120     int formatIndex(int pos);
121     QTextCharFormat format(int pos);
122
123 private:
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())
133 };
134
135 class Q_GUI_EXPORT QTextObjectInterface
136 {
137 public:
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;
141 };
142
143 Q_DECLARE_INTERFACE(QTextObjectInterface, "org.qt-project.Qt.QTextObjectInterface")
144
145 QT_END_NAMESPACE
146
147 QT_END_HEADER
148
149 #endif // QABSTRACTTEXTDOCUMENTLAYOUT_H