| 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 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QQuickTextPrivate; |
| 26 | class QQuickTextLine; |
| 27 | class Q_QUICK_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) |
| 35 | Q_PROPERTY(QColor linkColor READ linkColor WRITE setLinkColor NOTIFY linkColorChanged) |
| 36 | Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged) |
| 37 | Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged) |
| 38 | Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged) |
| 39 | Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged) |
| 40 | Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged) |
| 41 | Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) |
| 42 | Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged) |
| 43 | Q_PROPERTY(bool truncated READ truncated NOTIFY truncatedChanged) |
| 44 | Q_PROPERTY(int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount NOTIFY maximumLineCountChanged RESET resetMaximumLineCount) |
| 45 | |
| 46 | Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) |
| 47 | Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode? |
| 48 | Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentWidthChanged) |
| 49 | Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentHeightChanged) |
| 50 | Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentWidthChanged) // Compatibility |
| 51 | Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentHeightChanged) |
| 52 | Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged) |
| 53 | Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged) |
| 54 | Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged) |
| 55 | Q_PROPERTY(int minimumPixelSize READ minimumPixelSize WRITE setMinimumPixelSize NOTIFY minimumPixelSizeChanged) |
| 56 | Q_PROPERTY(int minimumPointSize READ minimumPointSize WRITE setMinimumPointSize NOTIFY minimumPointSizeChanged) |
| 57 | Q_PROPERTY(FontSizeMode fontSizeMode READ fontSizeMode WRITE setFontSizeMode NOTIFY fontSizeModeChanged) |
| 58 | Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged) |
| 59 | Q_PROPERTY(QString hoveredLink READ hoveredLink NOTIFY linkHovered REVISION(2, 2)) |
| 60 | Q_PROPERTY(int renderTypeQuality READ renderTypeQuality WRITE setRenderTypeQuality NOTIFY renderTypeQualityChanged REVISION(6, 0)) |
| 61 | |
| 62 | Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6)) |
| 63 | Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6)) |
| 64 | Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6)) |
| 65 | Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6)) |
| 66 | Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6)) |
| 67 | |
| 68 | Q_PROPERTY(QJSValue fontInfo READ fontInfo NOTIFY fontInfoChanged REVISION(2, 9)) |
| 69 | Q_PROPERTY(QSizeF advance READ advance NOTIFY contentSizeChanged REVISION(2, 10)) |
| 70 | QML_NAMED_ELEMENT(Text) |
| 71 | QML_ADDED_IN_VERSION(2, 0) |
| 72 | |
| 73 | public: |
| 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 | CurveRendering |
| 114 | }; |
| 115 | Q_ENUM(RenderType) |
| 116 | |
| 117 | enum RenderTypeQuality { DefaultRenderTypeQuality = -1, |
| 118 | LowRenderTypeQuality = 26, |
| 119 | NormalRenderTypeQuality = 52, |
| 120 | HighRenderTypeQuality = 104, |
| 121 | VeryHighRenderTypeQuality = 208 |
| 122 | }; |
| 123 | Q_ENUM(RenderTypeQuality) |
| 124 | |
| 125 | enum LineHeightMode { ProportionalHeight, FixedHeight }; |
| 126 | Q_ENUM(LineHeightMode) |
| 127 | |
| 128 | enum FontSizeMode { FixedSize = 0x0, HorizontalFit = 0x01, VerticalFit = 0x02, |
| 129 | Fit = HorizontalFit | VerticalFit }; |
| 130 | Q_ENUM(FontSizeMode) |
| 131 | |
| 132 | QString text() const; |
| 133 | void setText(const QString &); |
| 134 | |
| 135 | QFont font() const; |
| 136 | void setFont(const QFont &font); |
| 137 | |
| 138 | QColor color() const; |
| 139 | void setColor(const QColor &c); |
| 140 | |
| 141 | QColor linkColor() const; |
| 142 | void setLinkColor(const QColor &color); |
| 143 | |
| 144 | TextStyle style() const; |
| 145 | void setStyle(TextStyle style); |
| 146 | |
| 147 | QColor styleColor() const; |
| 148 | void setStyleColor(const QColor &c); |
| 149 | |
| 150 | HAlignment hAlign() const; |
| 151 | void setHAlign(HAlignment align); |
| 152 | void resetHAlign(); |
| 153 | HAlignment effectiveHAlign() const; |
| 154 | |
| 155 | VAlignment vAlign() const; |
| 156 | void setVAlign(VAlignment align); |
| 157 | |
| 158 | WrapMode wrapMode() const; |
| 159 | void setWrapMode(WrapMode w); |
| 160 | |
| 161 | int lineCount() const; |
| 162 | bool truncated() const; |
| 163 | |
| 164 | int maximumLineCount() const; |
| 165 | void setMaximumLineCount(int lines); |
| 166 | void resetMaximumLineCount(); |
| 167 | |
| 168 | TextFormat textFormat() const; |
| 169 | void setTextFormat(TextFormat format); |
| 170 | |
| 171 | TextElideMode elideMode() const; |
| 172 | void setElideMode(TextElideMode); |
| 173 | |
| 174 | qreal lineHeight() const; |
| 175 | void setLineHeight(qreal lineHeight); |
| 176 | |
| 177 | LineHeightMode lineHeightMode() const; |
| 178 | void setLineHeightMode(LineHeightMode); |
| 179 | |
| 180 | |
| 181 | QUrl baseUrl() const; |
| 182 | void setBaseUrl(const QUrl &url); |
| 183 | void resetBaseUrl(); |
| 184 | |
| 185 | int minimumPixelSize() const; |
| 186 | void setMinimumPixelSize(int size); |
| 187 | |
| 188 | int minimumPointSize() const; |
| 189 | void setMinimumPointSize(int size); |
| 190 | |
| 191 | FontSizeMode fontSizeMode() const; |
| 192 | void setFontSizeMode(FontSizeMode mode); |
| 193 | |
| 194 | void componentComplete() override; |
| 195 | |
| 196 | int resourcesLoading() const; // mainly for testing |
| 197 | |
| 198 | qreal contentWidth() const; |
| 199 | qreal contentHeight() const; |
| 200 | |
| 201 | QRectF boundingRect() const override; |
| 202 | QRectF clipRect() const override; |
| 203 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 204 | #if QT_DEPRECATED_SINCE(5, 15) |
| 205 | QT_DEPRECATED_X("Use forceLayout() instead" ) |
| 206 | Q_INVOKABLE void doLayout(); |
| 207 | #endif |
| 208 | #endif |
| 209 | Q_REVISION(2, 9) Q_INVOKABLE void forceLayout(); |
| 210 | |
| 211 | RenderType renderType() const; |
| 212 | void setRenderType(RenderType renderType); |
| 213 | |
| 214 | int renderTypeQuality() const; |
| 215 | void setRenderTypeQuality(int renderTypeQuality); |
| 216 | |
| 217 | QString hoveredLink() const; |
| 218 | |
| 219 | Q_REVISION(2, 3) Q_INVOKABLE QString linkAt(qreal x, qreal y) const; |
| 220 | |
| 221 | qreal padding() const; |
| 222 | void setPadding(qreal padding); |
| 223 | void resetPadding(); |
| 224 | |
| 225 | qreal topPadding() const; |
| 226 | void setTopPadding(qreal padding); |
| 227 | void resetTopPadding(); |
| 228 | |
| 229 | qreal leftPadding() const; |
| 230 | void setLeftPadding(qreal padding); |
| 231 | void resetLeftPadding(); |
| 232 | |
| 233 | qreal rightPadding() const; |
| 234 | void setRightPadding(qreal padding); |
| 235 | void resetRightPadding(); |
| 236 | |
| 237 | qreal bottomPadding() const; |
| 238 | void setBottomPadding(qreal padding); |
| 239 | void resetBottomPadding(); |
| 240 | |
| 241 | QJSValue fontInfo() const; |
| 242 | QSizeF advance() const; |
| 243 | |
| 244 | void invalidate() override; |
| 245 | |
| 246 | Q_SIGNALS: |
| 247 | void textChanged(const QString &text); |
| 248 | void linkActivated(const QString &link); |
| 249 | Q_REVISION(2, 2) void linkHovered(const QString &link); |
| 250 | void fontChanged(const QFont &font); |
| 251 | void colorChanged(); |
| 252 | void linkColorChanged(); |
| 253 | void styleChanged(QQuickText::TextStyle style); |
| 254 | void styleColorChanged(); |
| 255 | void horizontalAlignmentChanged(QQuickText::HAlignment alignment); |
| 256 | void verticalAlignmentChanged(QQuickText::VAlignment alignment); |
| 257 | void wrapModeChanged(); |
| 258 | void lineCountChanged(); |
| 259 | void truncatedChanged(); |
| 260 | void maximumLineCountChanged(); |
| 261 | void textFormatChanged(QQuickText::TextFormat textFormat); |
| 262 | void elideModeChanged(QQuickText::TextElideMode mode); |
| 263 | void contentSizeChanged(); |
| 264 | // The next two signals should be marked as Q_REVISION(2, 12). See QTBUG-71247 |
| 265 | void contentWidthChanged(qreal contentWidth); |
| 266 | void contentHeightChanged(qreal contentHeight); |
| 267 | |
| 268 | void lineHeightChanged(qreal lineHeight); |
| 269 | void lineHeightModeChanged(LineHeightMode mode); |
| 270 | void fontSizeModeChanged(); |
| 271 | void minimumPixelSizeChanged(); |
| 272 | void minimumPointSizeChanged(); |
| 273 | void effectiveHorizontalAlignmentChanged(); |
| 274 | void lineLaidOut(QQuickTextLine *line); |
| 275 | void baseUrlChanged(); |
| 276 | void renderTypeChanged(); |
| 277 | Q_REVISION(2, 6) void paddingChanged(); |
| 278 | Q_REVISION(2, 6) void topPaddingChanged(); |
| 279 | Q_REVISION(2, 6) void leftPaddingChanged(); |
| 280 | Q_REVISION(2, 6) void rightPaddingChanged(); |
| 281 | Q_REVISION(2, 6) void bottomPaddingChanged(); |
| 282 | Q_REVISION(2, 9) void fontInfoChanged(); |
| 283 | Q_REVISION(6, 0) void renderTypeQualityChanged(); |
| 284 | |
| 285 | protected: |
| 286 | QQuickText(QQuickTextPrivate &dd, QQuickItem *parent = nullptr); |
| 287 | |
| 288 | void mousePressEvent(QMouseEvent *event) override; |
| 289 | void mouseReleaseEvent(QMouseEvent *event) override; |
| 290 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 291 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 292 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 293 | |
| 294 | void updatePolish() override; |
| 295 | |
| 296 | void hoverEnterEvent(QHoverEvent *event) override; |
| 297 | void hoverMoveEvent(QHoverEvent *event) override; |
| 298 | void hoverLeaveEvent(QHoverEvent *event) override; |
| 299 | void invalidateFontCaches(); |
| 300 | |
| 301 | private Q_SLOTS: |
| 302 | void q_updateLayout(); |
| 303 | void triggerPreprocess(); |
| 304 | Q_REVISION(6, 7) QVariant loadResource(int type, const QUrl &source); |
| 305 | void resourceRequestFinished(); |
| 306 | void imageDownloadFinished(); |
| 307 | |
| 308 | private: |
| 309 | Q_DISABLE_COPY(QQuickText) |
| 310 | Q_DECLARE_PRIVATE(QQuickText) |
| 311 | }; |
| 312 | |
| 313 | Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, QQuickText::HAlignment, QQuickText::VAlignment) |
| 314 | |
| 315 | class QTextLine; |
| 316 | class Q_QUICK_EXPORT QQuickTextLine : public QObject |
| 317 | { |
| 318 | Q_OBJECT |
| 319 | Q_PROPERTY(int number READ number FINAL) |
| 320 | Q_PROPERTY(qreal width READ width WRITE setWidth FINAL) |
| 321 | Q_PROPERTY(qreal height READ height WRITE setHeight FINAL) |
| 322 | Q_PROPERTY(qreal x READ x WRITE setX FINAL) |
| 323 | Q_PROPERTY(qreal y READ y WRITE setY FINAL) |
| 324 | Q_PROPERTY(qreal implicitWidth READ implicitWidth REVISION(2, 15) FINAL) |
| 325 | Q_PROPERTY(bool isLast READ isLast REVISION(2, 15) FINAL) |
| 326 | QML_ANONYMOUS |
| 327 | QML_ADDED_IN_VERSION(2, 0) |
| 328 | |
| 329 | public: |
| 330 | QQuickTextLine(); |
| 331 | |
| 332 | void setLine(QTextLine* line); |
| 333 | void setLineOffset(int offset); |
| 334 | void setFullLayoutTextLength(int length); |
| 335 | int number() const; |
| 336 | qreal implicitWidth() const; |
| 337 | bool isLast() const; |
| 338 | |
| 339 | qreal width() const; |
| 340 | void setWidth(qreal width); |
| 341 | |
| 342 | qreal height() const; |
| 343 | void setHeight(qreal height); |
| 344 | |
| 345 | qreal x() const; |
| 346 | void setX(qreal x); |
| 347 | |
| 348 | qreal y() const; |
| 349 | void setY(qreal y); |
| 350 | |
| 351 | private: |
| 352 | QTextLine *m_line; |
| 353 | qreal m_height; |
| 354 | int m_lineOffset; |
| 355 | int m_fullLayoutTextLength; |
| 356 | }; |
| 357 | |
| 358 | QT_END_NAMESPACE |
| 359 | |
| 360 | #endif // QQUICKTEXT_P_H |
| 361 | |