1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QVIRTUALKEYBOARDINPUTENGINE_H
5#define QVIRTUALKEYBOARDINPUTENGINE_H
6
7#include <QtCore/QObject>
8#include <QtCore/QPointer>
9#include <QtQml/qqml.h>
10#include <QtVirtualKeyboard/qvirtualkeyboard_global.h>
11
12QT_BEGIN_NAMESPACE
13
14class QVirtualKeyboardInputContext;
15class QVirtualKeyboardSelectionListModel;
16class QVirtualKeyboardAbstractInputMethod;
17class QVirtualKeyboardInputEnginePrivate;
18class QVirtualKeyboardTrace;
19
20class Q_VIRTUALKEYBOARD_EXPORT QVirtualKeyboardInputEngine : public QObject
21{
22 Q_OBJECT
23 Q_DISABLE_COPY(QVirtualKeyboardInputEngine)
24 Q_DECLARE_PRIVATE(QVirtualKeyboardInputEngine)
25 Q_PROPERTY(Qt::Key activeKey READ activeKey NOTIFY activeKeyChanged)
26 Q_PROPERTY(Qt::Key previousKey READ previousKey NOTIFY previousKeyChanged)
27 Q_PROPERTY(QVirtualKeyboardAbstractInputMethod *inputMethod READ inputMethod WRITE setInputMethod NOTIFY inputMethodChanged)
28 Q_PROPERTY(QList<int> inputModes READ inputModes NOTIFY inputModesChanged)
29 Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode NOTIFY inputModeChanged)
30 Q_PROPERTY(QList<int> patternRecognitionModes READ patternRecognitionModes NOTIFY patternRecognitionModesChanged)
31 Q_PROPERTY(QVirtualKeyboardSelectionListModel *wordCandidateListModel READ wordCandidateListModel NOTIFY wordCandidateListModelChanged)
32 Q_PROPERTY(bool wordCandidateListVisibleHint READ wordCandidateListVisibleHint NOTIFY wordCandidateListVisibleHintChanged)
33 Q_MOC_INCLUDE("qvirtualkeyboardabstractinputmethod.h")
34 QML_NAMED_ELEMENT(InputEngine)
35 QML_UNCREATABLE("InputEngine is only available via InputContext.inputEngine")
36 QML_ADDED_IN_VERSION(1, 0)
37 QML_EXTRA_VERSION(2, 0)
38
39 explicit QVirtualKeyboardInputEngine(QVirtualKeyboardInputContext *parent = nullptr);
40 void init();
41
42public:
43 enum class TextCase {
44 Lower,
45 Upper
46 };
47 Q_ENUM(TextCase)
48
49 enum class InputMode {
50 Latin,
51 Numeric,
52 Dialable,
53 Pinyin,
54 Cangjie,
55 Zhuyin,
56 Hangul,
57 Hiragana,
58 Katakana,
59 FullwidthLatin,
60 Greek,
61 Cyrillic,
62 Arabic,
63 Hebrew,
64 ChineseHandwriting,
65 JapaneseHandwriting,
66 KoreanHandwriting,
67 Thai,
68 Stroke,
69 Romaji,
70 };
71 Q_ENUM(InputMode)
72
73 enum class PatternRecognitionMode {
74 None,
75 PatternRecognitionDisabled = None,
76 Handwriting,
77 HandwritingRecoginition = Handwriting
78 };
79 Q_ENUM(PatternRecognitionMode)
80
81 enum class ReselectFlag {
82 WordBeforeCursor = 0x1,
83 WordAfterCursor = 0x2,
84 WordAtCursor = WordBeforeCursor | WordAfterCursor
85 };
86 Q_FLAG(ReselectFlag)
87 Q_DECLARE_FLAGS(ReselectFlags, ReselectFlag)
88
89public:
90 ~QVirtualKeyboardInputEngine();
91
92 Q_INVOKABLE bool virtualKeyPress(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers, bool repeat);
93 Q_INVOKABLE void virtualKeyCancel();
94 Q_INVOKABLE bool virtualKeyRelease(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers);
95 Q_INVOKABLE bool virtualKeyClick(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers);
96
97 QVirtualKeyboardInputContext *inputContext() const;
98 Qt::Key activeKey() const;
99 Qt::Key previousKey() const;
100
101 QVirtualKeyboardAbstractInputMethod *inputMethod() const;
102 void setInputMethod(QVirtualKeyboardAbstractInputMethod *inputMethod);
103
104 QList<int> inputModes() const;
105
106 InputMode inputMode() const;
107 void setInputMode(InputMode inputMode);
108
109 QVirtualKeyboardSelectionListModel *wordCandidateListModel() const;
110 bool wordCandidateListVisibleHint() const;
111
112 QList<int> patternRecognitionModes() const;
113 Q_INVOKABLE QVirtualKeyboardTrace *traceBegin(
114 int traceId, PatternRecognitionMode patternRecognitionMode,
115 const QVariantMap &traceCaptureDeviceInfo, const QVariantMap &traceScreenInfo);
116 Q_INVOKABLE bool traceEnd(QVirtualKeyboardTrace *trace);
117
118 Q_INVOKABLE bool reselect(int cursorPosition, const ReselectFlags &reselectFlags);
119 bool clickPreeditText(int cursorPosition);
120
121Q_SIGNALS:
122 void virtualKeyClicked(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers, bool isAutoRepeat);
123 void activeKeyChanged(Qt::Key key);
124 void previousKeyChanged(Qt::Key key);
125 void inputMethodChanged();
126 void inputMethodReset();
127 void inputMethodUpdate();
128 void inputModesChanged();
129 void inputModeChanged();
130 void patternRecognitionModesChanged();
131 void wordCandidateListModelChanged();
132 void wordCandidateListVisibleHintChanged();
133
134private Q_SLOTS:
135 void reset();
136 void update();
137 void shiftChanged();
138 void updateSelectionListModels();
139 void updateInputModes();
140
141protected:
142 void timerEvent(QTimerEvent *timerEvent) override;
143
144private:
145 friend class QVirtualKeyboardInputContext;
146 friend class QVirtualKeyboardInputContextPrivate;
147};
148
149Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(QVirtualKeyboardInputEngine::InputMode key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
150Q_DECLARE_OPERATORS_FOR_FLAGS(QVirtualKeyboardInputEngine::ReselectFlags)
151
152QT_END_NAMESPACE
153
154Q_DECLARE_METATYPE(QVirtualKeyboardInputEngine::TextCase)
155Q_DECLARE_METATYPE(QVirtualKeyboardInputEngine::InputMode)
156Q_DECLARE_METATYPE(QVirtualKeyboardInputEngine::PatternRecognitionMode)
157Q_DECLARE_METATYPE(QVirtualKeyboardInputEngine::ReselectFlag)
158
159#endif
160

source code of qtvirtualkeyboard/src/virtualkeyboard/qvirtualkeyboardinputengine.h