1*4882a593Smuzhiyun #ifndef INPUTCONTEXT_H 2*4882a593Smuzhiyun #define INPUTCONTEXT_H 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #include <QObject> 5*4882a593Smuzhiyun #include <QRectF> 6*4882a593Smuzhiyun #include <QLocale> 7*4882a593Smuzhiyun #include <QInputMethodEvent> 8*4882a593Smuzhiyun #include <QInputMethod> 9*4882a593Smuzhiyun #include "dwkeyboard_global.h" 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun namespace QtVirtualKeyboard { 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun class PlatformInputContext; 14*4882a593Smuzhiyun class InputEngine; 15*4882a593Smuzhiyun class ShiftHandler; 16*4882a593Smuzhiyun class InputContextPrivate; 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun class DWKEYBOARDSHARED_EXPORT InputContext : public QObject 19*4882a593Smuzhiyun { 20*4882a593Smuzhiyun Q_OBJECT 21*4882a593Smuzhiyun Q_DISABLE_COPY(InputContext) 22*4882a593Smuzhiyun Q_DECLARE_PRIVATE(InputContext) 23*4882a593Smuzhiyun Q_PROPERTY(bool focus READ focus NOTIFY focusChanged) 24*4882a593Smuzhiyun Q_PROPERTY(bool shift READ shift WRITE setShift NOTIFY shiftChanged) 25*4882a593Smuzhiyun Q_PROPERTY(bool capsLock READ capsLock WRITE setCapsLock NOTIFY capsLockChanged) 26*4882a593Smuzhiyun Q_PROPERTY(int cursorPosition READ cursorPosition NOTIFY cursorPositionChanged) 27*4882a593Smuzhiyun Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints NOTIFY inputMethodHintsChanged) 28*4882a593Smuzhiyun Q_PROPERTY(QString preeditText READ preeditText WRITE setPreeditText NOTIFY preeditTextChanged) 29*4882a593Smuzhiyun Q_PROPERTY(QString surroundingText READ surroundingText NOTIFY surroundingTextChanged) 30*4882a593Smuzhiyun Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) 31*4882a593Smuzhiyun Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) 32*4882a593Smuzhiyun Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle WRITE setKeyboardRectangle NOTIFY keyboardRectangleChanged) 33*4882a593Smuzhiyun Q_PROPERTY(QRectF previewRectangle READ previewRectangle WRITE setPreviewRectangle NOTIFY previewRectangleChanged) 34*4882a593Smuzhiyun Q_PROPERTY(bool previewVisible READ previewVisible WRITE setPreviewVisible NOTIFY previewVisibleChanged) 35*4882a593Smuzhiyun Q_PROPERTY(bool animating READ animating WRITE setAnimating NOTIFY animatingChanged) 36*4882a593Smuzhiyun Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged) 37*4882a593Smuzhiyun Q_PROPERTY(QObject *inputItem READ inputItem NOTIFY inputItemChanged) 38*4882a593Smuzhiyun Q_PROPERTY(QtVirtualKeyboard::ShiftHandler *shiftHandler READ shiftHandler CONSTANT) 39*4882a593Smuzhiyun Q_PROPERTY(QtVirtualKeyboard::InputEngine *inputEngine READ inputEngine CONSTANT) 40*4882a593Smuzhiyun Q_PROPERTY(bool selectionControlVisible READ selectionControlVisible NOTIFY selectionControlVisibleChanged) 41*4882a593Smuzhiyun Q_PROPERTY(bool anchorRectIntersectsClipRect READ anchorRectIntersectsClipRect NOTIFY anchorRectIntersectsClipRectChanged) 42*4882a593Smuzhiyun Q_PROPERTY(bool cursorRectIntersectsClipRect READ cursorRectIntersectsClipRect NOTIFY cursorRectIntersectsClipRectChanged) 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun public: 45*4882a593Smuzhiyun explicit InputContext(PlatformInputContext *parent = 0); 46*4882a593Smuzhiyun ~InputContext(); 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun bool focus() const; 49*4882a593Smuzhiyun bool shift() const; 50*4882a593Smuzhiyun void setShift(bool enable); 51*4882a593Smuzhiyun bool capsLock() const; 52*4882a593Smuzhiyun void setCapsLock(bool enable); 53*4882a593Smuzhiyun int cursorPosition() const; 54*4882a593Smuzhiyun Qt::InputMethodHints inputMethodHints() const; 55*4882a593Smuzhiyun QString preeditText() const; 56*4882a593Smuzhiyun void setPreeditText(const QString &text, QList<QInputMethodEvent::Attribute> attributes = QList<QInputMethodEvent::Attribute>(), int replaceFrom = 0, int replaceLength = 0); 57*4882a593Smuzhiyun QString surroundingText() const; 58*4882a593Smuzhiyun QString selectedText() const; 59*4882a593Smuzhiyun QRectF cursorRectangle() const; 60*4882a593Smuzhiyun QRectF keyboardRectangle() const; 61*4882a593Smuzhiyun void setKeyboardRectangle(QRectF rectangle); 62*4882a593Smuzhiyun QRectF previewRectangle() const; 63*4882a593Smuzhiyun void setPreviewRectangle(QRectF rectangle); 64*4882a593Smuzhiyun bool previewVisible() const; 65*4882a593Smuzhiyun void setPreviewVisible(bool visible); 66*4882a593Smuzhiyun bool animating() const; 67*4882a593Smuzhiyun void setAnimating(bool animating); 68*4882a593Smuzhiyun QString locale() const; 69*4882a593Smuzhiyun void setLocale(const QString &locale); 70*4882a593Smuzhiyun Q_INVOKABLE void updateAvailableLocales(const QStringList &availableLocales); 71*4882a593Smuzhiyun QObject *inputItem() const; 72*4882a593Smuzhiyun ShiftHandler *shiftHandler() const; 73*4882a593Smuzhiyun InputEngine *inputEngine() const; 74*4882a593Smuzhiyun bool selectionControlVisible() const; 75*4882a593Smuzhiyun bool anchorRectIntersectsClipRect() const; 76*4882a593Smuzhiyun bool cursorRectIntersectsClipRect() const; 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun Q_INVOKABLE void hideInputPanel(); 79*4882a593Smuzhiyun Q_INVOKABLE void sendKeyClick(int key, const QString &text, int modifiers = 0); 80*4882a593Smuzhiyun Q_INVOKABLE void commit(); 81*4882a593Smuzhiyun Q_INVOKABLE void commit(const QString &text, int replaceFrom = 0, int replaceLength = 0); 82*4882a593Smuzhiyun Q_INVOKABLE void clear(); 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun // Helper functions 85*4882a593Smuzhiyun Q_INVOKABLE bool fileExists(const QUrl &fileUrl); 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun // For selection handles 88*4882a593Smuzhiyun Q_INVOKABLE void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos); 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun signals: 91*4882a593Smuzhiyun void focusChanged(); 92*4882a593Smuzhiyun void focusEditorChanged(); 93*4882a593Smuzhiyun void preeditTextChanged(); 94*4882a593Smuzhiyun void inputMethodHintsChanged(); 95*4882a593Smuzhiyun void surroundingTextChanged(); 96*4882a593Smuzhiyun void selectedTextChanged(); 97*4882a593Smuzhiyun void cursorPositionChanged(); 98*4882a593Smuzhiyun void cursorRectangleChanged(); 99*4882a593Smuzhiyun void shiftChanged(); 100*4882a593Smuzhiyun void capsLockChanged(); 101*4882a593Smuzhiyun void keyboardRectangleChanged(); 102*4882a593Smuzhiyun void previewRectangleChanged(); 103*4882a593Smuzhiyun void previewVisibleChanged(); 104*4882a593Smuzhiyun void animatingChanged(); 105*4882a593Smuzhiyun void localeChanged(); 106*4882a593Smuzhiyun void inputItemChanged(); 107*4882a593Smuzhiyun void selectionControlVisibleChanged(); 108*4882a593Smuzhiyun void navigationKeyPressed(int key, bool isAutoRepeat); 109*4882a593Smuzhiyun void navigationKeyReleased(int key, bool isAutoRepeat); 110*4882a593Smuzhiyun void anchorRectIntersectsClipRectChanged(); 111*4882a593Smuzhiyun void cursorRectIntersectsClipRectChanged(); 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun private slots: 114*4882a593Smuzhiyun void onInputItemChanged(); 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun private: 117*4882a593Smuzhiyun void setFocus(bool enable); 118*4882a593Smuzhiyun void sendPreedit(const QString &text, const QList<QInputMethodEvent::Attribute> &attributes, int replaceFrom, int replaceLength); 119*4882a593Smuzhiyun void reset(); 120*4882a593Smuzhiyun void externalCommit(); 121*4882a593Smuzhiyun void update(Qt::InputMethodQueries queries); 122*4882a593Smuzhiyun void invokeAction(QInputMethod::Action action, int cursorPosition); 123*4882a593Smuzhiyun bool filterEvent(const QEvent *event); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun private: 126*4882a593Smuzhiyun friend class PlatformInputContext; 127*4882a593Smuzhiyun }; 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun } // namespace QtVirtualKeyboard 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun #endif 132