QFontMetrics: make conversion from QFont to QFontMetrics explicit
[profile/ivi/qtbase.git] / src / gui / text / qtextdocument.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 QTEXTDOCUMENT_H
43 #define QTEXTDOCUMENT_H
44
45 #include <QtCore/qobject.h>
46 #include <QtCore/qsize.h>
47 #include <QtCore/qrect.h>
48 #include <QtGui/qfont.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54
55 class QTextFormatCollection;
56 class QTextListFormat;
57 class QRect;
58 class QPainter;
59 class QPagedPaintDevice;
60 class QAbstractTextDocumentLayout;
61 class QPoint;
62 class QTextObject;
63 class QTextFormat;
64 class QTextFrame;
65 class QTextBlock;
66 class QTextCodec;
67 class QUrl;
68 class QVariant;
69 class QRectF;
70 class QTextOption;
71 class QTextCursor;
72
73 template<typename T> class QVector;
74
75 namespace Qt
76 {
77     enum HitTestAccuracy { ExactHit, FuzzyHit };
78     enum WhiteSpaceMode {
79         WhiteSpaceNormal,
80         WhiteSpacePre,
81         WhiteSpaceNoWrap,
82         WhiteSpaceModeUndefined = -1
83     };
84
85     Q_GUI_EXPORT bool mightBeRichText(const QString&);
86     Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
87
88 #ifndef QT_NO_TEXTCODEC
89     Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba);
90 #endif
91 }
92
93 class Q_GUI_EXPORT QAbstractUndoItem
94 {
95 public:
96     virtual ~QAbstractUndoItem() = 0;
97     virtual void undo() = 0;
98     virtual void redo() = 0;
99 };
100
101 inline QAbstractUndoItem::~QAbstractUndoItem()
102 {
103 }
104
105 class QTextDocumentPrivate;
106
107 class Q_GUI_EXPORT QTextDocument : public QObject
108 {
109     Q_OBJECT
110
111     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
112     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
113     Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
114     Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
115     Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
116     Q_PROPERTY(QSizeF size READ size)
117     Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
118     Q_PROPERTY(int blockCount READ blockCount)
119     Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
120 #ifndef QT_NO_CSSPARSER
121     Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
122 #endif
123     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
124     Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
125     QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
126
127 public:
128     explicit QTextDocument(QObject *parent = 0);
129     explicit QTextDocument(const QString &text, QObject *parent = 0);
130     ~QTextDocument();
131
132     QTextDocument *clone(QObject *parent = 0) const;
133
134     bool isEmpty() const;
135     virtual void clear();
136
137     void setUndoRedoEnabled(bool enable);
138     bool isUndoRedoEnabled() const;
139
140     bool isUndoAvailable() const;
141     bool isRedoAvailable() const;
142
143     int availableUndoSteps() const;
144     int availableRedoSteps() const;
145
146     int revision() const;
147
148     void setDocumentLayout(QAbstractTextDocumentLayout *layout);
149     QAbstractTextDocumentLayout *documentLayout() const;
150
151     enum MetaInformation {
152         DocumentTitle,
153         DocumentUrl
154     };
155     void setMetaInformation(MetaInformation info, const QString &);
156     QString metaInformation(MetaInformation info) const;
157
158 #ifndef QT_NO_TEXTHTMLPARSER
159     QString toHtml(const QByteArray &encoding = QByteArray()) const;
160     void setHtml(const QString &html);
161 #endif
162
163     QString toPlainText() const;
164     void setPlainText(const QString &text);
165
166     QChar characterAt(int pos) const;
167
168     enum FindFlag
169     {
170         FindBackward        = 0x00001,
171         FindCaseSensitively = 0x00002,
172         FindWholeWords      = 0x00004
173     };
174     Q_DECLARE_FLAGS(FindFlags, FindFlag)
175
176     QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
177     QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
178
179     QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
180     QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
181
182     QTextFrame *frameAt(int pos) const;
183     QTextFrame *rootFrame() const;
184
185     QTextObject *object(int objectIndex) const;
186     QTextObject *objectForFormat(const QTextFormat &) const;
187
188     QTextBlock findBlock(int pos) const;
189     QTextBlock findBlockByNumber(int blockNumber) const;
190     QTextBlock findBlockByLineNumber(int blockNumber) const;
191     QTextBlock begin() const;
192     QTextBlock end() const;
193
194     QTextBlock firstBlock() const;
195     QTextBlock lastBlock() const;
196
197     void setPageSize(const QSizeF &size);
198     QSizeF pageSize() const;
199
200     void setDefaultFont(const QFont &font);
201     QFont defaultFont() const;
202
203     int pageCount() const;
204
205     bool isModified() const;
206
207     void print(QPagedPaintDevice *printer) const;
208
209     enum ResourceType {
210         HtmlResource  = 1,
211         ImageResource = 2,
212         StyleSheetResource = 3,
213
214         UserResource  = 100
215     };
216
217     QVariant resource(int type, const QUrl &name) const;
218     void addResource(int type, const QUrl &name, const QVariant &resource);
219
220     QVector<QTextFormat> allFormats() const;
221
222     void markContentsDirty(int from, int length);
223
224     void setUseDesignMetrics(bool b);
225     bool useDesignMetrics() const;
226
227     void drawContents(QPainter *painter, const QRectF &rect = QRectF());
228
229     void setTextWidth(qreal width);
230     qreal textWidth() const;
231
232     qreal idealWidth() const;
233
234     qreal indentWidth() const;
235     void setIndentWidth(qreal width);
236
237     qreal documentMargin() const;
238     void setDocumentMargin(qreal margin);
239
240     void adjustSize();
241     QSizeF size() const;
242
243     int blockCount() const;
244     int lineCount() const;
245     int characterCount() const;
246
247 #ifndef QT_NO_CSSPARSER
248     void setDefaultStyleSheet(const QString &sheet);
249     QString defaultStyleSheet() const;
250 #endif
251
252     void undo(QTextCursor *cursor);
253     void redo(QTextCursor *cursor);
254
255     enum Stacks {
256         UndoStack = 0x01,
257         RedoStack = 0x02,
258         UndoAndRedoStacks = UndoStack | RedoStack
259     };
260     void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
261
262     int maximumBlockCount() const;
263     void setMaximumBlockCount(int maximum);
264
265     QTextOption defaultTextOption() const;
266     void setDefaultTextOption(const QTextOption &option);
267
268     Qt::CursorMoveStyle defaultCursorMoveStyle() const;
269     void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
270
271 Q_SIGNALS:
272     void contentsChange(int from, int charsRemoves, int charsAdded);
273     void contentsChanged();
274     void undoAvailable(bool);
275     void redoAvailable(bool);
276     void undoCommandAdded();
277     void modificationChanged(bool m);
278     void cursorPositionChanged(const QTextCursor &cursor);
279     void blockCountChanged(int newBlockCount);
280
281     void documentLayoutChanged();
282
283 public Q_SLOTS:
284     void undo();
285     void redo();
286     void appendUndoItem(QAbstractUndoItem *);
287     void setModified(bool m = true);
288
289 protected:
290     virtual QTextObject *createObject(const QTextFormat &f);
291     virtual QVariant loadResource(int type, const QUrl &name);
292
293     QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
294 public:
295     QTextDocumentPrivate *docHandle() const;
296 private:
297     Q_DISABLE_COPY(QTextDocument)
298     Q_DECLARE_PRIVATE(QTextDocument)
299     friend class QTextObjectPrivate;
300 };
301
302 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
303
304 QT_END_NAMESPACE
305
306 QT_END_HEADER
307
308 #endif // QTEXTDOCUMENT_H