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

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