1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
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
55QT_BEGIN_HEADER
56
57QT_BEGIN_NAMESPACE
58
59QT_MODULE(Gui)
60
61class QTextEngine;
62class QFont;
63class QRect;
64class QRegion;
65class QTextFormat;
66class QPalette;
67class QPainter;
68
69class Q_GUI_EXPORT QTextInlineObject
70{
71public:
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
93private:
94 friend class QTextLayout;
95 int itm;
96 QTextEngine *eng;
97};
98
99class QPaintDevice;
100class QTextFormat;
101class QTextLine;
102class QTextBlock;
103class QTextOption;
104
105class Q_GUI_EXPORT QTextLayout
106{
107public:
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() const;
178#endif
179
180 QTextEngine *engine() const { return d; }
181 void setFlags(int flags);
182private:
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
197class Q_GUI_EXPORT QTextLine
198{
199public:
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
247private:
248 QTextLine(int line, QTextEngine *e) : i(line), eng(e) {}
249 void layout_helper(int numGlyphs);
250
251#if !defined(QT_NO_RAWFONT)
252 QList<QGlyphRun> glyphs(int from, int length) const;
253#endif
254
255 friend class QTextLayout;
256 friend class QTextFragment;
257 int i;
258 QTextEngine *eng;
259};
260
261QT_END_NAMESPACE
262
263QT_END_HEADER
264
265#endif // QTEXTLAYOUT_H
266