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