| 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 QVIRTUALKEYBOARDINPUTCONTEXT_H |
| 31 | #define QVIRTUALKEYBOARDINPUTCONTEXT_H |
| 32 | |
| 33 | #include <QObject> |
| 34 | #include <QRectF> |
| 35 | #include <QLocale> |
| 36 | #include <QInputMethodEvent> |
| 37 | #include <QInputMethod> |
| 38 | #include <QtVirtualKeyboard/qvirtualkeyboard_global.h> |
| 39 | |
| 40 | QT_BEGIN_NAMESPACE |
| 41 | |
| 42 | namespace QtVirtualKeyboard { |
| 43 | class PlatformInputContext; |
| 44 | } |
| 45 | class QVirtualKeyboardInputEngine; |
| 46 | class QVirtualKeyboardInputContextPrivate; |
| 47 | |
| 48 | class QVIRTUALKEYBOARD_EXPORT QVirtualKeyboardInputContext : public QObject |
| 49 | { |
| 50 | Q_OBJECT |
| 51 | Q_DISABLE_COPY(QVirtualKeyboardInputContext) |
| 52 | Q_DECLARE_PRIVATE(QVirtualKeyboardInputContext) |
| 53 | Q_PROPERTY(bool shift READ isShiftActive NOTIFY shiftActiveChanged) |
| 54 | Q_PROPERTY(bool shiftActive READ isShiftActive NOTIFY shiftActiveChanged REVISION 4) |
| 55 | Q_PROPERTY(bool capsLock READ isCapsLockActive NOTIFY capsLockActiveChanged) |
| 56 | Q_PROPERTY(bool capsLockActive READ isCapsLockActive NOTIFY capsLockActiveChanged REVISION 4) |
| 57 | Q_PROPERTY(bool uppercase READ isUppercase NOTIFY uppercaseChanged) |
| 58 | Q_PROPERTY(int anchorPosition READ anchorPosition NOTIFY anchorPositionChanged) |
| 59 | Q_PROPERTY(int cursorPosition READ cursorPosition NOTIFY cursorPositionChanged) |
| 60 | Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints NOTIFY inputMethodHintsChanged) |
| 61 | Q_PROPERTY(QString preeditText READ preeditText WRITE setPreeditText NOTIFY preeditTextChanged) |
| 62 | Q_PROPERTY(QString surroundingText READ surroundingText NOTIFY surroundingTextChanged) |
| 63 | Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) |
| 64 | Q_PROPERTY(QRectF anchorRectangle READ anchorRectangle NOTIFY anchorRectangleChanged) |
| 65 | Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) |
| 66 | Q_PROPERTY(bool animating READ isAnimating WRITE setAnimating NOTIFY animatingChanged) |
| 67 | Q_PROPERTY(QString locale READ locale NOTIFY localeChanged) |
| 68 | Q_PROPERTY(QObject *inputItem READ inputItem NOTIFY inputItemChanged) |
| 69 | Q_PROPERTY(QVirtualKeyboardInputEngine *inputEngine READ inputEngine CONSTANT) |
| 70 | Q_PROPERTY(bool selectionControlVisible READ isSelectionControlVisible NOTIFY selectionControlVisibleChanged) |
| 71 | Q_PROPERTY(bool anchorRectIntersectsClipRect READ anchorRectIntersectsClipRect NOTIFY anchorRectIntersectsClipRectChanged) |
| 72 | Q_PROPERTY(bool cursorRectIntersectsClipRect READ cursorRectIntersectsClipRect NOTIFY cursorRectIntersectsClipRectChanged) |
| 73 | Q_PROPERTY(QVirtualKeyboardInputContextPrivate *priv READ priv CONSTANT) |
| 74 | |
| 75 | public: |
| 76 | explicit QVirtualKeyboardInputContext(QObject *parent = nullptr); |
| 77 | ~QVirtualKeyboardInputContext(); |
| 78 | |
| 79 | bool isShiftActive() const; |
| 80 | bool isCapsLockActive() const; |
| 81 | bool isUppercase() const; |
| 82 | int anchorPosition() const; |
| 83 | int cursorPosition() const; |
| 84 | Qt::InputMethodHints inputMethodHints() const; |
| 85 | QString preeditText() const; |
| 86 | void setPreeditText(const QString &text, QList<QInputMethodEvent::Attribute> attributes = QList<QInputMethodEvent::Attribute>(), int replaceFrom = 0, int replaceLength = 0); |
| 87 | QList<QInputMethodEvent::Attribute> preeditTextAttributes() const; |
| 88 | QString surroundingText() const; |
| 89 | QString selectedText() const; |
| 90 | QRectF anchorRectangle() const; |
| 91 | QRectF cursorRectangle() const; |
| 92 | bool isAnimating() const; |
| 93 | void setAnimating(bool isAnimating); |
| 94 | QString locale() const; |
| 95 | QObject *inputItem() const; |
| 96 | QVirtualKeyboardInputEngine *inputEngine() const; |
| 97 | bool isSelectionControlVisible() const; |
| 98 | bool anchorRectIntersectsClipRect() const; |
| 99 | bool cursorRectIntersectsClipRect() const; |
| 100 | QVirtualKeyboardInputContextPrivate *priv() const; |
| 101 | |
| 102 | Q_INVOKABLE void sendKeyClick(int key, const QString &text, int modifiers = 0); |
| 103 | Q_INVOKABLE void commit(); |
| 104 | Q_INVOKABLE void commit(const QString &text, int replaceFrom = 0, int replaceLength = 0); |
| 105 | Q_INVOKABLE void clear(); |
| 106 | |
| 107 | // For selection handles |
| 108 | Q_INVOKABLE void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos); |
| 109 | |
| 110 | Q_SIGNALS: |
| 111 | void preeditTextChanged(); |
| 112 | void inputMethodHintsChanged(); |
| 113 | void surroundingTextChanged(); |
| 114 | void selectedTextChanged(); |
| 115 | void anchorPositionChanged(); |
| 116 | void cursorPositionChanged(); |
| 117 | void anchorRectangleChanged(); |
| 118 | void cursorRectangleChanged(); |
| 119 | void shiftActiveChanged(); |
| 120 | void capsLockActiveChanged(); |
| 121 | void uppercaseChanged(); |
| 122 | void animatingChanged(); |
| 123 | void localeChanged(); |
| 124 | void inputItemChanged(); |
| 125 | void selectionControlVisibleChanged(); |
| 126 | void anchorRectIntersectsClipRectChanged(); |
| 127 | void cursorRectIntersectsClipRectChanged(); |
| 128 | |
| 129 | private: |
| 130 | |
| 131 | QScopedPointer<QVirtualKeyboardInputContextPrivate> d_ptr; |
| 132 | }; |
| 133 | |
| 134 | QT_END_NAMESPACE |
| 135 | |
| 136 | #endif |
| 137 | |