Qt 4.8
qtextlayout.h
Go to the documentation of this file.
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 
56 
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 
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;
97 };
98 
99 class QPaintDevice;
100 class QTextFormat;
101 class QTextLine;
102 class QTextBlock;
103 class QTextOption;
104 
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;
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 {
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);
182 private:
185 
186  friend class QPainter;
187  friend class QPSPrinter;
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);
194 };
195 
196 
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 {
221  Trailing
222  };
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 private:
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;
259 };
260 
262 
264 
265 #endif // QTEXTLAYOUT_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QTextEngine * engine() const
Definition: qtextlayout.h:180
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QTextInlineObject(int i, QTextEngine *e)
Creates a new inline object for the item at position i in the text engine e.
Definition: qtextlayout.h:72
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
qreal cursorToX(int cursorPos, Edge edge=Leading) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtextlayout.h:230
QTextLine()
Creates an invalid line.
Definition: qtextlayout.h:200
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
long ASN1_INTEGER_get ASN1_INTEGER * a
QTextEngine * eng
Definition: qtextlayout.h:96
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
static const QRectF boundingRect(const QPointF *points, int pointCount)
QTextEngine * eng
Definition: qtextlayout.h:258
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
LayoutDirection
Definition: qnamespace.h:1580
QTextLayout(QTextEngine *e)
Definition: qtextlayout.h:183
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
CursorMoveStyle
This enum describes the movement style available to text cursors.
Definition: qnamespace.h:1790
The QTextInlineObject class represents an inline object in a QTextLayout.
Definition: qtextlayout.h:69
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QTextOption *opt, const QString &str, QRectF *brect, int tabstops, int *, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
bool isValid() const
Returns true if this inline object is valid; otherwise returns false.
Definition: qtextlayout.h:74
#define text
Definition: qobjectdefs.h:80
QTextLine(int line, QTextEngine *e)
Definition: qtextlayout.h:248
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61