| 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 | #include <private/qquicktextdocument_p.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QTextLayout; |
| 31 | |
| 32 | class Q_QUICK_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 | QTextDocument *; |
| 75 | QQuickTextImageHandler *imageHandler = nullptr; |
| 76 | QString ; |
| 77 | QString ; |
| 78 | int ; |
| 79 | int ; |
| 80 | int ; |
| 81 | int ; |
| 82 | bool : 1; |
| 83 | QQuickText::LineHeightMode ; |
| 84 | QQuickText::FontSizeMode ; |
| 85 | QList<QQuickStyledTextImgTag*> ; |
| 86 | QList<QQuickStyledTextImgTag*> ; |
| 87 | QList<QQuickPixmap *> ; |
| 88 | QUrl ; |
| 89 | }; |
| 90 | QLazilyAllocated<ExtraData> ; |
| 91 | |
| 92 | QString text; |
| 93 | QFont font; |
| 94 | QFont sourceFont; |
| 95 | QFontInfo fontInfo; |
| 96 | |
| 97 | QTextLayout layout; |
| 98 | QScopedPointer<QTextLayout> elideLayout; |
| 99 | QScopedPointer<QQuickTextLine> textLine; |
| 100 | |
| 101 | qreal lineWidth; |
| 102 | |
| 103 | QRgb color; |
| 104 | QRgb linkColor; |
| 105 | QRgb styleColor; |
| 106 | |
| 107 | int lineCount; |
| 108 | int multilengthEos; |
| 109 | |
| 110 | enum UpdateType { |
| 111 | UpdateNone, |
| 112 | UpdatePreprocess, |
| 113 | UpdatePaintNode |
| 114 | }; |
| 115 | |
| 116 | QQuickText::TextElideMode elideMode; |
| 117 | QQuickText::HAlignment hAlign; |
| 118 | QQuickText::VAlignment vAlign; |
| 119 | QQuickText::TextFormat format; |
| 120 | QQuickText::WrapMode wrapMode; |
| 121 | QQuickText::TextStyle style; |
| 122 | QQuickText::RenderType renderType; |
| 123 | UpdateType updateType; |
| 124 | |
| 125 | QString assignedFont; |
| 126 | |
| 127 | bool maximumLineCountValid:1; |
| 128 | bool updateOnComponentComplete:1; |
| 129 | bool richText:1; |
| 130 | bool styledText:1; |
| 131 | bool markdownText:1; |
| 132 | bool widthExceeded:1; |
| 133 | bool heightExceeded:1; |
| 134 | bool internalWidthUpdate:1; |
| 135 | bool requireImplicitSize:1; |
| 136 | bool implicitWidthValid:1; |
| 137 | bool implicitHeightValid:1; |
| 138 | bool truncated:1; |
| 139 | bool hAlignImplicit:1; |
| 140 | bool rightToLeftText:1; |
| 141 | bool layoutTextElided:1; |
| 142 | bool textHasChanged:1; |
| 143 | bool needToUpdateLayout:1; |
| 144 | bool formatModifiesFontSize:1; |
| 145 | bool polishSize:1; // Workaround for problem with polish called after updateSize (QTBUG-42636) |
| 146 | bool updateSizeRecursionGuard:1; |
| 147 | bool containsUnscalableGlyphs:1; |
| 148 | |
| 149 | static const QChar elideChar; |
| 150 | static const int largeTextSizeThreshold; |
| 151 | |
| 152 | qreal getImplicitWidth() const override; |
| 153 | qreal getImplicitHeight() const override; |
| 154 | |
| 155 | qreal availableWidth() const; |
| 156 | qreal availableHeight() const; |
| 157 | |
| 158 | inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; } |
| 159 | void setTopPadding(qreal value, bool reset = false); |
| 160 | void setLeftPadding(qreal value, bool reset = false); |
| 161 | void setRightPadding(qreal value, bool reset = false); |
| 162 | void setBottomPadding(qreal value, bool reset = false); |
| 163 | |
| 164 | void ensureDoc(); |
| 165 | void updateDocumentText(); |
| 166 | |
| 167 | qreal devicePixelRatio() const; |
| 168 | |
| 169 | QRectF setupTextLayout(qreal * const baseline); |
| 170 | void setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset = 0); |
| 171 | bool isLinkActivatedConnected(); |
| 172 | bool isLinkHoveredConnected(); |
| 173 | QStringList links() const; |
| 174 | |
| 175 | struct LinkDesc { |
| 176 | QString m_anchor; |
| 177 | QString m_anchorTarget; |
| 178 | int m_startIndex; |
| 179 | int m_endIndex; |
| 180 | QRect rect; |
| 181 | }; |
| 182 | |
| 183 | QVector<LinkDesc> getLinks() const; |
| 184 | |
| 185 | static QString anchorAt(const QTextLayout *layout, const QPointF &mousePos); |
| 186 | QString anchorAt(const QPointF &pos) const; |
| 187 | |
| 188 | inline qreal lineHeight() const { return extra.isAllocated() ? extra->lineHeight : 1.0; } |
| 189 | inline int maximumLineCount() const { return extra.isAllocated() ? extra->maximumLineCount : INT_MAX; } |
| 190 | inline int renderTypeQuality() const { return extra.isAllocated() ? extra->renderTypeQuality : QQuickText::DefaultRenderTypeQuality; } |
| 191 | inline QQuickText::LineHeightMode lineHeightMode() const { return extra.isAllocated() ? extra->lineHeightMode : QQuickText::ProportionalHeight; } |
| 192 | inline QQuickText::FontSizeMode fontSizeMode() const { return extra.isAllocated() ? extra->fontSizeMode : QQuickText::FixedSize; } |
| 193 | inline int minimumPixelSize() const { return extra.isAllocated() ? extra->minimumPixelSize : 12; } |
| 194 | inline int minimumPointSize() const { return extra.isAllocated() ? extra->minimumPointSize : 12; } |
| 195 | static inline QQuickTextPrivate *get(QQuickText *t) { return t->d_func(); } |
| 196 | }; |
| 197 | |
| 198 | QT_END_NAMESPACE |
| 199 | |
| 200 | #endif // QQUICKTEXT_P_P_H |
| 201 | |