Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquicktext_p.h
Go to the documentation of this file.
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
20#include <private/qtquickglobal_p.h>
21#include <QtGui/qtextoption.h>
22
24
26class QQuickTextLine;
27class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem, public QQuickTextInterface
28{
31
32 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
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)
72
73public:
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)
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
106 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
108 };
109 Q_ENUM(WrapMode)
110
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
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
247 void linkActivated(const QString &link);
248 Q_REVISION(2, 2) void linkHovered(const QString &link);
249 void fontChanged(const QFont &font);
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:
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
301 void q_updateLayout();
302 void triggerPreprocess();
303 void imageDownloadFinished();
304
305private:
306 Q_DISABLE_COPY(QQuickText)
307 Q_DECLARE_PRIVATE(QQuickText)
308};
309
311
312class QTextLine;
314{
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)
325
326public:
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
356
359
360#endif // QQUICKTEXT_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\reentrant
Definition qfont.h:20
\inmodule QtGui
Definition qevent.h:245
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtGui
Definition qevent.h:195
\inmodule QtCore
Definition qobject.h:90
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
virtual QRectF clipRect() const
Returns the rectangular area within this item that is currently visible in \l viewportItem(),...
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
Q_REVISION(2, 9) Q_INVOKABLE void forceLayout()
\inmodule QtCore\reentrant
Definition qrect.h:483
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
\inmodule QtCore
Definition qsize.h:207
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\reentrant
@ WrapAtWordBoundaryOrAnywhere
Definition qtextoption.h:65
\inmodule QtCore
Definition qurl.h:94
QString text
void colorChanged()
void textChanged(const QString &newText)
uint alignment
Combined button and popup list for selecting options.
@ AlignRight
Definition qnamespace.h:145
@ AlignJustify
Definition qnamespace.h:148
@ AlignBottom
Definition qnamespace.h:153
@ AlignVCenter
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:152
@ AlignHCenter
Definition qnamespace.h:147
@ AlignLeft
Definition qnamespace.h:143
@ RichText
@ MarkdownText
@ PlainText
@ AutoText
@ ElideMiddle
Definition qnamespace.h:190
@ ElideRight
Definition qnamespace.h:189
@ ElideNone
Definition qnamespace.h:191
@ ElideLeft
Definition qnamespace.h:188
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(Ret, Flags, Enum)
Definition qflags.h:247
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei width
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLint y
struct _cl_event * event
const GLubyte * c
#define QML_DECLARE_TYPE(TYPE)
Definition qqml.h:19
#define QML_ANONYMOUS
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QT_DEPRECATED_X(text)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_INVOKABLE
#define Q_INTERFACES(x)
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:92
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
p setX(p.x()+1)
myFilter setColor(QColor(128, 0, 0))
widget setStyle(proxy)
insertRed setText("insert red text")
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
\inmodule QtQuick
Definition qquickitem.h:158