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 <optional>
8#include <qohosenums.h>
9#include <qohosinputmethodproxy.h>
10#include <qohosplugincore.h>
11#include <qpa/qplatforminputcontext.h>
12#include <qpa/qwindowsysteminterface.h>
13#include <QtCore/private/qohoscommon_p.h>
14#include <QtCore/qglobal.h>
15
17
18class QOhosNativeXComponent;
19
21{
23
24public:
26
28
30
32
35 bool isValid() const override { return true; }
36
37 void reset() override;
38 void commit() override;
39 void update(Qt::InputMethodQueries queries) override;
40 void invokeAction(QInputMethod::Action action, int cursorPosition) override;
41 QRectF keyboardRect() const override;
42 bool isAnimating() const override;
45 bool isInputPanelVisible() const override;
46 void setFocusObject(QObject *object) override;
48
49 void setSoftwareKeyboardVisibilityStatus(bool visible);
50 void setLastInputTypeToTriggerSoftKeyboard(RequestKeyboardReason inputType);
51
52 bool eventFilter(QObject *obj, QEvent *event) override;
53private:
54 enum class ImConnectionState {
55 Attached,
56 Detached,
57 };
58
59 struct JsScopeData
60 {
61 std::shared_ptr<void> imControllerCallbacksHandle;
62 };
63
64 void setImConnectionState(ImConnectionState requestedState);
65 void setImConnectionStateImpl(ImConnectionState requestedState);
66 void dispatchRequestedImStateChange(ImConnectionState requestedState);
67 void showTextInput();
68 void updateInputMethodControllerAttributes(
69 Qt::InputMethodHints qtInputMethodHints, Qt::EnterKeyType qtEnterKeyType);
70 void updateOhosCursor(const QRect &globalCursorRect);
71 void pushTextAroundCursorToProxy();
72 void updateSelection();
73 bool attachToInputMethodController();
74 bool detachFromInputMethodController();
75 void handleRequestedImConnectionState(ImConnectionState requestedState, bool success);
76
77 void onCursorRectangleChanged();
78 void handleFocusInEvent(QObject *obj, QFocusEvent *event);
79
80 void sendInsertedTextToQt(const std::string &textToInsert);
81 void sendInsertedPreviewTextToQt(std::string previewText);
82 void sendFocusObjectInputMethodEvent(QInputMethodEvent *event);
83 void sendCursorMoveToQt(QOhosInputContext::Direction direction);
84 void sendFocusObjectFunctionalKeyEvent(Qt::Key key, const QString &keyText = {}, int repeatCount = 1);
85
86 bool queryImEnabled() const;
87 Qt::InputMethodHints queryInputMethodHints() const;
88 Qt::EnterKeyType queryEnterKeyType() const;
89 std::optional<int> tryQueryCursorPosition() const;
90 QSharedPointer<QInputMethodQueryEvent> tryQueryFocusObjectInputMethod(Qt::InputMethodQueries queries) const;
91
92 QRect m_lastCursorRectangle;
93 QPoint m_lastFocusedWindowPosition;
94
95 ImConnectionState m_imConnectionState = ImConnectionState::Detached;
96 ImConnectionState m_imConnectionRequestedState = ImConnectionState::Detached;
97 bool m_imConnectionRequestActive = false;
98
99 bool m_updateCursorRectangleAfterAttaching = false;
100 bool m_softwareKeyboardVisible = false;
101
102 std::optional<RequestKeyboardReason> m_lastInputTypeToTriggerSoftKeyboard;
103
104 bool m_qtImEnabled;
105 Qt::InputMethodHints m_qtInputMethodHints;
106 Qt::EnterKeyType m_qtEnterKeyType;
107
108 std::shared_ptr<JsScopeData> m_jsScopeData;
109 std::shared_ptr<QOhosInputMethodProxy> m_imProxy;
110
111 QPointer<QObject> m_focusObject;
112 QString m_pendingPreeditText;
113};
114
115QT_END_NAMESPACE
116
117#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
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
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.
void setDisplayIdFromOhos(std::optional< QOhosDisplayInfo::JsDisplayId > displayId)
void setExposedFromOhos(bool exposed)
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()
bool startMoving()
void raise()
QtOhos::enums::ohos::window::WindowEventType WindowEventType
static QWindowProxyRegistry & instance()
Combined button and popup list for selecting options.
bool shouldClearQtFocusOnSystemFocusLoss(QWindow *windowLosingSystemFocus)
bool isWindowRotatedByTabletScreenRotation(QWindow *window, QOhosWindowProxy::RectChangeOptions rectChangeOptions)
static QMargins cutoutMarginsForWindow(const QList< QRect > &cutoutRects, const QRect &windowRect)