Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qtextlayout.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 #ifndef QTEXTLAYOUT_H
42 #define QTEXTLAYOUT_H
43
44 #include <QtCore/qstring.h>
45 #include <QtCore/qnamespace.h>
46 #include <QtCore/qrect.h>
47 #include <QtCore/qvector.h>
48 #include <QtGui/qcolor.h>
49 #include <QtCore/qobject.h>
50 #include <QtGui/qevent.h>
51 #include <QtGui/qtextformat.h>
52 #include <QtGui/qglyphrun.h>
53 #include <QtGui/qtextcursor.h>
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59
60 class QTextEngine;
61 class QFont;
62 #ifndef QT_NO_RAWFONT
63 class QRawFont;
64 #endif
65 class QRect;
66 class QRegion;
67 class QTextFormat;
68 class QPalette;
69 class QPainter;
70
71 class Q_GUI_EXPORT QTextInlineObject
72 {
73 public:
74     QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
75     inline QTextInlineObject() : itm(0), eng(0) {}
76     inline bool isValid() const { return eng; }
77
78     QRectF rect() const;
79     qreal width() const;
80     qreal ascent() const;
81     qreal descent() const;
82     qreal height() const;
83
84     Qt::LayoutDirection textDirection() const;
85
86     void setWidth(qreal w);
87     void setAscent(qreal a);
88     void setDescent(qreal d);
89
90     int textPosition() const;
91
92     int formatIndex() const;
93     QTextFormat format() const;
94
95 private:
96     friend class QTextLayout;
97     int itm;
98     QTextEngine *eng;
99 };
100
101 class QPaintDevice;
102 class QTextFormat;
103 class QTextLine;
104 class QTextBlock;
105 class QTextOption;
106
107 class Q_GUI_EXPORT QTextLayout
108 {
109 public:
110     // does itemization
111     QTextLayout();
112     QTextLayout(const QString& text);
113     QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = 0);
114     QTextLayout(const QTextBlock &b);
115     ~QTextLayout();
116
117     void setFont(const QFont &f);
118     QFont font() const;
119
120 #ifndef QT_NO_RAWFONT
121     void setRawFont(const QRawFont &rawFont);
122 #endif
123
124     void setText(const QString& string);
125     QString text() const;
126
127     void setTextOption(const QTextOption &option);
128     QTextOption textOption() const;
129
130     void setPreeditArea(int position, const QString &text);
131     int preeditAreaPosition() const;
132     QString preeditAreaText() const;
133
134     struct FormatRange {
135         int start;
136         int length;
137         QTextCharFormat format;
138     };
139     void setAdditionalFormats(const QList<FormatRange> &overrides);
140     QList<FormatRange> additionalFormats() const;
141     void clearAdditionalFormats();
142
143     void setCacheEnabled(bool enable);
144     bool cacheEnabled() const;
145
146     void setCursorMoveStyle(Qt::CursorMoveStyle style);
147     Qt::CursorMoveStyle cursorMoveStyle() const;
148
149     void beginLayout();
150     void endLayout();
151     void clearLayout();
152
153     QTextLine createLine();
154
155     int lineCount() const;
156     QTextLine lineAt(int i) const;
157     QTextLine lineForTextPosition(int pos) const;
158
159     enum CursorMode {
160         SkipCharacters,
161         SkipWords
162     };
163     bool isValidCursorPosition(int pos) const;
164     int nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
165     int previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
166     int leftCursorPosition(int oldPos) const;
167     int rightCursorPosition(int oldPos) const;
168
169     void draw(QPainter *p, const QPointF &pos, const QVector<FormatRange> &selections = QVector<FormatRange>(),
170               const QRectF &clip = QRectF()) const;
171     void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const;
172     void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition, int width) const;
173
174     QPointF position() const;
175     void setPosition(const QPointF &p);
176
177     QRectF boundingRect() const;
178
179     qreal minimumWidth() const;
180     qreal maximumWidth() const;
181
182 #if !defined(QT_NO_RAWFONT)
183     QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
184 #endif
185
186     QTextEngine *engine() const { return d; }
187     void setFlags(int flags);
188 private:
189     QTextLayout(QTextEngine *e) : d(e) {}
190     Q_DISABLE_COPY(QTextLayout)
191
192     friend class QPainter;
193     friend class QPSPrinter;
194     friend class QGraphicsSimpleTextItemPrivate;
195     friend class QGraphicsSimpleTextItem;
196     friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str,
197                                QRectF *brect, int tabstops, int* tabarray, int tabarraylen,
198                                QPainter *painter);
199     QTextEngine *d;
200 };
201
202
203 class Q_GUI_EXPORT QTextLine
204 {
205 public:
206     inline QTextLine() : index(0), eng(0) {}
207     inline bool isValid() const { return eng; }
208
209     QRectF rect() const;
210     qreal x() const;
211     qreal y() const;
212     qreal width() const;
213     qreal ascent() const;
214     qreal descent() const;
215     qreal height() const;
216     qreal leading() const;
217
218     void setLeadingIncluded(bool included);
219     bool leadingIncluded() const;
220
221     qreal naturalTextWidth() const;
222     qreal horizontalAdvance() const;
223     QRectF naturalTextRect() const;
224
225     enum Edge {
226         Leading,
227         Trailing
228     };
229     enum CursorPosition {
230         CursorBetweenCharacters,
231         CursorOnCharacter
232     };
233
234     /* cursorPos gets set to the valid position */
235     qreal cursorToX(int *cursorPos, Edge edge = Leading) const;
236     inline qreal cursorToX(int cursorPos, Edge edge = Leading) const { return cursorToX(&cursorPos, edge); }
237     int xToCursor(qreal x, CursorPosition = CursorBetweenCharacters) const;
238
239     void setLineWidth(qreal width);
240     void setNumColumns(int columns);
241     void setNumColumns(int columns, qreal alignmentWidth);
242
243     void setPosition(const QPointF &pos);
244     QPointF position() const;
245
246     int textStart() const;
247     int textLength() const;
248
249     int lineNumber() const { return index; }
250
251     void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = 0) const;
252
253 #if !defined(QT_NO_RAWFONT)
254     QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
255 #endif
256
257 private:
258     QTextLine(int line, QTextEngine *e) : index(line), eng(e) {}
259     void layout_helper(int numGlyphs);
260
261     friend class QTextLayout;
262     friend class QTextFragment;
263     int index;
264     QTextEngine *eng;
265 };
266
267 QT_END_NAMESPACE
268
269 QT_END_HEADER
270
271 #endif // QTEXTLAYOUT_H