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