Export QTextImageHandler and add accessor for image
[profile/ivi/qtbase.git] / src / gui / text / qtextlayout.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 QT_MODULE(Gui)
60
61 class QTextEngine;
62 class QFont;
63 class QRect;
64 class QRegion;
65 class QTextFormat;
66 class QPalette;
67 class QPainter;
68
69 class Q_GUI_EXPORT QTextInlineObject
70 {
71 public:
72     QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
73     inline QTextInlineObject() : itm(0), eng(0) {}
74     inline bool isValid() const { return eng; }
75
76     QRectF rect() const;
77     qreal width() const;
78     qreal ascent() const;
79     qreal descent() const;
80     qreal height() const;
81
82     Qt::LayoutDirection textDirection() const;
83
84     void setWidth(qreal w);
85     void setAscent(qreal a);
86     void setDescent(qreal d);
87
88     int textPosition() const;
89
90     int formatIndex() const;
91     QTextFormat format() const;
92
93 private:
94     friend class QTextLayout;
95     int itm;
96     QTextEngine *eng;
97 };
98
99 class QPaintDevice;
100 class QTextFormat;
101 class QTextLine;
102 class QTextBlock;
103 class QTextOption;
104
105 class Q_GUI_EXPORT QTextLayout
106 {
107 public:
108     // does itemization
109     QTextLayout();
110     QTextLayout(const QString& text);
111     QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = 0);
112     QTextLayout(const QTextBlock &b);
113     ~QTextLayout();
114
115     void setFont(const QFont &f);
116     QFont font() const;
117
118     void setText(const QString& string);
119     QString text() const;
120
121     void setTextOption(const QTextOption &option);
122     QTextOption textOption() const;
123
124     void setPreeditArea(int position, const QString &text);
125     int preeditAreaPosition() const;
126     QString preeditAreaText() const;
127
128     struct FormatRange {
129         int start;
130         int length;
131         QTextCharFormat format;
132     };
133     void setAdditionalFormats(const QList<FormatRange> &overrides);
134     QList<FormatRange> additionalFormats() const;
135     void clearAdditionalFormats();
136
137     void setCacheEnabled(bool enable);
138     bool cacheEnabled() const;
139
140     void setCursorMoveStyle(Qt::CursorMoveStyle style);
141     Qt::CursorMoveStyle cursorMoveStyle() const;
142
143     void beginLayout();
144     void endLayout();
145     void clearLayout();
146
147     QTextLine createLine();
148
149     int lineCount() const;
150     QTextLine lineAt(int i) const;
151     QTextLine lineForTextPosition(int pos) const;
152
153     enum CursorMode {
154         SkipCharacters,
155         SkipWords
156     };
157     bool isValidCursorPosition(int pos) const;
158     int nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
159     int previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
160     int leftCursorPosition(int oldPos) const;
161     int rightCursorPosition(int oldPos) const;
162
163     void draw(QPainter *p, const QPointF &pos, const QVector<FormatRange> &selections = QVector<FormatRange>(),
164               const QRectF &clip = QRectF()) const;
165     void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const;
166     void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition, int width) const;
167
168     QPointF position() const;
169     void setPosition(const QPointF &p);
170
171     QRectF boundingRect() const;
172
173     qreal minimumWidth() const;
174     qreal maximumWidth() const;
175
176 #if !defined(QT_NO_RAWFONT)
177     QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
178 #endif
179
180     QTextEngine *engine() const { return d; }
181     void setFlags(int flags);
182 private:
183     QTextLayout(QTextEngine *e) : d(e) {}
184     Q_DISABLE_COPY(QTextLayout)
185
186     friend class QPainter;
187     friend class QPSPrinter;
188     friend class QGraphicsSimpleTextItemPrivate;
189     friend class QGraphicsSimpleTextItem;
190     friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str,
191                                QRectF *brect, int tabstops, int* tabarray, int tabarraylen,
192                                QPainter *painter);
193     QTextEngine *d;
194 };
195
196
197 class Q_GUI_EXPORT QTextLine
198 {
199 public:
200     inline QTextLine() : i(0), eng(0) {}
201     inline bool isValid() const { return eng; }
202
203     QRectF rect() const;
204     qreal x() const;
205     qreal y() const;
206     qreal width() const;
207     qreal ascent() const;
208     qreal descent() const;
209     qreal height() const;
210     qreal leading() const;
211
212     void setLeadingIncluded(bool included);
213     bool leadingIncluded() const;
214
215     qreal naturalTextWidth() const;
216     qreal horizontalAdvance() const;
217     QRectF naturalTextRect() const;
218
219     enum Edge {
220         Leading,
221         Trailing
222     };
223     enum CursorPosition {
224         CursorBetweenCharacters,
225         CursorOnCharacter
226     };
227
228     /* cursorPos gets set to the valid position */
229     qreal cursorToX(int *cursorPos, Edge edge = Leading) const;
230     inline qreal cursorToX(int cursorPos, Edge edge = Leading) const { return cursorToX(&cursorPos, edge); }
231     int xToCursor(qreal x, CursorPosition = CursorBetweenCharacters) const;
232
233     void setLineWidth(qreal width);
234     void setNumColumns(int columns);
235     void setNumColumns(int columns, qreal alignmentWidth);
236
237     void setPosition(const QPointF &pos);
238     QPointF position() const;
239
240     int textStart() const;
241     int textLength() const;
242
243     int lineNumber() const { return i; }
244
245     void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = 0) const;
246
247 #if !defined(QT_NO_RAWFONT)
248     QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
249 #endif
250
251 private:
252     QTextLine(int line, QTextEngine *e) : i(line), eng(e) {}
253     void layout_helper(int numGlyphs);
254
255     friend class QTextLayout;
256     friend class QTextFragment;
257     int i;
258     QTextEngine *eng;
259 };
260
261 QT_END_NAMESPACE
262
263 QT_END_HEADER
264
265 #endif // QTEXTLAYOUT_H