| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QVIRTUALKEYBOARDINPUTCONTEXT_H |
| 5 | #define QVIRTUALKEYBOARDINPUTCONTEXT_H |
| 6 | |
| 7 | #include <QtCore/QObject> |
| 8 | #include <QtCore/QRectF> |
| 9 | #include <QtCore/QLocale> |
| 10 | #include <QtGui/QInputMethodEvent> |
| 11 | #include <QtGui/QInputMethod> |
| 12 | #include <QtQml/qqml.h> |
| 13 | #include <QtVirtualKeyboard/qvirtualkeyboard_global.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | namespace QtVirtualKeyboard { |
| 18 | class PlatformInputContext; |
| 19 | } |
| 20 | class QVirtualKeyboardInputEngine; |
| 21 | class QVirtualKeyboardInputContextPrivate; |
| 22 | class QVirtualKeyboardObserver; |
| 23 | |
| 24 | class Q_VIRTUALKEYBOARD_EXPORT QVirtualKeyboardInputContext : public QObject |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | Q_DISABLE_COPY(QVirtualKeyboardInputContext) |
| 28 | Q_DECLARE_PRIVATE(QVirtualKeyboardInputContext) |
| 29 | Q_PROPERTY(bool shift READ isShiftActive NOTIFY shiftActiveChanged) |
| 30 | Q_PROPERTY(bool shiftActive READ isShiftActive NOTIFY shiftActiveChanged REVISION(2, 4)) |
| 31 | Q_PROPERTY(bool capsLock READ isCapsLockActive NOTIFY capsLockActiveChanged) |
| 32 | Q_PROPERTY(bool capsLockActive READ isCapsLockActive NOTIFY capsLockActiveChanged REVISION(2, 4)) |
| 33 | Q_PROPERTY(bool uppercase READ isUppercase NOTIFY uppercaseChanged) |
| 34 | Q_PROPERTY(int anchorPosition READ anchorPosition NOTIFY anchorPositionChanged) |
| 35 | Q_PROPERTY(int cursorPosition READ cursorPosition NOTIFY cursorPositionChanged) |
| 36 | Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints NOTIFY inputMethodHintsChanged) |
| 37 | Q_PROPERTY(QString preeditText READ preeditText WRITE setPreeditText NOTIFY preeditTextChanged) |
| 38 | Q_PROPERTY(QString surroundingText READ surroundingText NOTIFY surroundingTextChanged) |
| 39 | Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) |
| 40 | Q_PROPERTY(QRectF anchorRectangle READ anchorRectangle NOTIFY anchorRectangleChanged) |
| 41 | Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) |
| 42 | Q_PROPERTY(bool animating READ isAnimating WRITE setAnimating NOTIFY animatingChanged) |
| 43 | Q_PROPERTY(QString locale READ locale NOTIFY localeChanged) |
| 44 | Q_PROPERTY(QObject *inputItem READ inputItem NOTIFY inputItemChanged) |
| 45 | Q_PROPERTY(QVirtualKeyboardInputEngine *inputEngine READ inputEngine CONSTANT) |
| 46 | Q_PROPERTY(bool selectionControlVisible READ isSelectionControlVisible NOTIFY selectionControlVisibleChanged) |
| 47 | Q_PROPERTY(bool anchorRectIntersectsClipRect READ anchorRectIntersectsClipRect NOTIFY anchorRectIntersectsClipRectChanged) |
| 48 | Q_PROPERTY(bool cursorRectIntersectsClipRect READ cursorRectIntersectsClipRect NOTIFY cursorRectIntersectsClipRectChanged) |
| 49 | Q_PROPERTY(QVirtualKeyboardInputContextPrivate *priv READ priv CONSTANT REVISION(2, 0)) |
| 50 | Q_PROPERTY(QVirtualKeyboardObserver *keyboardObserver READ keyboardObserver CONSTANT REVISION(6, 1)) |
| 51 | Q_MOC_INCLUDE("qvirtualkeyboardinputengine.h" ) |
| 52 | Q_MOC_INCLUDE("qvirtualkeyboardinputcontext_p.h" ) |
| 53 | QML_NAMED_ELEMENT(InputContext) |
| 54 | QML_SINGLETON |
| 55 | QML_ADDED_IN_VERSION(1, 0) |
| 56 | QML_EXTRA_VERSION(2, 0) |
| 57 | |
| 58 | public: |
| 59 | explicit QVirtualKeyboardInputContext(QObject *parent = nullptr); |
| 60 | ~QVirtualKeyboardInputContext(); |
| 61 | |
| 62 | bool isShiftActive() const; |
| 63 | bool isCapsLockActive() const; |
| 64 | bool isUppercase() const; |
| 65 | int anchorPosition() const; |
| 66 | int cursorPosition() const; |
| 67 | Qt::InputMethodHints inputMethodHints() const; |
| 68 | QString preeditText() const; |
| 69 | void setPreeditText(const QString &text, QList<QInputMethodEvent::Attribute> attributes = QList<QInputMethodEvent::Attribute>(), int replaceFrom = 0, int replaceLength = 0); |
| 70 | QList<QInputMethodEvent::Attribute> preeditTextAttributes() const; |
| 71 | QString surroundingText() const; |
| 72 | QString selectedText() const; |
| 73 | QRectF anchorRectangle() const; |
| 74 | QRectF cursorRectangle() const; |
| 75 | bool isAnimating() const; |
| 76 | void setAnimating(bool isAnimating); |
| 77 | QString locale() const; |
| 78 | QObject *inputItem() const; |
| 79 | QVirtualKeyboardInputEngine *inputEngine() const; |
| 80 | bool isSelectionControlVisible() const; |
| 81 | bool anchorRectIntersectsClipRect() const; |
| 82 | bool cursorRectIntersectsClipRect() const; |
| 83 | QVirtualKeyboardInputContextPrivate *priv() const; |
| 84 | QVirtualKeyboardObserver *keyboardObserver() const; |
| 85 | |
| 86 | Q_INVOKABLE void sendKeyClick(int key, const QString &text, int modifiers = 0); |
| 87 | Q_INVOKABLE void commit(); |
| 88 | Q_INVOKABLE void commit(const QString &text, int replaceFrom = 0, int replaceLength = 0); |
| 89 | Q_INVOKABLE void clear(); |
| 90 | |
| 91 | // For selection handles |
| 92 | Q_INVOKABLE void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos); |
| 93 | |
| 94 | Q_SIGNALS: |
| 95 | void preeditTextChanged(); |
| 96 | void inputMethodHintsChanged(); |
| 97 | void surroundingTextChanged(); |
| 98 | void selectedTextChanged(); |
| 99 | void anchorPositionChanged(); |
| 100 | void cursorPositionChanged(); |
| 101 | void anchorRectangleChanged(); |
| 102 | void cursorRectangleChanged(); |
| 103 | void shiftActiveChanged(); |
| 104 | void capsLockActiveChanged(); |
| 105 | void uppercaseChanged(); |
| 106 | void animatingChanged(); |
| 107 | void localeChanged(); |
| 108 | void inputItemChanged(); |
| 109 | void selectionControlVisibleChanged(); |
| 110 | void anchorRectIntersectsClipRectChanged(); |
| 111 | void cursorRectIntersectsClipRectChanged(); |
| 112 | |
| 113 | private: |
| 114 | |
| 115 | QScopedPointer<QVirtualKeyboardInputContextPrivate> d_ptr; |
| 116 | }; |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #endif |
| 121 | |