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 4) |
31 | Q_PROPERTY(bool capsLock READ isCapsLockActive NOTIFY capsLockActiveChanged) |
32 | Q_PROPERTY(bool capsLockActive READ isCapsLockActive NOTIFY capsLockActiveChanged REVISION 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) |
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 | |
54 | // The QML macros are unused for now, until we can move the QML_NAMED_ELEMENT back here. |
55 | // QML_SINGLETON generates some code that might or might not emit symbols on some platforms. |
56 | QML_SINGLETON |
57 | QML_ADDED_IN_VERSION(1, 0) |
58 | QML_EXTRA_VERSION(2, 0) |
59 | |
60 | public: |
61 | explicit QVirtualKeyboardInputContext(QObject *parent = nullptr); |
62 | ~QVirtualKeyboardInputContext(); |
63 | |
64 | bool isShiftActive() const; |
65 | bool isCapsLockActive() const; |
66 | bool isUppercase() const; |
67 | int anchorPosition() const; |
68 | int cursorPosition() const; |
69 | Qt::InputMethodHints inputMethodHints() const; |
70 | QString preeditText() const; |
71 | void setPreeditText(const QString &text, QList<QInputMethodEvent::Attribute> attributes = QList<QInputMethodEvent::Attribute>(), int replaceFrom = 0, int replaceLength = 0); |
72 | QList<QInputMethodEvent::Attribute> preeditTextAttributes() const; |
73 | QString surroundingText() const; |
74 | QString selectedText() const; |
75 | QRectF anchorRectangle() const; |
76 | QRectF cursorRectangle() const; |
77 | bool isAnimating() const; |
78 | void setAnimating(bool isAnimating); |
79 | QString locale() const; |
80 | QObject *inputItem() const; |
81 | QVirtualKeyboardInputEngine *inputEngine() const; |
82 | bool isSelectionControlVisible() const; |
83 | bool anchorRectIntersectsClipRect() const; |
84 | bool cursorRectIntersectsClipRect() const; |
85 | QVirtualKeyboardInputContextPrivate *priv() const; |
86 | QVirtualKeyboardObserver *keyboardObserver() const; |
87 | |
88 | Q_INVOKABLE void sendKeyClick(int key, const QString &text, int modifiers = 0); |
89 | Q_INVOKABLE void commit(); |
90 | Q_INVOKABLE void commit(const QString &text, int replaceFrom = 0, int replaceLength = 0); |
91 | Q_INVOKABLE void clear(); |
92 | |
93 | // For selection handles |
94 | Q_INVOKABLE void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos); |
95 | |
96 | Q_SIGNALS: |
97 | void preeditTextChanged(); |
98 | void inputMethodHintsChanged(); |
99 | void surroundingTextChanged(); |
100 | void selectedTextChanged(); |
101 | void anchorPositionChanged(); |
102 | void cursorPositionChanged(); |
103 | void anchorRectangleChanged(); |
104 | void cursorRectangleChanged(); |
105 | void shiftActiveChanged(); |
106 | void capsLockActiveChanged(); |
107 | void uppercaseChanged(); |
108 | void animatingChanged(); |
109 | void localeChanged(); |
110 | void inputItemChanged(); |
111 | void selectionControlVisibleChanged(); |
112 | void anchorRectIntersectsClipRectChanged(); |
113 | void cursorRectIntersectsClipRectChanged(); |
114 | |
115 | private: |
116 | |
117 | QScopedPointer<QVirtualKeyboardInputContextPrivate> d_ptr; |
118 | }; |
119 | |
120 | QT_END_NAMESPACE |
121 | |
122 | #endif |
123 | |