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 QQUICKTEXTCONTROL_P_H |
5 | #define QQUICKTEXTCONTROL_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 <QtGui/qtextdocument.h> |
19 | #include <QtGui/qtextoption.h> |
20 | #include <QtGui/qtextcursor.h> |
21 | #include <QtGui/qtextformat.h> |
22 | #include <QtCore/qrect.h> |
23 | #include <QtGui/qabstracttextdocumentlayout.h> |
24 | #include <QtGui/qtextdocumentfragment.h> |
25 | #include <QtGui/qclipboard.h> |
26 | #include <QtGui/private/qinputcontrol_p.h> |
27 | #include <QtCore/qmimedata.h> |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | |
32 | class QStyleSheet; |
33 | class QTextDocument; |
34 | class QQuickTextControlPrivate; |
35 | class QAbstractScrollArea; |
36 | class QEvent; |
37 | class QTimerEvent; |
38 | class QTransform; |
39 | |
40 | class Q_AUTOTEST_EXPORT QQuickTextControl : public QInputControl |
41 | { |
42 | Q_OBJECT |
43 | Q_DECLARE_PRIVATE(QQuickTextControl) |
44 | public: |
45 | explicit QQuickTextControl(QTextDocument *doc, QObject *parent = nullptr); |
46 | virtual ~QQuickTextControl(); |
47 | |
48 | QTextDocument *document() const; |
49 | |
50 | void setTextCursor(const QTextCursor &cursor); |
51 | QTextCursor textCursor() const; |
52 | |
53 | void setTextInteractionFlags(Qt::TextInteractionFlags flags); |
54 | Qt::TextInteractionFlags textInteractionFlags() const; |
55 | |
56 | QString toPlainText() const; |
57 | |
58 | #if QT_CONFIG(texthtmlparser) |
59 | QString toHtml() const; |
60 | #endif |
61 | #if QT_CONFIG(textmarkdownwriter) |
62 | QString toMarkdown() const; |
63 | #endif |
64 | |
65 | bool hasImState() const; |
66 | bool overwriteMode() const; |
67 | void setOverwriteMode(bool overwrite); |
68 | bool cursorVisible() const; |
69 | void setCursorVisible(bool visible); |
70 | QRectF anchorRect() const; |
71 | QRectF cursorRect(const QTextCursor &cursor) const; |
72 | QRectF cursorRect() const; |
73 | QRectF selectionRect(const QTextCursor &cursor) const; |
74 | QRectF selectionRect() const; |
75 | |
76 | QString hoveredLink() const; |
77 | QString anchorAt(const QPointF &pos) const; |
78 | QTextBlock blockWithMarkerAt(const QPointF &pos) const; |
79 | |
80 | void setCursorWidth(int width); |
81 | |
82 | void setAcceptRichText(bool accept); |
83 | |
84 | void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
85 | |
86 | bool canPaste() const; |
87 | |
88 | void setCursorIsFocusIndicator(bool b); |
89 | void setWordSelectionEnabled(bool enabled); |
90 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) |
91 | void setTouchDragSelectionEnabled(bool enabled); |
92 | #endif |
93 | |
94 | void updateCursorRectangle(bool force); |
95 | |
96 | virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const; |
97 | virtual QRectF blockBoundingRect(const QTextBlock &block) const; |
98 | |
99 | QString preeditText() const; |
100 | |
101 | public Q_SLOTS: |
102 | void setPlainText(const QString &text); |
103 | void setMarkdownText(const QString &text); |
104 | void setHtml(const QString &text); |
105 | |
106 | #if QT_CONFIG(clipboard) |
107 | void cut(); |
108 | void copy(); |
109 | void paste(QClipboard::Mode mode = QClipboard::Clipboard); |
110 | #endif |
111 | |
112 | void undo(); |
113 | void redo(); |
114 | void clear(); |
115 | |
116 | void selectAll(); |
117 | |
118 | Q_SIGNALS: |
119 | void textChanged(); |
120 | void preeditTextChanged(); |
121 | void contentsChange(int from, int charsRemoved, int charsAdded); |
122 | void undoAvailable(bool b); |
123 | void redoAvailable(bool b); |
124 | void currentCharFormatChanged(const QTextCharFormat &format); |
125 | void copyAvailable(bool b); |
126 | void selectionChanged(); |
127 | void cursorPositionChanged(); |
128 | void overwriteModeChanged(bool overwriteMode); |
129 | |
130 | // control signals |
131 | void updateCursorRequest(); |
132 | void updateRequest(); |
133 | void cursorRectangleChanged(); |
134 | void linkActivated(const QString &link); |
135 | void linkHovered(const QString &link); |
136 | void markerClicked(); |
137 | void markerHovered(bool marker); |
138 | |
139 | public: |
140 | virtual void processEvent(QEvent *e, const QTransform &transform); |
141 | void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF()); |
142 | |
143 | #if QT_CONFIG(im) |
144 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const; |
145 | Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const; |
146 | #endif |
147 | |
148 | virtual QMimeData *createMimeDataFromSelection() const; |
149 | virtual bool canInsertFromMimeData(const QMimeData *source) const; |
150 | virtual void insertFromMimeData(const QMimeData *source); |
151 | |
152 | bool cursorOn() const; |
153 | |
154 | protected: |
155 | void timerEvent(QTimerEvent *e) override; |
156 | |
157 | bool event(QEvent *e) override; |
158 | |
159 | private: |
160 | Q_DISABLE_COPY(QQuickTextControl) |
161 | Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection()) |
162 | Q_PRIVATE_SLOT(d_func(), void _q_updateCursorPosChanged(const QTextCursor &)) |
163 | }; |
164 | |
165 | |
166 | // also used by QLabel |
167 | class QQuickTextEditMimeData : public QMimeData |
168 | { |
169 | public: |
170 | inline QQuickTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {} |
171 | |
172 | QStringList formats() const override; |
173 | |
174 | protected: |
175 | QVariant retrieveData(const QString &mimeType, QMetaType type) const override; |
176 | |
177 | private: |
178 | void setup() const; |
179 | |
180 | mutable QTextDocumentFragment fragment; |
181 | }; |
182 | |
183 | QT_END_NAMESPACE |
184 | |
185 | #endif // QQuickTextControl_H |
186 | |