xref: /OK3568_Linux_fs/app/forlinx/DWKeyboard/include/inputengine.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 Qt Virtual Keyboard module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
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 General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 or (at your option) any later version
20 ** approved by the KDE Free Qt Foundation. The licenses are as published by
21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
22 ** included in the packaging of this file. Please review the following
23 ** information to ensure the GNU General Public License requirements will
24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 **
26 ** $QT_END_LICENSE$
27 **
28 ****************************************************************************/
29 
30 #ifndef INPUTENGINE_H
31 #define INPUTENGINE_H
32 
33 #include <QObject>
34 #include <QPointer>
35 #include "dwkeyboard_global.h"
36 
37 namespace QtVirtualKeyboard {
38 
39 class InputContext;
40 class SelectionListModel;
41 class AbstractInputMethod;
42 class InputEnginePrivate;
43 class Trace;
44 
45 class DWKEYBOARDSHARED_EXPORT InputEngine : public QObject
46 {
47     Q_OBJECT
48     Q_DISABLE_COPY(InputEngine)
49     Q_DECLARE_PRIVATE(InputEngine)
50     Q_ENUMS(TextCase)
51     Q_ENUMS(InputMode)
52     Q_ENUMS(PatternRecognitionMode)
53     Q_FLAGS(ReselectFlags)
54     Q_PROPERTY(Qt::Key activeKey READ activeKey NOTIFY activeKeyChanged)
55     Q_PROPERTY(Qt::Key previousKey READ previousKey NOTIFY previousKeyChanged)
56     Q_PROPERTY(QtVirtualKeyboard::AbstractInputMethod *inputMethod READ inputMethod WRITE setInputMethod NOTIFY inputMethodChanged)
57     Q_PROPERTY(QList<int> inputModes READ inputModes NOTIFY inputModesChanged)
58     Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode NOTIFY inputModeChanged)
59     Q_PROPERTY(QList<int> patternRecognitionModes READ patternRecognitionModes NOTIFY patternRecognitionModesChanged)
60     Q_PROPERTY(QtVirtualKeyboard::SelectionListModel *wordCandidateListModel READ wordCandidateListModel NOTIFY wordCandidateListModelChanged)
61     Q_PROPERTY(bool wordCandidateListVisibleHint READ wordCandidateListVisibleHint NOTIFY wordCandidateListVisibleHintChanged)
62 
63     explicit InputEngine(InputContext *parent = 0);
64 
65 public:
66     enum TextCase {
67         Lower,
68         Upper
69     };
70     enum InputMode {
71         Latin,      // 英文[拉丁]
72         Numeric,
73         Dialable,
74         Pinyin,     // 拼音
75         Cangjie,    // 仓颉编码
76         Zhuyin,
77         Hangul,     // 韩语
78         Hiragana,   // 平假名
79         Katakana,   // 片假名
80         FullwidthLatin
81     };
82     enum PatternRecognitionMode {
83         PatternRecognitionDisabled,
84         HandwritingRecoginition
85     };
86     enum ReselectFlag {
87         WordBeforeCursor = 0x1,
88         WordAfterCursor = 0x2,
89         WordAtCursor = WordBeforeCursor | WordAfterCursor
90     };
91     Q_DECLARE_FLAGS(ReselectFlags, ReselectFlag)
92 
93 public:
94     ~InputEngine();
95 
96     Q_INVOKABLE bool virtualKeyPress(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers, bool repeat);
97     Q_INVOKABLE void virtualKeyCancel();
98     Q_INVOKABLE bool virtualKeyRelease(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers);
99     Q_INVOKABLE bool virtualKeyClick(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers);
100 
101     InputContext *inputContext() const;
102     Qt::Key activeKey() const;
103     Qt::Key previousKey() const;
104 
105     AbstractInputMethod *inputMethod() const;
106     void setInputMethod(AbstractInputMethod *inputMethod);
107 
108     QList<int> inputModes() const;
109 
110     InputMode inputMode() const;
111     void setInputMode(InputMode inputMode);
112 
113     SelectionListModel *wordCandidateListModel() const;
114     bool wordCandidateListVisibleHint() const;
115 
116     QList<int> patternRecognitionModes() const;
117     Q_INVOKABLE QtVirtualKeyboard::Trace *traceBegin(int traceId, QtVirtualKeyboard::InputEngine::PatternRecognitionMode patternRecognitionMode,
118                                                      const QVariantMap &traceCaptureDeviceInfo, const QVariantMap &traceScreenInfo);
119     Q_INVOKABLE bool traceEnd(QtVirtualKeyboard::Trace *trace);
120 
121     Q_INVOKABLE bool reselect(int cursorPosition, const ReselectFlags &reselectFlags);
122 
123 signals:
124     void virtualKeyClicked(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers, bool isAutoRepeat);
125     void activeKeyChanged(Qt::Key key);
126     void previousKeyChanged(Qt::Key key);
127     void inputMethodChanged();
128     void inputMethodReset();
129     void inputMethodUpdate();
130     void inputModesChanged();
131     void inputModeChanged();
132     void patternRecognitionModesChanged();
133     void wordCandidateListModelChanged();
134     void wordCandidateListVisibleHintChanged();
135 
136 private slots:
137     void reset();
138     void update();
139     void shiftChanged();
140 
141 protected:
142     void timerEvent(QTimerEvent *timerEvent);
143 
144 private:
145     friend class InputContext;
146 };
147 
148 } // namespace QtVirtualKeyboard
149 
150 Q_DECLARE_METATYPE(QtVirtualKeyboard::InputEngine::TextCase)
151 Q_DECLARE_METATYPE(QtVirtualKeyboard::InputEngine::InputMode)
152 Q_DECLARE_OPERATORS_FOR_FLAGS(QtVirtualKeyboard::InputEngine::ReselectFlags)
153 
154 #endif
155