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