File indexing completed on 2025-01-18 10:08:17
0001
0002
0003 #ifndef QTEXTLAYOUT_H
0004 #define QTEXTLAYOUT_H
0005
0006 #include <QtGui/qcolor.h>
0007 #include <QtGui/qevent.h>
0008 #include <QtGui/qglyphrun.h>
0009 #include <QtGui/qtextcursor.h>
0010 #include <QtGui/qtextformat.h>
0011 #include <QtGui/qtguiglobal.h>
0012
0013 #include <QtCore/qlist.h>
0014 #include <QtCore/qnamespace.h>
0015 #include <QtCore/qobject.h>
0016 #include <QtCore/qrect.h>
0017 #include <QtCore/qstring.h>
0018
0019 QT_BEGIN_NAMESPACE
0020
0021
0022 class QTextEngine;
0023 class QFont;
0024 #ifndef QT_NO_RAWFONT
0025 class QRawFont;
0026 #endif
0027 class QRect;
0028 class QRegion;
0029 class QTextFormat;
0030 class QPalette;
0031 class QPainter;
0032
0033 class Q_GUI_EXPORT QTextInlineObject
0034 {
0035 public:
0036 QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
0037 inline QTextInlineObject() : itm(0), eng(nullptr) {}
0038 inline bool isValid() const { return eng; }
0039
0040 QRectF rect() const;
0041 qreal width() const;
0042 qreal ascent() const;
0043 qreal descent() const;
0044 qreal height() const;
0045
0046 Qt::LayoutDirection textDirection() const;
0047
0048 void setWidth(qreal w);
0049 void setAscent(qreal a);
0050 void setDescent(qreal d);
0051
0052 int textPosition() const;
0053
0054 int formatIndex() const;
0055 QTextFormat format() const;
0056
0057 private:
0058 friend class QTextLayout;
0059 int itm;
0060 QTextEngine *eng;
0061 };
0062
0063 class QPaintDevice;
0064 class QTextFormat;
0065 class QTextLine;
0066 class QTextBlock;
0067 class QTextOption;
0068
0069 class Q_GUI_EXPORT QTextLayout
0070 {
0071 public:
0072 enum GlyphRunRetrievalFlag : quint16 {
0073 RetrieveGlyphIndexes = 0x1,
0074 RetrieveGlyphPositions = 0x2,
0075 RetrieveStringIndexes = 0x4,
0076 RetrieveString = 0x8,
0077
0078 DefaultRetrievalFlags = RetrieveGlyphIndexes | RetrieveGlyphPositions,
0079 RetrieveAll = 0xffff
0080 };
0081 Q_DECLARE_FLAGS(GlyphRunRetrievalFlags, GlyphRunRetrievalFlag)
0082
0083
0084 QTextLayout();
0085 QTextLayout(const QString& text);
0086 QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice = nullptr);
0087 QTextLayout(const QTextBlock &b);
0088 ~QTextLayout();
0089
0090 void setFont(const QFont &f);
0091 QFont font() const;
0092
0093 #ifndef QT_NO_RAWFONT
0094 void setRawFont(const QRawFont &rawFont);
0095 #endif
0096
0097 void setText(const QString& string);
0098 QString text() const;
0099
0100 void setTextOption(const QTextOption &option);
0101 const QTextOption &textOption() const;
0102
0103 void setPreeditArea(int position, const QString &text);
0104 int preeditAreaPosition() const;
0105 QString preeditAreaText() const;
0106
0107 struct FormatRange {
0108 int start;
0109 int length;
0110 QTextCharFormat format;
0111
0112 friend bool operator==(const FormatRange &lhs, const FormatRange &rhs)
0113 { return lhs.start == rhs.start && lhs.length == rhs.length && lhs.format == rhs.format; }
0114 friend bool operator!=(const FormatRange &lhs, const FormatRange &rhs)
0115 { return !operator==(lhs, rhs); }
0116 };
0117 void setFormats(const QList<FormatRange> &overrides);
0118 QList<FormatRange> formats() const;
0119 void clearFormats();
0120
0121 void setCacheEnabled(bool enable);
0122 bool cacheEnabled() const;
0123
0124 void setCursorMoveStyle(Qt::CursorMoveStyle style);
0125 Qt::CursorMoveStyle cursorMoveStyle() const;
0126
0127 void beginLayout();
0128 void endLayout();
0129 void clearLayout();
0130
0131 QTextLine createLine();
0132
0133 int lineCount() const;
0134 QTextLine lineAt(int i) const;
0135 QTextLine lineForTextPosition(int pos) const;
0136
0137 enum CursorMode {
0138 SkipCharacters,
0139 SkipWords
0140 };
0141 bool isValidCursorPosition(int pos) const;
0142 int nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
0143 int previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
0144 int leftCursorPosition(int oldPos) const;
0145 int rightCursorPosition(int oldPos) const;
0146
0147 void draw(QPainter *p, const QPointF &pos,
0148 const QList<FormatRange> &selections = QList<FormatRange>(),
0149 const QRectF &clip = QRectF()) const;
0150 void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const;
0151 void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition, int width) const;
0152
0153 QPointF position() const;
0154 void setPosition(const QPointF &p);
0155
0156 QRectF boundingRect() const;
0157
0158 qreal minimumWidth() const;
0159 qreal maximumWidth() const;
0160
0161 #if !defined(QT_NO_RAWFONT)
0162
0163 # if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0164 QList<QGlyphRun> glyphRuns(int from, int length, GlyphRunRetrievalFlags flags) const;
0165 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
0166 # else
0167 QList<QGlyphRun> glyphRuns(int from = -1,
0168 int length = -1,
0169 GlyphRunRetrievalFlags flags = DefaultRetrievalFlags) const;
0170 # endif
0171 #endif
0172
0173 QTextEngine *engine() const { return d; }
0174 void setFlags(int flags);
0175 private:
0176 QTextLayout(QTextEngine *e) : d(e) {}
0177 Q_DISABLE_COPY(QTextLayout)
0178
0179 friend class QPainter;
0180 friend class QGraphicsSimpleTextItemPrivate;
0181 friend class QGraphicsSimpleTextItem;
0182 friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str,
0183 QRectF *brect, int tabstops, int* tabarray, int tabarraylen,
0184 QPainter *painter);
0185 QTextEngine *d;
0186 };
0187 Q_DECLARE_TYPEINFO(QTextLayout::FormatRange, Q_RELOCATABLE_TYPE);
0188 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextLayout::GlyphRunRetrievalFlags)
0189
0190 class Q_GUI_EXPORT QTextLine
0191 {
0192 public:
0193 inline QTextLine() : index(0), eng(nullptr) {}
0194 inline bool isValid() const { return eng; }
0195
0196 QRectF rect() const;
0197 qreal x() const;
0198 qreal y() const;
0199 qreal width() const;
0200 qreal ascent() const;
0201 qreal descent() const;
0202 qreal height() const;
0203 qreal leading() const;
0204
0205 void setLeadingIncluded(bool included);
0206 bool leadingIncluded() const;
0207
0208 qreal naturalTextWidth() const;
0209 qreal horizontalAdvance() const;
0210 QRectF naturalTextRect() const;
0211
0212 enum Edge {
0213 Leading,
0214 Trailing
0215 };
0216 enum CursorPosition {
0217 CursorBetweenCharacters,
0218 CursorOnCharacter
0219 };
0220
0221
0222 qreal cursorToX(int *cursorPos, Edge edge = Leading) const;
0223 inline qreal cursorToX(int cursorPos, Edge edge = Leading) const { return cursorToX(&cursorPos, edge); }
0224 int xToCursor(qreal x, CursorPosition = CursorBetweenCharacters) const;
0225
0226 void setLineWidth(qreal width);
0227 void setNumColumns(int columns);
0228 void setNumColumns(int columns, qreal alignmentWidth);
0229
0230 void setPosition(const QPointF &pos);
0231 QPointF position() const;
0232
0233 int textStart() const;
0234 int textLength() const;
0235
0236 int lineNumber() const { return index; }
0237
0238 void draw(QPainter *painter, const QPointF &position) const;
0239
0240 #if !defined(QT_NO_RAWFONT)
0241 # if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0242 QList<QGlyphRun> glyphRuns(int from, int length, QTextLayout::GlyphRunRetrievalFlags flags) const;
0243 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
0244 # else
0245 QList<QGlyphRun> glyphRuns(int from = -1,
0246 int length = -1,
0247 QTextLayout::GlyphRunRetrievalFlags flags = QTextLayout::DefaultRetrievalFlags) const;
0248 # endif
0249 #endif
0250
0251 private:
0252 QTextLine(int line, QTextEngine *e) : index(line), eng(e) {}
0253 void layout_helper(int numGlyphs);
0254 void draw_internal(QPainter *p, const QPointF &pos,
0255 const QTextLayout::FormatRange *selection) const;
0256
0257 friend class QTextLayout;
0258 friend class QTextFragment;
0259 int index;
0260 QTextEngine *eng;
0261 };
0262
0263 QT_END_NAMESPACE
0264
0265 #endif