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 QQUICKTEXTEDIT_P_H
41#define QQUICKTEXTEDIT_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 "qquickimplicitsizeitem_p.h"
55
56#include <QtGui/qtextoption.h>
57
58QT_BEGIN_NAMESPACE
59
60class QQuickTextDocument;
61class QQuickTextEditPrivate;
62class QTextBlock;
63
64class Q_QUICK_PRIVATE_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
65{
66 Q_OBJECT
67
68 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
69 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
70 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
71 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
72 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
73 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
74 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
75 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
76 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
77 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
78 Q_PROPERTY(int length READ length NOTIFY textChanged)
79 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
80 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
81 Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentSizeChanged) // Compatibility
82 Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentSizeChanged)
83 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
84 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
85 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
86 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
87 Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
88 Q_PROPERTY(QQmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
89 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged)
90 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
91 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
92 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
93 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
94 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
95 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
96 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
97 Q_PROPERTY(bool selectByKeyboard READ selectByKeyboard WRITE setSelectByKeyboard NOTIFY selectByKeyboardChanged REVISION 1)
98 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
99 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
100 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
101 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
102 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
103 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
104 Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged)
105 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
106 Q_PROPERTY(QQuickTextDocument *textDocument READ textDocument CONSTANT FINAL REVISION 1)
107 Q_PROPERTY(QString hoveredLink READ hoveredLink NOTIFY linkHovered REVISION 2)
108 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION 6)
109 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION 6)
110 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION 6)
111 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION 6)
112 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION 6)
113 Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION 7)
114 Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance NOTIFY tabStopDistanceChanged REVISION 10)
115 QML_NAMED_ELEMENT(TextEdit)
116
117public:
118 QQuickTextEdit(QQuickItem *parent=nullptr);
119
120 enum HAlignment {
121 AlignLeft = Qt::AlignLeft,
122 AlignRight = Qt::AlignRight,
123 AlignHCenter = Qt::AlignHCenter,
124 AlignJustify = Qt::AlignJustify
125 };
126 Q_ENUM(HAlignment)
127
128 enum VAlignment {
129 AlignTop = Qt::AlignTop,
130 AlignBottom = Qt::AlignBottom,
131 AlignVCenter = Qt::AlignVCenter
132 };
133 Q_ENUM(VAlignment)
134
135 enum TextFormat {
136 PlainText = Qt::PlainText,
137 RichText = Qt::RichText,
138 AutoText = Qt::AutoText,
139 MarkdownText = Qt::MarkdownText
140 };
141 Q_ENUM(TextFormat)
142
143 enum WrapMode { NoWrap = QTextOption::NoWrap,
144 WordWrap = QTextOption::WordWrap,
145 WrapAnywhere = QTextOption::WrapAnywhere,
146 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
147 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
148 };
149 Q_ENUM(WrapMode)
150
151 enum SelectionMode {
152 SelectCharacters,
153 SelectWords
154 };
155 Q_ENUM(SelectionMode)
156
157 enum RenderType { QtRendering,
158 NativeRendering
159 };
160 Q_ENUM(RenderType)
161
162 QString text() const;
163 void setText(const QString &);
164
165 Q_REVISION(7) QString preeditText() const;
166
167 TextFormat textFormat() const;
168 void setTextFormat(TextFormat format);
169
170 QFont font() const;
171 void setFont(const QFont &font);
172
173 QColor color() const;
174 void setColor(const QColor &c);
175
176 QColor selectionColor() const;
177 void setSelectionColor(const QColor &c);
178
179 QColor selectedTextColor() const;
180 void setSelectedTextColor(const QColor &c);
181
182 HAlignment hAlign() const;
183 void setHAlign(HAlignment align);
184 void resetHAlign();
185 HAlignment effectiveHAlign() const;
186
187 VAlignment vAlign() const;
188 void setVAlign(VAlignment align);
189
190 WrapMode wrapMode() const;
191 void setWrapMode(WrapMode w);
192
193 int lineCount() const;
194
195 int length() const;
196
197 bool isCursorVisible() const;
198 void setCursorVisible(bool on);
199
200 int cursorPosition() const;
201 void setCursorPosition(int pos);
202
203 QQmlComponent* cursorDelegate() const;
204 void setCursorDelegate(QQmlComponent*);
205
206 bool overwriteMode() const;
207 void setOverwriteMode(bool overwrite);
208
209 int selectionStart() const;
210 int selectionEnd() const;
211
212 QString selectedText() const;
213
214 bool focusOnPress() const;
215 void setFocusOnPress(bool on);
216
217 bool persistentSelection() const;
218 void setPersistentSelection(bool on);
219
220 qreal textMargin() const;
221 void setTextMargin(qreal margin);
222
223 Qt::InputMethodHints inputMethodHints() const;
224 void setInputMethodHints(Qt::InputMethodHints hints);
225
226 bool selectByKeyboard() const;
227 void setSelectByKeyboard(bool);
228
229 bool selectByMouse() const;
230 void setSelectByMouse(bool);
231
232 SelectionMode mouseSelectionMode() const;
233 void setMouseSelectionMode(SelectionMode mode);
234
235 bool canPaste() const;
236
237 bool canUndo() const;
238 bool canRedo() const;
239
240 void componentComplete() override;
241
242 /* FROM EDIT */
243 void setReadOnly(bool);
244 bool isReadOnly() const;
245
246 QRectF cursorRectangle() const;
247
248#if QT_CONFIG(im)
249 QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
250 Q_REVISION(4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const;
251#endif
252
253 qreal contentWidth() const;
254 qreal contentHeight() const;
255
256 QUrl baseUrl() const;
257 void setBaseUrl(const QUrl &url);
258 void resetBaseUrl();
259
260 Q_INVOKABLE QRectF positionToRectangle(int) const;
261 Q_INVOKABLE int positionAt(qreal x, qreal y) const;
262 Q_INVOKABLE void moveCursorSelection(int pos);
263 Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
264
265 QRectF boundingRect() const override;
266 QRectF clipRect() const override;
267
268 bool isInputMethodComposing() const;
269
270 RenderType renderType() const;
271 void setRenderType(RenderType renderType);
272
273 Q_INVOKABLE QString getText(int start, int end) const;
274 Q_INVOKABLE QString getFormattedText(int start, int end) const;
275
276 QQuickTextDocument *textDocument();
277
278 QString hoveredLink() const;
279
280 Q_REVISION(3) Q_INVOKABLE QString linkAt(qreal x, qreal y) const;
281
282 qreal padding() const;
283 void setPadding(qreal padding);
284 void resetPadding();
285
286 qreal topPadding() const;
287 void setTopPadding(qreal padding);
288 void resetTopPadding();
289
290 qreal leftPadding() const;
291 void setLeftPadding(qreal padding);
292 void resetLeftPadding();
293
294 qreal rightPadding() const;
295 void setRightPadding(qreal padding);
296 void resetRightPadding();
297
298 qreal bottomPadding() const;
299 void setBottomPadding(qreal padding);
300 void resetBottomPadding();
301
302 int tabStopDistance() const;
303 void setTabStopDistance(qreal distance);
304
305Q_SIGNALS:
306 void textChanged();
307 Q_REVISION(7) void preeditTextChanged();
308 void contentSizeChanged();
309 void cursorPositionChanged();
310 void cursorRectangleChanged();
311 void selectionStartChanged();
312 void selectionEndChanged();
313 void selectedTextChanged();
314 void colorChanged(const QColor &color);
315 void selectionColorChanged(const QColor &color);
316 void selectedTextColorChanged(const QColor &color);
317 void fontChanged(const QFont &font);
318 void horizontalAlignmentChanged(QQuickTextEdit::HAlignment alignment);
319 void verticalAlignmentChanged(QQuickTextEdit::VAlignment alignment);
320 void wrapModeChanged();
321 void lineCountChanged();
322 void textFormatChanged(QQuickTextEdit::TextFormat textFormat);
323 void readOnlyChanged(bool isReadOnly);
324 void cursorVisibleChanged(bool isCursorVisible);
325 void cursorDelegateChanged();
326 void overwriteModeChanged(bool overwriteMode);
327 void activeFocusOnPressChanged(bool activeFocusOnPressed);
328 void persistentSelectionChanged(bool isPersistentSelection);
329 void textMarginChanged(qreal textMargin);
330 Q_REVISION(1) void selectByKeyboardChanged(bool selectByKeyboard);
331 void selectByMouseChanged(bool selectByMouse);
332 void mouseSelectionModeChanged(QQuickTextEdit::SelectionMode mode);
333 void linkActivated(const QString &link);
334 Q_REVISION(2) void linkHovered(const QString &link);
335 void canPasteChanged();
336 void canUndoChanged();
337 void canRedoChanged();
338 void inputMethodComposingChanged();
339 void effectiveHorizontalAlignmentChanged();
340 void baseUrlChanged();
341 void inputMethodHintsChanged();
342 void renderTypeChanged();
343 Q_REVISION(6) void editingFinished();
344 Q_REVISION(6) void paddingChanged();
345 Q_REVISION(6) void topPaddingChanged();
346 Q_REVISION(6) void leftPaddingChanged();
347 Q_REVISION(6) void rightPaddingChanged();
348 Q_REVISION(6) void bottomPaddingChanged();
349 Q_REVISION(10) void tabStopDistanceChanged(qreal distance);
350
351public Q_SLOTS:
352 void selectAll();
353 void selectWord();
354 void select(int start, int end);
355 void deselect();
356 bool isRightToLeft(int start, int end);
357#if QT_CONFIG(clipboard)
358 void cut();
359 void copy();
360 void paste();
361#endif
362 void undo();
363 void redo();
364 void insert(int position, const QString &text);
365 void remove(int start, int end);
366 Q_REVISION(2) void append(const QString &text);
367 Q_REVISION(7) void clear();
368
369private Q_SLOTS:
370 void q_textChanged();
371 void q_contentsChange(int, int, int);
372 void updateSelection();
373 void moveCursorDelegate();
374 void createCursor();
375 void q_canPasteChanged();
376 void updateWholeDocument();
377 void invalidateBlock(const QTextBlock &block);
378 void updateCursor();
379 void q_linkHovered(const QString &link);
380 void q_markerHovered(bool hovered);
381 void q_updateAlignment();
382 void updateSize();
383 void triggerPreprocess();
384
385private:
386 void markDirtyNodesForRange(int start, int end, int charDelta);
387 void updateTotalLines();
388 void invalidateFontCaches();
389
390protected:
391 QQuickTextEdit(QQuickTextEditPrivate &dd, QQuickItem *parent = nullptr);
392
393 void geometryChanged(const QRectF &newGeometry,
394 const QRectF &oldGeometry) override;
395
396 bool event(QEvent *) override;
397 void keyPressEvent(QKeyEvent *) override;
398 void keyReleaseEvent(QKeyEvent *) override;
399 void focusInEvent(QFocusEvent *event) override;
400 void focusOutEvent(QFocusEvent *event) override;
401
402 void hoverEnterEvent(QHoverEvent *event) override;
403 void hoverMoveEvent(QHoverEvent *event) override;
404 void hoverLeaveEvent(QHoverEvent *event) override;
405
406 // mouse filter?
407 void mousePressEvent(QMouseEvent *event) override;
408 void mouseReleaseEvent(QMouseEvent *event) override;
409 void mouseDoubleClickEvent(QMouseEvent *event) override;
410 void mouseMoveEvent(QMouseEvent *event) override;
411#if QT_CONFIG(im)
412 void inputMethodEvent(QInputMethodEvent *e) override;
413#endif
414 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
415 void updatePolish() override;
416
417 friend class QQuickTextUtil;
418 friend class QQuickTextDocument;
419
420private:
421 Q_DISABLE_COPY(QQuickTextEdit)
422 Q_DECLARE_PRIVATE(QQuickTextEdit)
423};
424
425QT_END_NAMESPACE
426
427QML_DECLARE_TYPE(QQuickTextEdit)
428
429#endif // QQUICKTEXTEDIT_P_H
430

source code of qtdeclarative/src/quick/items/qquicktextedit_p.h