Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosinputcontext.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOHOSINPUTCONTEXT_H
5#define QOHOSINPUTCONTEXT_H
6
7#include <qohosinputmethodproxy.h>
8#include <qohosplugincore.h>
9#include <qpa/qplatforminputcontext.h>
10#include <qpa/qwindowsysteminterface.h>
11#include <QtCore/private/qohoscommon_p.h>
12#include <QtCore/qglobal.h>
13
15
16class QOhosNativeXComponent;
17
19{
21
22public:
29
42
54
61
64 bool isValid() const override { return true; }
65
66 void reset() override;
67 void commit() override;
68 void update(Qt::InputMethodQueries queries) override;
69 void invokeAction(QInputMethod::Action action, int cursorPosition) override;
70 QRectF keyboardRect() const override;
71 bool isAnimating() const override;
74 bool isInputPanelVisible() const override;
75 void setFocusObject(QObject *object) override;
77
78 void setSoftwareKeyboardVisibilityStatus(bool visible);
79 void setLastInputTypeToTriggerSoftKeyboard(RequestKeyboardReason inputType);
80
81 bool eventFilter(QObject *obj, QEvent *event) override;
82private:
83 enum class ImConnectionState {
84 Attached,
85 Detached,
86 };
87
88 struct JsScopeData
89 {
90 std::shared_ptr<void> imControllerCallbacksHandle;
91 };
92
93 void setImConnectionState(ImConnectionState requestedState);
94 void setImConnectionStateImpl(ImConnectionState requestedState);
95 void dispatchRequestedImStateChange(ImConnectionState requestedState);
96 void showTextInput();
97 void updateInputMethodControllerAttributes(
98 Qt::InputMethodHints qtInputMethodHints, Qt::EnterKeyType qtEnterKeyType);
99 void updateOhosCursor(const QRect &globalCursorRect);
100 bool attachToInputMethodController();
101 bool detachFromInputMethodController();
102 void handleRequestedImConnectionState(ImConnectionState requestedState, bool success);
103
104 void onCursorRectangleChanged();
105 void handleFocusInEvent(QObject *obj, QFocusEvent *event);
106
107 void sendInsertedTextToQt(const std::string &textToInsert);
108 void sendInsertedPreviewTextToQt(std::string previewText);
109 void sendFocusObjectInputMethodEvent(QInputMethodEvent *event);
110 void sendCursorMoveToQt(QOhosInputContext::Direction direction);
111 void sendFocusObjectFunctionalKeyEvent(Qt::Key key, const QChar &keyChar, int repeatCount = 1);
112
113 bool queryImEnabled() const;
114 Qt::InputMethodHints queryInputMethodHints() const;
115 Qt::EnterKeyType queryEnterKeyType() const;
116 QOhosOptional<int> tryQueryCursorPosition() const;
117 QSharedPointer<QInputMethodQueryEvent> tryQueryFocusObjectInputMethod(Qt::InputMethodQueries queries) const;
118
119 QRect m_lastCursorRectangle;
120 QPoint m_lastFocusedWindowPosition;
121
122 ImConnectionState m_imConnectionState = ImConnectionState::Detached;
123 ImConnectionState m_imConnectionRequestedState = ImConnectionState::Detached;
124 bool m_imConnectionRequestActive = false;
125
126 bool m_updateCursorRectangleAfterAttaching = false;
127 bool m_softwareKeyboardVisible = false;
128
129 QOhosOptional<RequestKeyboardReason> m_lastInputTypeToTriggerSoftKeyboard;
130
131 bool m_qtImEnabled;
132 Qt::InputMethodHints m_qtInputMethodHints;
133 Qt::EnterKeyType m_qtEnterKeyType;
134
135 std::shared_ptr<JsScopeData> m_jsScopeData;
136 std::shared_ptr<QOhosInputMethodProxy> m_imProxy;
137
138 QPointer<QObject> m_focusObject;
139 QString m_pendingPreeditText;
140};
141
142namespace QtOhos {
143
144template<>
146{
147 static constexpr const char *fullTypeName = "@ohos.inputMethod.RequestKeyboardReason";
154};
155
156template<>
158{
159 static constexpr const char *fullTypeName = "@ohos.inputMethod.TextInputType";
160 static constexpr std::array<std::pair<QOhosInputContext::TextInputType, const char *>, 10> enumeratorsNames = {{
167 {QOhosInputContext::TextInputType::EMAIL_ADDRESS, "EMAIL_ADDRESS"},
169 {QOhosInputContext::TextInputType::VISIBLE_PASSWORD, "VISIBLE_PASSWORD"},
170 {QOhosInputContext::TextInputType::NUMBER_PASSWORD, "NUMBER_PASSWORD"},
171 }};
172};
173
174template<>
176{
177 static constexpr const char *fullTypeName = "@ohos.inputMethod.EnterKeyType";
178 static constexpr std::array<std::pair<QOhosInputContext::EnterKeyType, const char *>, 9> enumeratorsNames = {{
179 {QOhosInputContext::EnterKeyType::UNSPECIFIED, "UNSPECIFIED"},
188 }};
189};
190
191template<>
193{
194 static constexpr const char *fullTypeName = "@ohos.inputMethod.Direction";
195 static constexpr std::array<std::pair<QOhosInputContext::Direction, const char *>, 4> enumeratorsNames = {{
196 {QOhosInputContext::Direction::CURSOR_UP, "CURSOR_UP"},
197 {QOhosInputContext::Direction::CURSOR_DOWN, "CURSOR_DOWN"},
198 {QOhosInputContext::Direction::CURSOR_LEFT, "CURSOR_LEFT"},
199 {QOhosInputContext::Direction::CURSOR_RIGHT, "CURSOR_RIGHT"},
200 }};
201};
202
203}
204
205QT_END_NAMESPACE
206
207#endif // QOHOSINPUTCONTEXT_H
QOhosFloatingWindow(QWindow *window)
~QOhosFloatingWindow() override
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
QOhosView * ownedViewOrNull() const override
void onWindowStateChanged(Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState) override
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags) override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QOhosSurface * ownedSurfaceOrNull() const override
void setMask(const QRegion &region) override
Reimplement to be able to let Qt set the mask of a window.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void update(Qt::InputMethodQueries queries) override
Notification on editor updates.
QRectF keyboardRect() const override
This function can be reimplemented to return virtual keyboard rectangle in currently active window co...
void setSoftwareKeyboardVisibilityStatus(bool visible)
void showInputPanel() override
Request to show input panel.
void invokeAction(QInputMethod::Action action, int cursorPosition) override
Called when the word currently being composed in the input item is tapped by the user.
void setLastInputTypeToTriggerSoftKeyboard(RequestKeyboardReason inputType)
void reset() override
Method to be called when input method needs to be reset.
void hideInputPanel() override
Request to hide input panel.
bool isValid() const override
Returns input context validity.
bool eventFilter(QObject *obj, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
bool isInputPanelVisible() const override
Returns input panel visibility status.
QObject * focusObjectOrNull() const
void setFocusObject(QObject *object) override
This virtual method gets called to notify updated focus to object.
bool isAnimating() const override
This function can be reimplemented to return true whenever input method is animating shown or hidden.
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
void setDisplayIdFromOhos(QOhosOptional< QOhosDisplayInfo::JsDisplayId > displayId)
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void notifyInputSystemsWindowActiveStatusChanged(bool active)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
QOhosSurface * surfaceOrNull() const
void setWindowMask(const QOhosWindowProxy::WindowMask &windowMask)
void lower()
ViewGeometry viewGeometry() const
bool startMoving()
bool isSubWindowCoveringFullScreen() const
void raise()
static QWindowProxyRegistry & instance()
bool isWindowPcModeEnabled()
Combined button and popup list for selecting options.
bool isWindowRotatedByTabletScreenRotation(QWindow *window, QOhosWindowProxy::RectChangeOptions rectChangeOptions)
QOhosRuntimeDeviceTypeAndMode queryQOhosRuntimeDeviceAndMode()