Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qandroidinputcontext.h
Go to the documentation of this file.
1// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef ANDROIDINPUTCONTEXT_H
6#define ANDROIDINPUTCONTEXT_H
7
8#include <qpa/qplatforminputcontext.h>
9#include <functional>
10#include <jni.h>
11#include <qevent.h>
12#include <QTimer>
13
15
17{
19 enum CapsMode
20 {
21 CAP_MODE_CHARACTERS = 0x00001000,
22 CAP_MODE_SENTENCES = 0x00004000,
23 CAP_MODE_WORDS = 0x00002000
24 };
25
26public:
27 enum EditContext : uint32_t {
28 CutButton = 1 << 0,
29 CopyButton = 1 << 1,
30 PasteButton = 1 << 2,
33 };
34
36 Hidden = 0,
39 ShowEditPopup = 0x100
40 };
41 Q_DECLARE_FLAGS(HandleModes, HandleMode)
42
44 {
46
47 void clear()
48 {
49 partialEndOffset = partialStartOffset = selectionEnd = selectionStart = startOffset = -1;
50 text.clear();
51 }
52
59 };
60
61public:
65 bool isValid() const override { return true; }
66
67 void reset() override;
68 void commit() override;
69 void update(Qt::InputMethodQueries queries) override;
70 void invokeAction(QInputMethod::Action action, int cursorPosition) override;
71 QRectF keyboardRect() const override;
72 bool isAnimating() const override;
73 void showInputPanel() override;
74 void hideInputPanel() override;
75 bool isInputPanelVisible() const override;
76
77 bool isComposing() const;
78 void clear();
79 void setFocusObject(QObject *object) override;
80 void sendShortcut(const QKeySequence &);
81
82 //---------------//
83 jboolean beginBatchEdit();
84 jboolean endBatchEdit();
85 jboolean commitText(const QString &text, jint newCursorPosition);
86 jboolean deleteSurroundingText(jint leftLength, jint rightLength);
87 jboolean finishComposingText();
88 jint getCursorCapsMode(jint reqModes);
89 const ExtractedText &getExtractedText(jint hintMaxChars, jint hintMaxLines, jint flags);
93 jboolean setComposingText(const QString &text, jint newCursorPosition);
94 jboolean setComposingRegion(jint start, jint end);
95 jboolean setSelection(jint start, jint end);
96 jboolean selectAll();
97 jboolean cut();
98 jboolean copy();
99 jboolean copyURL();
100 jboolean paste();
101
102public slots:
103 void safeCall(const std::function<void()> &func, Qt::ConnectionType conType = Qt::BlockingQueuedConnection);
106 void handleLocationChanged(int handleId, int x, int y);
107 void touchDown(int x, int y);
108 void longPress(int x, int y);
109 void keyDown();
111
112private slots:
113 void showInputPanelLater(Qt::ApplicationState);
114
115private:
116 void sendInputMethodEvent(QInputMethodEvent *event);
117 QSharedPointer<QInputMethodQueryEvent> focusObjectInputMethodQuery(Qt::InputMethodQueries queries = Qt::ImQueryAll);
118 bool focusObjectIsComposing() const;
119 void focusObjectStartComposing();
120 bool focusObjectStopComposing();
121
122private:
123 ExtractedText m_extractedText;
124 QString m_composingText;
125 int m_composingTextStart;
126 int m_composingCursor;
127 QMetaObject::Connection m_updateCursorPosConnection;
128 HandleModes m_handleMode;
129 int m_batchEditNestingLevel;
130 QPointer<QObject> m_focusObject;
131 QTimer m_hideCursorHandleTimer;
132};
133Q_DECLARE_OPERATORS_FOR_FLAGS(QAndroidInputContext::HandleModes)
135
136#endif // ANDROIDINPUTCONTEXT_H
jboolean setSelection(jint start, jint end)
void safeCall(const std::function< void()> &func, Qt::ConnectionType conType=Qt::BlockingQueuedConnection)
bool isValid() const override
Returns input context validity.
jint getCursorCapsMode(jint reqModes)
QString getSelectedText(jint flags)
bool isAnimating() const override
This function can be reimplemented to return true whenever input method is animating shown or hidden.
QString getTextAfterCursor(jint length, jint flags)
QRectF keyboardRect() const override
This function can be reimplemented to return virtual keyboard rectangle in currently active window co...
void reset() override
Method to be called when input method needs to be reset.
jboolean setComposingText(const QString &text, jint newCursorPosition)
void hideInputPanel() override
Request to hide input panel.
void setFocusObject(QObject *object) override
This virtual method gets called to notify updated focus to object.
jboolean commitText(const QString &text, jint newCursorPosition)
jboolean setComposingRegion(jint start, jint end)
static QAndroidInputContext * androidInputContext()
void update(Qt::InputMethodQueries queries) override
Notification on editor updates.
QString getTextBeforeCursor(jint length, jint flags)
void sendShortcut(const QKeySequence &)
void invokeAction(QInputMethod::Action action, int cursorPosition) override
Called when the word currently being composed in the input item is tapped by the user.
jboolean deleteSurroundingText(jint leftLength, jint rightLength)
void handleLocationChanged(int handleId, int x, int y)
void showInputPanel() override
Request to show input panel.
const ExtractedText & getExtractedText(jint hintMaxChars, jint hintMaxLines, jint flags)
bool isInputPanelVisible() const override
Returns input panel visibility status.
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
Action
Indicates the kind of action performed by the user.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore
Definition qobject.h:90
The QPlatformInputContext class abstracts the input method dependent data and composing state.
\inmodule QtCore
Definition qpointer.h:18
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
\inmodule QtCore
Definition qtimer.h:20
QString text
Combined button and popup list for selecting options.
@ ImQueryAll
ApplicationState
Definition qnamespace.h:261
ConnectionType
@ BlockingQueuedConnection
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLint GLint GLint GLint GLint x
[0]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLbitfield flags
GLuint start
GLint y
struct _cl_event * event
GLenum func
Definition qopenglext.h:663
#define Q_OBJECT
#define slots