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