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

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