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