1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKTEXT_P_H
5#define QQUICKTEXT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qquickimplicitsizeitem_p.h"
19#include "qquicktextinterface_p.h"
20#include <private/qtquickglobal_p.h>
21#include <QtGui/qtextoption.h>
22
23QT_BEGIN_NAMESPACE
24
25class QQuickTextPrivate;
26class QQuickTextLine;
27class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem, public QQuickTextInterface
28{
29 Q_OBJECT
30 Q_INTERFACES(QQuickTextInterface)
31
32 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
33 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
34 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
35 Q_PROPERTY(QColor linkColor READ linkColor WRITE setLinkColor NOTIFY linkColorChanged FINAL)
36 Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged FINAL)
37 Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged FINAL)
38 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged FINAL)
39 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged FINAL)
40 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged FINAL)
41 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged FINAL)
42 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged FINAL)
43 Q_PROPERTY(bool truncated READ truncated NOTIFY truncatedChanged FINAL)
44 Q_PROPERTY(int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount NOTIFY maximumLineCountChanged RESET resetMaximumLineCount FINAL)
45
46 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged FINAL)
47 Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged FINAL) //### elideMode?
48 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentWidthChanged FINAL)
49 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentHeightChanged FINAL)
50 Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentWidthChanged FINAL) // Compatibility
51 Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentHeightChanged FINAL)
52 Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged FINAL)
53 Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged FINAL)
54 Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged FINAL)
55 Q_PROPERTY(int minimumPixelSize READ minimumPixelSize WRITE setMinimumPixelSize NOTIFY minimumPixelSizeChanged FINAL)
56 Q_PROPERTY(int minimumPointSize READ minimumPointSize WRITE setMinimumPointSize NOTIFY minimumPointSizeChanged FINAL)
57 Q_PROPERTY(FontSizeMode fontSizeMode READ fontSizeMode WRITE setFontSizeMode NOTIFY fontSizeModeChanged FINAL)
58 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged FINAL)
59 Q_PROPERTY(QString hoveredLink READ hoveredLink NOTIFY linkHovered REVISION(2, 2) FINAL)
60 Q_PROPERTY(int renderTypeQuality READ renderTypeQuality WRITE setRenderTypeQuality NOTIFY renderTypeQualityChanged REVISION(6, 0) FINAL)
61
62 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6) FINAL)
63 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6) FINAL)
64 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6) FINAL)
65 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6) FINAL)
66 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6) FINAL)
67
68 Q_PROPERTY(QJSValue fontInfo READ fontInfo NOTIFY fontInfoChanged REVISION(2, 9) FINAL)
69 Q_PROPERTY(QSizeF advance READ advance NOTIFY contentSizeChanged REVISION(2, 10) FINAL)
70 QML_NAMED_ELEMENT(Text)
71 QML_ADDED_IN_VERSION(2, 0)
72
73public:
74 QQuickText(QQuickItem *parent=nullptr);
75 ~QQuickText() override;
76
77 enum HAlignment { AlignLeft = Qt::AlignLeft,
78 AlignRight = Qt::AlignRight,
79 AlignHCenter = Qt::AlignHCenter,
80 AlignJustify = Qt::AlignJustify };
81 Q_ENUM(HAlignment)
82 enum VAlignment { AlignTop = Qt::AlignTop,
83 AlignBottom = Qt::AlignBottom,
84 AlignVCenter = Qt::AlignVCenter };
85 Q_ENUM(VAlignment)
86 enum TextStyle { Normal,
87 Outline,
88 Raised,
89 Sunken };
90 Q_ENUM(TextStyle)
91 enum TextFormat { PlainText = Qt::PlainText,
92 RichText = Qt::RichText,
93 MarkdownText = Qt::MarkdownText,
94 AutoText = Qt::AutoText,
95 StyledText = 4 };
96 Q_ENUM(TextFormat)
97 enum TextElideMode { ElideLeft = Qt::ElideLeft,
98 ElideRight = Qt::ElideRight,
99 ElideMiddle = Qt::ElideMiddle,
100 ElideNone = Qt::ElideNone };
101 Q_ENUM(TextElideMode)
102
103 enum WrapMode { NoWrap = QTextOption::NoWrap,
104 WordWrap = QTextOption::WordWrap,
105 WrapAnywhere = QTextOption::WrapAnywhere,
106 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
107 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
108 };
109 Q_ENUM(WrapMode)
110
111 enum RenderType { QtRendering,
112 NativeRendering
113 };
114 Q_ENUM(RenderType)
115
116 enum RenderTypeQuality { DefaultRenderTypeQuality = -1,
117 LowRenderTypeQuality = 26,
118 NormalRenderTypeQuality = 52,
119 HighRenderTypeQuality = 104,
120 VeryHighRenderTypeQuality = 208
121 };
122 Q_ENUM(RenderTypeQuality)
123
124 enum LineHeightMode { ProportionalHeight, FixedHeight };
125 Q_ENUM(LineHeightMode)
126
127 enum FontSizeMode { FixedSize = 0x0, HorizontalFit = 0x01, VerticalFit = 0x02,
128 Fit = HorizontalFit | VerticalFit };
129 Q_ENUM(FontSizeMode)
130
131 QString text() const;
132 void setText(const QString &);
133
134 QFont font() const;
135 void setFont(const QFont &font);
136
137 QColor color() const;
138 void setColor(const QColor &c);
139
140 QColor linkColor() const;
141 void setLinkColor(const QColor &color);
142
143 TextStyle style() const;
144 void setStyle(TextStyle style);
145
146 QColor styleColor() const;
147 void setStyleColor(const QColor &c);
148
149 HAlignment hAlign() const;
150 void setHAlign(HAlignment align);
151 void resetHAlign();
152 HAlignment effectiveHAlign() const;
153
154 VAlignment vAlign() const;
155 void setVAlign(VAlignment align);
156
157 WrapMode wrapMode() const;
158 void setWrapMode(WrapMode w);
159
160 int lineCount() const;
161 bool truncated() const;
162
163 int maximumLineCount() const;
164 void setMaximumLineCount(int lines);
165 void resetMaximumLineCount();
166
167 TextFormat textFormat() const;
168 void setTextFormat(TextFormat format);
169
170 TextElideMode elideMode() const;
171 void setElideMode(TextElideMode);
172
173 qreal lineHeight() const;
174 void setLineHeight(qreal lineHeight);
175
176 LineHeightMode lineHeightMode() const;
177 void setLineHeightMode(LineHeightMode);
178
179
180 QUrl baseUrl() const;
181 void setBaseUrl(const QUrl &url);
182 void resetBaseUrl();
183
184 int minimumPixelSize() const;
185 void setMinimumPixelSize(int size);
186
187 int minimumPointSize() const;
188 void setMinimumPointSize(int size);
189
190 FontSizeMode fontSizeMode() const;
191 void setFontSizeMode(FontSizeMode mode);
192
193 void componentComplete() override;
194
195 int resourcesLoading() const; // mainly for testing
196
197 qreal contentWidth() const;
198 qreal contentHeight() const;
199
200 QRectF boundingRect() const override;
201 QRectF clipRect() const override;
202#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
203#if QT_DEPRECATED_SINCE(5, 15)
204 QT_DEPRECATED_X("Use forceLayout() instead")
205 Q_INVOKABLE void doLayout();
206#endif
207#endif
208 Q_REVISION(2, 9) Q_INVOKABLE void forceLayout();
209
210 RenderType renderType() const;
211 void setRenderType(RenderType renderType);
212
213 int renderTypeQuality() const;
214 void setRenderTypeQuality(int renderTypeQuality);
215
216 QString hoveredLink() const;
217
218 Q_REVISION(2, 3) Q_INVOKABLE QString linkAt(qreal x, qreal y) const;
219
220 qreal padding() const;
221 void setPadding(qreal padding);
222 void resetPadding();
223
224 qreal topPadding() const;
225 void setTopPadding(qreal padding);
226 void resetTopPadding();
227
228 qreal leftPadding() const;
229 void setLeftPadding(qreal padding);
230 void resetLeftPadding();
231
232 qreal rightPadding() const;
233 void setRightPadding(qreal padding);
234 void resetRightPadding();
235
236 qreal bottomPadding() const;
237 void setBottomPadding(qreal padding);
238 void resetBottomPadding();
239
240 QJSValue fontInfo() const;
241 QSizeF advance() const;
242
243 void invalidate() override;
244
245Q_SIGNALS:
246 void textChanged(const QString &text);
247 void linkActivated(const QString &link);
248 Q_REVISION(2, 2) void linkHovered(const QString &link);
249 void fontChanged(const QFont &font);
250 void colorChanged();
251 void linkColorChanged();
252 void styleChanged(QQuickText::TextStyle style);
253 void styleColorChanged();
254 void horizontalAlignmentChanged(QQuickText::HAlignment alignment);
255 void verticalAlignmentChanged(QQuickText::VAlignment alignment);
256 void wrapModeChanged();
257 void lineCountChanged();
258 void truncatedChanged();
259 void maximumLineCountChanged();
260 void textFormatChanged(QQuickText::TextFormat textFormat);
261 void elideModeChanged(QQuickText::TextElideMode mode);
262 void contentSizeChanged();
263 // The next two signals should be marked as Q_REVISION(2, 12). See QTBUG-71247
264 void contentWidthChanged(qreal contentWidth);
265 void contentHeightChanged(qreal contentHeight);
266
267 void lineHeightChanged(qreal lineHeight);
268 void lineHeightModeChanged(LineHeightMode mode);
269 void fontSizeModeChanged();
270 void minimumPixelSizeChanged();
271 void minimumPointSizeChanged();
272 void effectiveHorizontalAlignmentChanged();
273 void lineLaidOut(QQuickTextLine *line);
274 void baseUrlChanged();
275 void renderTypeChanged();
276 Q_REVISION(2, 6) void paddingChanged();
277 Q_REVISION(2, 6) void topPaddingChanged();
278 Q_REVISION(2, 6) void leftPaddingChanged();
279 Q_REVISION(2, 6) void rightPaddingChanged();
280 Q_REVISION(2, 6) void bottomPaddingChanged();
281 Q_REVISION(2, 9) void fontInfoChanged();
282 Q_REVISION(6, 0) void renderTypeQualityChanged();
283
284protected:
285 QQuickText(QQuickTextPrivate &dd, QQuickItem *parent = nullptr);
286
287 void mousePressEvent(QMouseEvent *event) override;
288 void mouseReleaseEvent(QMouseEvent *event) override;
289 void itemChange(ItemChange change, const ItemChangeData &value) override;
290 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
291 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
292
293 void updatePolish() override;
294
295 void hoverEnterEvent(QHoverEvent *event) override;
296 void hoverMoveEvent(QHoverEvent *event) override;
297 void hoverLeaveEvent(QHoverEvent *event) override;
298 void invalidateFontCaches();
299
300private Q_SLOTS:
301 void q_updateLayout();
302 void triggerPreprocess();
303 void imageDownloadFinished();
304
305private:
306 Q_DISABLE_COPY(QQuickText)
307 Q_DECLARE_PRIVATE(QQuickText)
308};
309
310Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, QQuickText::HAlignment, QQuickText::VAlignment)
311
312class QTextLine;
313class Q_QUICK_PRIVATE_EXPORT QQuickTextLine : public QObject
314{
315 Q_OBJECT
316 Q_PROPERTY(int number READ number FINAL)
317 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
318 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
319 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
320 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
321 Q_PROPERTY(qreal implicitWidth READ implicitWidth REVISION(2, 15) FINAL)
322 Q_PROPERTY(bool isLast READ isLast REVISION(2, 15) FINAL)
323 QML_ANONYMOUS
324 QML_ADDED_IN_VERSION(2, 0)
325
326public:
327 QQuickTextLine();
328
329 void setLine(QTextLine* line);
330 void setLineOffset(int offset);
331 void setFullLayoutTextLength(int length);
332 int number() const;
333 qreal implicitWidth() const;
334 bool isLast() const;
335
336 qreal width() const;
337 void setWidth(qreal width);
338
339 qreal height() const;
340 void setHeight(qreal height);
341
342 qreal x() const;
343 void setX(qreal x);
344
345 qreal y() const;
346 void setY(qreal y);
347
348private:
349 QTextLine *m_line;
350 qreal m_height;
351 int m_lineOffset;
352 int m_fullLayoutTextLength;
353};
354
355QT_END_NAMESPACE
356
357QML_DECLARE_TYPE(QQuickText)
358QML_DECLARE_TYPE(QQuickTextLine)
359
360#endif // QQUICKTEXT_P_H
361

source code of qtdeclarative/src/quick/items/qquicktext_p.h