1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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>
71 class Q_GUI_EXPORT QTextInlineObject
74 QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
75 inline QTextInlineObject() : itm(0), eng(0) {}
76 inline bool isValid() const { return eng; }
81 qreal descent() const;
84 Qt::LayoutDirection textDirection() const;
86 void setWidth(qreal w);
87 void setAscent(qreal a);
88 void setDescent(qreal d);
90 int textPosition() const;
92 int formatIndex() const;
93 QTextFormat format() const;
96 friend class QTextLayout;
107 class Q_GUI_EXPORT QTextLayout
112 QTextLayout(const QString& text);
113 QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = 0);
114 QTextLayout(const QTextBlock &b);
117 void setFont(const QFont &f);
120 #ifndef QT_NO_RAWFONT
121 void setRawFont(const QRawFont &rawFont);
124 void setText(const QString& string);
125 QString text() const;
127 void setTextOption(const QTextOption &option);
128 QTextOption textOption() const;
130 void setPreeditArea(int position, const QString &text);
131 int preeditAreaPosition() const;
132 QString preeditAreaText() const;
137 QTextCharFormat format;
139 void setAdditionalFormats(const QList<FormatRange> &overrides);
140 QList<FormatRange> additionalFormats() const;
141 void clearAdditionalFormats();
143 void setCacheEnabled(bool enable);
144 bool cacheEnabled() const;
146 void setCursorMoveStyle(Qt::CursorMoveStyle style);
147 Qt::CursorMoveStyle cursorMoveStyle() const;
153 QTextLine createLine();
155 int lineCount() const;
156 QTextLine lineAt(int i) const;
157 QTextLine lineForTextPosition(int pos) const;
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;
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;
174 QPointF position() const;
175 void setPosition(const QPointF &p);
177 QRectF boundingRect() const;
179 qreal minimumWidth() const;
180 qreal maximumWidth() const;
182 #if !defined(QT_NO_RAWFONT)
183 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
186 QTextEngine *engine() const { return d; }
187 void setFlags(int flags);
189 QTextLayout(QTextEngine *e) : d(e) {}
190 Q_DISABLE_COPY(QTextLayout)
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,
203 class Q_GUI_EXPORT QTextLine
206 inline QTextLine() : index(0), eng(0) {}
207 inline bool isValid() const { return eng; }
213 qreal ascent() const;
214 qreal descent() const;
215 qreal height() const;
216 qreal leading() const;
218 void setLeadingIncluded(bool included);
219 bool leadingIncluded() const;
221 qreal naturalTextWidth() const;
222 qreal horizontalAdvance() const;
223 QRectF naturalTextRect() const;
229 enum CursorPosition {
230 CursorBetweenCharacters,
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;
239 void setLineWidth(qreal width);
240 void setNumColumns(int columns);
241 void setNumColumns(int columns, qreal alignmentWidth);
243 void setPosition(const QPointF &pos);
244 QPointF position() const;
246 int textStart() const;
247 int textLength() const;
249 int lineNumber() const { return index; }
251 void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = 0) const;
253 #if !defined(QT_NO_RAWFONT)
254 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
258 QTextLine(int line, QTextEngine *e) : index(line), eng(e) {}
259 void layout_helper(int numGlyphs);
261 friend class QTextLayout;
262 friend class QTextFragment;
271 #endif // QTEXTLAYOUT_H