Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktextedit_p_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKTEXTEDIT_P_P_H
6#define QQUICKTEXTEDIT_P_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
22
23#include <QtQuick/private/qquicktextselection_p.h>
24
25#include <QtQml/qqml.h>
26#include <QtCore/qlist.h>
27#include <private/qlazilyallocated_p.h>
28#include <private/qquicktextdocument_p.h>
29
30#if QT_CONFIG(accessibility)
31#include <QtGui/qaccessible.h>
32#endif
33
34#include <limits>
35
36QT_BEGIN_NAMESPACE
37class QTextLayout;
38class QQuickPixmap;
39class QQuickTextControl;
40class QSGInternalTextNode;
42
43class Q_QUICK_EXPORT QQuickTextEditPrivate : public QQuickImplicitSizeItemPrivate
44#if QT_CONFIG(accessibility)
45 , public QAccessible::ActivationObserver
46#endif
47{
48public:
49 Q_DECLARE_PUBLIC(QQuickTextEdit)
50
51 typedef QQuickTextEdit Public;
52
53 struct Node {
54 explicit Node(int startPos = std::numeric_limits<int>::max(),
55 QSGInternalTextNode *node = nullptr)
56 : m_node(node), m_startPos(startPos) { }
57 QSGInternalTextNode *textNode() const { return m_node; }
58 void moveStartPos(int delta) { Q_ASSERT(m_startPos + delta > 0); m_startPos += delta; }
59 int startPos() const { return m_startPos; }
60 void setDirty() { m_dirty = true; }
61 bool dirty() const { return m_dirty; }
62
63 private:
64 QSGInternalTextNode *m_node;
65 int m_startPos;
66 bool m_dirty = false;
67
68#ifndef QT_NO_DEBUG_STREAM
69 friend QDebug Q_QUICK_EXPORT operator<<(QDebug, const Node &);
70#endif
71 };
72 typedef QList<Node>::iterator TextNodeIterator;
73
74 struct ExtraData {
75 ExtraData();
76
77 qreal padding = 0;
78 qreal topPadding = 0;
79 qreal leftPadding = 0;
80 qreal rightPadding = 0;
81 qreal bottomPadding = 0;
82 bool explicitTopPadding : 1;
83 bool explicitLeftPadding : 1;
84 bool explicitRightPadding : 1;
85 bool explicitBottomPadding : 1;
86 bool implicitResize : 1;
87 };
88 QLazilyAllocated<ExtraData> extra;
89
90
91 QQuickTextEditPrivate()
92 : dirty(false), richText(false), cursorVisible(false), cursorPending(false)
93 , focusOnPress(true), persistentSelection(false), requireImplicitWidth(false)
94 , selectByMouse(true), canPaste(false), canPasteValid(false), hAlignImplicit(true)
95 , textCached(true), inLayout(false), selectByKeyboard(false), selectByKeyboardSet(false)
96 , hadSelection(false), markdownText(false), inResize(false), ownsDocument(false)
97 , containsUnscalableGlyphs(false)
98 {
99#if QT_CONFIG(accessibility)
100 QAccessible::installActivationObserver(this);
101#endif
102 }
103
104 ~QQuickTextEditPrivate()
105 {
106#if QT_CONFIG(accessibility)
107 QAccessible::removeActivationObserver(this);
108#endif
109 }
110
111 static QQuickTextEditPrivate *get(QQuickTextEdit *item) {
112 return static_cast<QQuickTextEditPrivate *>(QObjectPrivate::get(item)); }
113
114 void init();
115
116 void resetInputMethod();
117 void updateDefaultTextOption();
118 void onDocumentStatusChanged();
119 void relayoutDocument();
120 bool determineHorizontalAlignment();
121 bool setHAlign(QQuickTextEdit::HAlignment, bool forceAlign = false);
122 void mirrorChange() override;
123 bool transformChanged(QQuickItem *transformedItem) override;
124 qreal getImplicitWidth() const override;
125 Qt::LayoutDirection textDirection(const QString &text) const;
126 bool isLinkHoveredConnected();
127 bool isHoveredToolTipChangedConnected();
128 bool isHoveredSignalConnected();
129
130#if QT_CONFIG(cursor)
131 void updateMouseCursorShape();
132#endif
133
134 void setNativeCursorEnabled(bool) {}
135#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
136 bool handleContextMenuEvent(QContextMenuEvent *event) override;
137#endif
138 void handleFocusEvent(QFocusEvent *event);
139 void addCurrentTextNodeToRoot(QQuickTextNodeEngine *, QSGTransformNode *, QSGInternalTextNode *, TextNodeIterator&, int startPos);
140 QSGInternalTextNode* createTextNode();
141
142#if QT_CONFIG(im)
143 Qt::InputMethodHints effectiveInputMethodHints() const;
144#endif
145
146#if QT_CONFIG(accessibility)
147 void accessibilityActiveChanged(bool active) override;
148 QAccessible::Role accessibleRole() const override;
149#endif
150
151 inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; }
152 void setTopPadding(qreal value, bool reset = false);
153 void setLeftPadding(qreal value, bool reset = false);
154 void setRightPadding(qreal value, bool reset = false);
155 void setBottomPadding(qreal value, bool reset = false);
156
157 bool isImplicitResizeEnabled() const;
158 void setImplicitResizeEnabled(bool enabled);
159
160 QColor color = QRgb(0xFF000000);
161 QColor selectionColor = QRgb(0xFF000080);
162 QColor selectedTextColor = QRgb(0xFFFFFFFF);
163
164 QSizeF contentSize;
165
166 qreal textMargin = 0;
167 qreal xoff = 0;
168 qreal yoff = 0;
169
170 QString text;
171 QUrl baseUrl;
172 QFont sourceFont;
173 QFont font;
174
175 QQmlComponent* cursorComponent = nullptr;
176 QQuickItem* cursorItem = nullptr;
177 QTextDocument *document = nullptr;
178 QQuickTextControl *control = nullptr;
179 QQuickTextDocument *quickDocument = nullptr;
180 mutable QQuickTextSelection *cursorSelection = nullptr;
181 QList<Node> textNodeMap;
182 QList<QQuickPixmap *> pixmapsInProgress;
183
184 int lastSelectionStart = 0;
185 int lastSelectionEnd = 0;
186 int lineCount = 0;
187 int firstBlockInViewport = -1; // can be wrong after scrolling sometimes
188 int firstBlockPastViewport = -1; // only for the autotest
189 int renderedBlockCount = -1; // only for the autotest
190 QRectF renderedRegion;
191
192 enum UpdateType {
193 UpdateNone,
194 UpdateOnlyPreprocess,
195 UpdatePaintNode,
196 UpdateAll
197 };
198
199 QQuickTextEdit::HAlignment hAlign = QQuickTextEdit::AlignLeft;
200 QQuickTextEdit::VAlignment vAlign = QQuickTextEdit::AlignTop;
201 QQuickTextEdit::TextFormat format = QQuickTextEdit::PlainText;
202 QQuickTextEdit::WrapMode wrapMode = QQuickTextEdit::NoWrap;
203 QQuickTextEdit::RenderType renderType = QQuickTextUtil::textRenderType<QQuickTextEdit>();
204 Qt::LayoutDirection contentDirection = Qt::LayoutDirectionAuto;
205 QQuickTextEdit::SelectionMode mouseSelectionMode = QQuickTextEdit::SelectCharacters;
206#if QT_CONFIG(im)
207 Qt::InputMethodHints inputMethodHints = Qt::ImhNone;
208#endif
209 UpdateType updateType = UpdatePaintNode;
210
211 bool dirty : 1;
212 bool richText : 1;
213 bool cursorVisible : 1;
214 bool cursorPending : 1;
215 bool focusOnPress : 1;
216 bool persistentSelection : 1;
217 bool requireImplicitWidth:1;
218 bool selectByMouse:1;
219 bool canPaste:1;
220 bool canPasteValid:1;
221 bool hAlignImplicit:1;
222 bool textCached:1;
223 bool inLayout:1;
224 bool selectByKeyboard:1;
225 bool selectByKeyboardSet:1;
226 bool hadSelection : 1;
227 bool markdownText : 1;
228 bool inResize : 1;
229 bool ownsDocument : 1;
230 bool containsUnscalableGlyphs : 1;
231
232 static const int largeTextSizeThreshold;
233};
234
235#ifndef QT_NO_DEBUG_STREAM
236QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickTextEditPrivate::Node &);
237#endif
238
239QT_END_NAMESPACE
240
241#endif // QQUICKTEXTEDIT_P_P_H
void setTextColor(const QColor &textColor)
void setSelectionColor(const QColor &selectionColor)
void setSelectedTextColor(const QColor &selectedTextColor)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define QQUICKTEXT_LARGETEXT_THRESHOLD
static bool operator<(const TextNode &n1, const TextNode &n2)
void resetEngine(QQuickTextNodeEngine *engine, const QColor &textColor, const QColor &selectedTextColor, const QColor &selectionColor, qreal dpr)
static const int nodeBreakingSize
\qmlsignal QtQuick::TextEdit::linkActivated(string link)
static void updateNodeTransform(QSGInternalTextNode *node, const QPointF &topLeft)
QQuickTextEditPrivate::Node TextNode
QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item)