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
128#if QT_CONFIG(cursor)
129 void updateMouseCursorShape();
130#endif
131
132 void setNativeCursorEnabled(bool) {}
133#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
134 bool handleContextMenuEvent(QContextMenuEvent *event) override;
135#endif
136 void handleFocusEvent(QFocusEvent *event);
137 void addCurrentTextNodeToRoot(QQuickTextNodeEngine *, QSGTransformNode *, QSGInternalTextNode *, TextNodeIterator&, int startPos);
138 QSGInternalTextNode* createTextNode();
139
140#if QT_CONFIG(im)
141 Qt::InputMethodHints effectiveInputMethodHints() const;
142#endif
143
144#if QT_CONFIG(accessibility)
145 void accessibilityActiveChanged(bool active) override;
146 QAccessible::Role accessibleRole() const override;
147#endif
148
149 inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; }
150 void setTopPadding(qreal value, bool reset = false);
151 void setLeftPadding(qreal value, bool reset = false);
152 void setRightPadding(qreal value, bool reset = false);
153 void setBottomPadding(qreal value, bool reset = false);
154
155 bool isImplicitResizeEnabled() const;
156 void setImplicitResizeEnabled(bool enabled);
157
158 QColor color = QRgb(0xFF000000);
159 QColor selectionColor = QRgb(0xFF000080);
160 QColor selectedTextColor = QRgb(0xFFFFFFFF);
161
162 QSizeF contentSize;
163
164 qreal textMargin = 0;
165 qreal xoff = 0;
166 qreal yoff = 0;
167
168 QString text;
169 QUrl baseUrl;
170 QFont sourceFont;
171 QFont font;
172
173 QQmlComponent* cursorComponent = nullptr;
174 QQuickItem* cursorItem = nullptr;
175 QTextDocument *document = nullptr;
176 QQuickTextControl *control = nullptr;
177 QQuickTextDocument *quickDocument = nullptr;
178 mutable QQuickTextSelection *cursorSelection = nullptr;
179 QList<Node> textNodeMap;
180 QList<QQuickPixmap *> pixmapsInProgress;
181
182 int lastSelectionStart = 0;
183 int lastSelectionEnd = 0;
184 int lineCount = 0;
185 int firstBlockInViewport = -1; // can be wrong after scrolling sometimes
186 int firstBlockPastViewport = -1; // only for the autotest
187 int renderedBlockCount = -1; // only for the autotest
188 QRectF renderedRegion;
189
190 enum UpdateType {
191 UpdateNone,
192 UpdateOnlyPreprocess,
193 UpdatePaintNode,
194 UpdateAll
195 };
196
197 QQuickTextEdit::HAlignment hAlign = QQuickTextEdit::AlignLeft;
198 QQuickTextEdit::VAlignment vAlign = QQuickTextEdit::AlignTop;
199 QQuickTextEdit::TextFormat format = QQuickTextEdit::PlainText;
200 QQuickTextEdit::WrapMode wrapMode = QQuickTextEdit::NoWrap;
201 QQuickTextEdit::RenderType renderType = QQuickTextUtil::textRenderType<QQuickTextEdit>();
202 Qt::LayoutDirection contentDirection = Qt::LayoutDirectionAuto;
203 QQuickTextEdit::SelectionMode mouseSelectionMode = QQuickTextEdit::SelectCharacters;
204#if QT_CONFIG(im)
205 Qt::InputMethodHints inputMethodHints = Qt::ImhNone;
206#endif
207 UpdateType updateType = UpdatePaintNode;
208
209 bool dirty : 1;
210 bool richText : 1;
211 bool cursorVisible : 1;
212 bool cursorPending : 1;
213 bool focusOnPress : 1;
214 bool persistentSelection : 1;
215 bool requireImplicitWidth:1;
216 bool selectByMouse:1;
217 bool canPaste:1;
218 bool canPasteValid:1;
219 bool hAlignImplicit:1;
220 bool textCached:1;
221 bool inLayout:1;
222 bool selectByKeyboard:1;
223 bool selectByKeyboardSet:1;
224 bool hadSelection : 1;
225 bool markdownText : 1;
226 bool inResize : 1;
227 bool ownsDocument : 1;
228 bool containsUnscalableGlyphs : 1;
229
230 static const int largeTextSizeThreshold;
231};
232
233#ifndef QT_NO_DEBUG_STREAM
234QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickTextEditPrivate::Node &);
235#endif
236
237QT_END_NAMESPACE
238
239#endif // QQUICKTEXTEDIT_P_P_H
void setTextColor(const QColor &textColor)
void setSelectionColor(const QColor &selectionColor)
void setSelectedTextColor(const QColor &selectedTextColor)
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
#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)