1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
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>
69 class Q_GUI_EXPORT QTextInlineObject
72 QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
73 inline QTextInlineObject() : itm(0), eng(0) {}
74 inline bool isValid() const { return eng; }
79 qreal descent() const;
82 Qt::LayoutDirection textDirection() const;
84 void setWidth(qreal w);
85 void setAscent(qreal a);
86 void setDescent(qreal d);
88 int textPosition() const;
90 int formatIndex() const;
91 QTextFormat format() const;
94 friend class QTextLayout;
105 class Q_GUI_EXPORT QTextLayout
110 QTextLayout(const QString& text);
111 QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = 0);
112 QTextLayout(const QTextBlock &b);
115 void setFont(const QFont &f);
118 void setText(const QString& string);
119 QString text() const;
121 void setTextOption(const QTextOption &option);
122 QTextOption textOption() const;
124 void setPreeditArea(int position, const QString &text);
125 int preeditAreaPosition() const;
126 QString preeditAreaText() const;
131 QTextCharFormat format;
133 void setAdditionalFormats(const QList<FormatRange> &overrides);
134 QList<FormatRange> additionalFormats() const;
135 void clearAdditionalFormats();
137 void setCacheEnabled(bool enable);
138 bool cacheEnabled() const;
140 void setCursorMoveStyle(Qt::CursorMoveStyle style);
141 Qt::CursorMoveStyle cursorMoveStyle() const;
147 QTextLine createLine();
149 int lineCount() const;
150 QTextLine lineAt(int i) const;
151 QTextLine lineForTextPosition(int pos) const;
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;
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;
168 QPointF position() const;
169 void setPosition(const QPointF &p);
171 QRectF boundingRect() const;
173 qreal minimumWidth() const;
174 qreal maximumWidth() const;
176 #if !defined(QT_NO_RAWFONT)
177 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
180 QTextEngine *engine() const { return d; }
181 void setFlags(int flags);
183 QTextLayout(QTextEngine *e) : d(e) {}
184 Q_DISABLE_COPY(QTextLayout)
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,
197 class Q_GUI_EXPORT QTextLine
200 inline QTextLine() : i(0), eng(0) {}
201 inline bool isValid() const { return eng; }
207 qreal ascent() const;
208 qreal descent() const;
209 qreal height() const;
210 qreal leading() const;
212 void setLeadingIncluded(bool included);
213 bool leadingIncluded() const;
215 qreal naturalTextWidth() const;
216 qreal horizontalAdvance() const;
217 QRectF naturalTextRect() const;
223 enum CursorPosition {
224 CursorBetweenCharacters,
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;
233 void setLineWidth(qreal width);
234 void setNumColumns(int columns);
235 void setNumColumns(int columns, qreal alignmentWidth);
237 void setPosition(const QPointF &pos);
238 QPointF position() const;
240 int textStart() const;
241 int textLength() const;
243 int lineNumber() const { return i; }
245 void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = 0) const;
247 #if !defined(QT_NO_RAWFONT)
248 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
252 QTextLine(int line, QTextEngine *e) : i(line), eng(e) {}
253 void layout_helper(int numGlyphs);
255 friend class QTextLayout;
256 friend class QTextFragment;
265 #endif // QTEXTLAYOUT_H