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
qohosjsutils.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 QOHOSJSUTILS_H
5#define QOHOSJSUTILS_H
6
7#include <QtCore/private/qnapi_p.h>
8#include <QtCore/private/qohoscommon_p.h>
9#include <QtCore/qglobal.h>
10#include <chrono>
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <qohosplugincore.h>
15#include <qohosutils.h>
16#include <string>
17#include <type_traits>
18
20
22
23namespace QtOhos {
24
31
32template<typename T>
34 JsState &jsState, std::function<QNapi::Value(JsState &, T)> promiseValueFactory,
35 const QOhosConsumer<JsState &, QOhosConsumer<JsState &, T>> &asyncCallFunc);
36
38 QNapi::Object eventSourceObject, const std::string &eventTypeName,
39 QNapi::CallbackFuncWrapper handler, OnOffMethodsBasedEventHandlerOptions options = {});
40
44
45int setJsTimeout(
46 JsState &jsState, std::function<void(const CallbackInfo &)> timeoutFunc,
47 std::chrono::milliseconds delay);
48
49void clearJsTimeout(JsState &jsState, int timerId);
50
51QNapi::Promise makeResolvedPromise(QNapi::Value valueForResolve);
52
53template<typename T>
54QOhosOptional<T> getOptionalProperty(const QNapi::Object &object, const std::string &propName);
55
57
58template<typename T>
60 JsState &jsState, std::function<QNapi::Value(JsState &, T)> promiseValueFactory,
61 const QOhosConsumer<JsState &, QOhosConsumer<JsState &, T>> &asyncCallFunc)
62{
63 auto promiseDeferred = QNapi::Promise::Deferred::New(jsState.env());
64
65 asyncCallFunc(
66 jsState,
67 makeCallOnceConsumerWrapper<JsState &, T>(
68 [promiseDeferred, promiseValueFactory = std::move(promiseValueFactory)](JsState &jsState, T result) {
69 promiseDeferred.Resolve(promiseValueFactory(jsState, result));
70 }));
71
72 return promiseDeferred.Promise();
73}
74
75template<typename T>
76QOhosOptional<T> getOptionalProperty(const QNapi::Object &object, const std::string &propName)
77{
78 auto optPropValue = QNapi::getOptionalPropOrEmpty<T>(object, propName);
79 return !optPropValue.IsEmpty()
80 ? makeQOhosOptional(optPropValue)
82}
83
84}
85
86QT_END_NAMESPACE
87
88#endif // QOHOSJSUTILS_H
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 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
JsInputMethodInsertedTextComposer & operator=(const JsInputMethodInsertedTextComposer &)=delete
JsInputMethodInsertedTextComposer(JsInputMethodInsertedTextComposer &&)=delete
static JsInputMethodInsertedTextComposer & instance()
JsInputMethodInsertedTextComposer & operator=(JsInputMethodInsertedTextComposer &&)=delete
QOhosOptional< InsertedTextId > lastId() const
JsInputMethodInsertedTextComposer(const JsInputMethodInsertedTextComposer &)=delete
QOhosInsertedText makeInsertedText(const std::string &text)
QOhosInsertedText(const std::string &text, const InsertedTextId &id)
Combined button and popup list for selecting options.
QOhosOptional< QOhosInputContext::Direction > tryMapInputMethodDirectionToQt(::InputMethod_Direction direction)
::InputMethod_TextInputType mapQtInputMethodHintsToOhosImeTextInputType(Qt::InputMethodHints hints)
::InputMethod_EnterKeyType mapQtToOhosImeEnterKeyType(Qt::EnterKeyType qtEnterKeyType)
const Qt::EnterKeyType defaultEnterKeyType
void notifyOhosInputMethodAboutPossibleAutocorrection(const QOhosInsertedText &insertedText, int cursorPosition)
const Qt::InputMethodHints defaultInputMethodHints
QPoint clampToRect(const QPoint &p, const QRect &rect)
::InputMethod_RequestKeyboardReason mapQtToOhosImeRequestReason(QOhosInputContext::RequestKeyboardReason qtRequestKeyboardReason)
QOhosOptional< int > tryGetIntPropertyFromQuery(Qt::InputMethodQuery property, QSharedPointer< QInputMethodQueryEvent > query)
std::shared_ptr< void > registerOnOffMethodsBasedEventHandler(QNapi::Object eventSourceObject, const std::string &eventTypeName, QNapi::CallbackFuncWrapper handler, OnOffMethodsBasedEventHandlerOptions options={})
void clearJsTimeout(JsState &jsState, int timerId)
int setJsTimeout(JsState &jsState, std::function< void(const CallbackInfo &)> timeoutFunc, std::chrono::milliseconds delay)
QOhosOptional< T > getOptionalProperty(const QNapi::Object &object, const std::string &propName)
QNapi::Promise adaptAsyncCallResultToJsPromise(JsState &jsState, std::function< QNapi::Value(JsState &, T)> promiseValueFactory, const QOhosConsumer< JsState &, QOhosConsumer< JsState &, T > > &asyncCallFunc)
QNapi::Promise makeResolvedPromise(QNapi::Value valueForResolve)
void invokeInJsThreadAndWaitForContinue(std::function< void(JsState &, std::function< void()>)> &&task)
QOhosOptional< std::uint32_t > tryGetCodeFromJsBusinessError(const Napi::Error &error)
QOhosOptional< void > makeEmptyQOhosOptional()
std::function< bool(QNapi::Object)> optEventSourceAliveCheckFunc
QOhosOptional< QNapi::ValueWrapper > extraOnArg
QOhosOptional< QNapi::ValueWrapper > extraOffArg