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_P_H |
5 | #define QQUICKTEXT_P_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 "qquicktext_p.h" |
19 | #include "qquickimplicitsizeitem_p_p.h" |
20 | |
21 | #include <QtQml/qqml.h> |
22 | #include <QtGui/qabstracttextdocumentlayout.h> |
23 | #include <QtGui/qtextlayout.h> |
24 | #include <private/qquickstyledtext_p.h> |
25 | #include <private/qlazilyallocated_p.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QTextLayout; |
30 | class QQuickTextDocumentWithImageResources; |
31 | |
32 | class Q_QUICK_PRIVATE_EXPORT QQuickTextPrivate : public QQuickImplicitSizeItemPrivate |
33 | { |
34 | Q_DECLARE_PUBLIC(QQuickText) |
35 | public: |
36 | QQuickTextPrivate(); |
37 | ~QQuickTextPrivate(); |
38 | void init(); |
39 | |
40 | void updateBaseline(qreal baseline, qreal dy); |
41 | void updateSize(); |
42 | void signalSizeChange(const QSizeF &previousSize); |
43 | void updateLayout(); |
44 | bool determineHorizontalAlignment(); |
45 | bool setHAlign(QQuickText::HAlignment, bool forceAlign = false); |
46 | void mirrorChange() override; |
47 | bool isLineLaidOutConnected(); |
48 | void setLineGeometry(QTextLine &line, qreal lineWidth, qreal &height); |
49 | |
50 | int lineHeightOffset() const; |
51 | QString elidedText(qreal lineWidth, const QTextLine &line, const QTextLine *nextLine = nullptr) const; |
52 | void elideFormats(int start, int length, int offset, QVector<QTextLayout::FormatRange> *elidedFormats); |
53 | void clearFormats(); |
54 | |
55 | void processHoverEvent(QHoverEvent *event); |
56 | bool transformChanged(QQuickItem *transformedItem) override; |
57 | |
58 | QRectF layedOutTextRect; |
59 | QSizeF advance; |
60 | |
61 | struct { |
62 | (); |
63 | |
64 | qreal ; |
65 | qreal ; |
66 | qreal ; |
67 | qreal ; |
68 | qreal ; |
69 | bool : 1; |
70 | bool : 1; |
71 | bool : 1; |
72 | bool : 1; |
73 | qreal ; |
74 | QQuickTextDocumentWithImageResources *; |
75 | QString ; |
76 | QString ; |
77 | int ; |
78 | int ; |
79 | int ; |
80 | int ; |
81 | int ; |
82 | bool : 1; |
83 | QQuickText::LineHeightMode ; |
84 | QQuickText::FontSizeMode ; |
85 | QList<QQuickStyledTextImgTag*> ; |
86 | QList<QQuickStyledTextImgTag*> ; |
87 | QUrl ; |
88 | }; |
89 | QLazilyAllocated<ExtraData> ; |
90 | |
91 | QString text; |
92 | QFont font; |
93 | QFont sourceFont; |
94 | QFontInfo fontInfo; |
95 | |
96 | QTextLayout layout; |
97 | QTextLayout *elideLayout; |
98 | QQuickTextLine *textLine; |
99 | |
100 | qreal lineWidth; |
101 | |
102 | QRgb color; |
103 | QRgb linkColor; |
104 | QRgb styleColor; |
105 | |
106 | int lineCount; |
107 | int multilengthEos; |
108 | |
109 | enum UpdateType { |
110 | UpdateNone, |
111 | UpdatePreprocess, |
112 | UpdatePaintNode |
113 | }; |
114 | |
115 | QQuickText::TextElideMode elideMode; |
116 | QQuickText::HAlignment hAlign; |
117 | QQuickText::VAlignment vAlign; |
118 | QQuickText::TextFormat format; |
119 | QQuickText::WrapMode wrapMode; |
120 | QQuickText::TextStyle style; |
121 | QQuickText::RenderType renderType; |
122 | UpdateType updateType; |
123 | |
124 | QString assignedFont; |
125 | |
126 | bool maximumLineCountValid:1; |
127 | bool updateOnComponentComplete:1; |
128 | bool richText:1; |
129 | bool styledText:1; |
130 | bool markdownText:1; |
131 | bool widthExceeded:1; |
132 | bool heightExceeded:1; |
133 | bool internalWidthUpdate:1; |
134 | bool requireImplicitSize:1; |
135 | bool implicitWidthValid:1; |
136 | bool implicitHeightValid:1; |
137 | bool truncated:1; |
138 | bool hAlignImplicit:1; |
139 | bool rightToLeftText:1; |
140 | bool layoutTextElided:1; |
141 | bool textHasChanged:1; |
142 | bool needToUpdateLayout:1; |
143 | bool formatModifiesFontSize:1; |
144 | bool polishSize:1; // Workaround for problem with polish called after updateSize (QTBUG-42636) |
145 | bool updateSizeRecursionGuard:1; |
146 | |
147 | static const QChar elideChar; |
148 | static const int largeTextSizeThreshold; |
149 | |
150 | qreal getImplicitWidth() const override; |
151 | qreal getImplicitHeight() const override; |
152 | |
153 | qreal availableWidth() const; |
154 | qreal availableHeight() const; |
155 | |
156 | inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; } |
157 | void setTopPadding(qreal value, bool reset = false); |
158 | void setLeftPadding(qreal value, bool reset = false); |
159 | void setRightPadding(qreal value, bool reset = false); |
160 | void setBottomPadding(qreal value, bool reset = false); |
161 | |
162 | void ensureDoc(); |
163 | void updateDocumentText(); |
164 | |
165 | QRectF setupTextLayout(qreal * const baseline); |
166 | void setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset = 0); |
167 | bool isLinkActivatedConnected(); |
168 | bool isLinkHoveredConnected(); |
169 | QStringList links() const; |
170 | |
171 | struct LinkDesc { |
172 | QString m_anchor; |
173 | QString m_anchorTarget; |
174 | int m_startIndex; |
175 | int m_endIndex; |
176 | QRect rect; |
177 | }; |
178 | |
179 | QVector<LinkDesc> getLinks() const; |
180 | |
181 | static QString anchorAt(const QTextLayout *layout, const QPointF &mousePos); |
182 | QString anchorAt(const QPointF &pos) const; |
183 | |
184 | inline qreal lineHeight() const { return extra.isAllocated() ? extra->lineHeight : 1.0; } |
185 | inline int maximumLineCount() const { return extra.isAllocated() ? extra->maximumLineCount : INT_MAX; } |
186 | inline int renderTypeQuality() const { return extra.isAllocated() ? extra->renderTypeQuality : QQuickText::DefaultRenderTypeQuality; } |
187 | inline QQuickText::LineHeightMode lineHeightMode() const { return extra.isAllocated() ? extra->lineHeightMode : QQuickText::ProportionalHeight; } |
188 | inline QQuickText::FontSizeMode fontSizeMode() const { return extra.isAllocated() ? extra->fontSizeMode : QQuickText::FixedSize; } |
189 | inline int minimumPixelSize() const { return extra.isAllocated() ? extra->minimumPixelSize : 12; } |
190 | inline int minimumPointSize() const { return extra.isAllocated() ? extra->minimumPointSize : 12; } |
191 | static inline QQuickTextPrivate *get(QQuickText *t) { return t->d_func(); } |
192 | }; |
193 | |
194 | QT_END_NAMESPACE |
195 | |
196 | #endif // QQUICKTEXT_P_P_H |
197 | |