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
qohosnativeaxiseventhandler.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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#include <render/qohosnativeaxiseventhandler.h>
5
6#include <render/qohosnativegestureshandler.h>
7
9
10namespace {
11
12class QOhosAxisEventHandler final : public std::enable_shared_from_this<QOhosAxisEventHandler>
13{
14public:
16 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
17 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef);
18
19 void handleUiAxisEvent(ArkUI_UIInputEvent *event);
20
21private:
22 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
23 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
24
25 QOhosConsumer<const QOhosNativeGestureEvent &> m_nativeGesturesHandler;
26};
27
29{
30 return {
31 {OH_ArkUI_PointerEvent_GetX(event), OH_ArkUI_PointerEvent_GetY(event)},
32 {OH_ArkUI_PointerEvent_GetDisplayX(event), OH_ArkUI_PointerEvent_GetDisplayY(event)}};
33}
34
35QOhosOptional<Qt::NativeGestureType> getQtGestureType(::InputEvent_AxisAction ohAxisActionType)
36{
37 switch (ohAxisActionType) {
38 case ::AXIS_ACTION_BEGIN:
39 return makeQOhosOptional(Qt::BeginNativeGesture);
40 case ::AXIS_ACTION_END :
41 case ::AXIS_ACTION_CANCEL:
42 return makeQOhosOptional(Qt::EndNativeGesture);
43 case ::AXIS_ACTION_UPDATE:
44 return makeQOhosOptional(Qt::ZoomNativeGesture);
45 }
47}
48
49QOhosAxisEventHandler::QOhosAxisEventHandler(
50 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
51 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
58 const auto totalScale =
60 ? 1.0
61 : event.value;
62 const auto scaleFactor =
68 }))
69{
70}
71
72void QOhosAxisEventHandler::handleUiAxisEvent(ArkUI_UIInputEvent *event)
73{
74 const auto now = std::chrono::steady_clock::now();
75
76 auto eventTimestamp = OH_ArkUI_UIInputEvent_GetEventTime(event);
77 QPointF localPosition;
78 QPointF screenPosition;
79 std::tie(localPosition, screenPosition) = getLocalAndGlobalPointsFromUiInputEvent(event);
80 double horizontalAxisValue = OH_ArkUI_AxisEvent_GetHorizontalAxisValue(event);
81 double verticalAxisValue = OH_ArkUI_AxisEvent_GetVerticalAxisValue(event);
82 auto eventToolType = OH_ArkUI_UIInputEvent_GetToolType(event);
83 auto eventAxisAction = OH_ArkUI_AxisEvent_GetAxisAction(event);
84 std::int32_t wheelScrollLines;
85 wheelScrollLines = OH_ArkUI_AxisEvent_GetScrollStep(event);
86
87 if (!qFuzzyIsNull(horizontalAxisValue) || !qFuzzyIsNull(verticalAxisValue)) {
88 QOhosWheelEvent ohosWheelEvent = {
89 .timestamp = eventTimestamp,
90 .localPoint = localPosition,
91 .globalPoint = screenPosition,
92 .horizontalValue = horizontalAxisValue,
93 .verticalValue = verticalAxisValue,
94 .eventToolType = eventToolType,
95 .axisAction = eventAxisAction,
96 .wheelScrollLines = wheelScrollLines,
97 .modifiers = readKeyModifiersFromOhosUiInputEvent(event),
98 };
99
100 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
101 m_imEventHandlerRef.visitInQtThreadIfAlive(
102 [weakSelf, ohosWheelEvent, qWindowRef = m_qWindowRef](auto &eventHandler) {
103 auto sharedSelf = weakSelf.lock();
104 if (!sharedSelf) {
105 return;
106 };
107 eventHandler.onMouseWheelEvent(ohosWheelEvent, qWindowRef.data());
108 });
109 }
110
111 const auto totalScale = OH_ArkUI_AxisEvent_GetPinchAxisScaleValue(event);
112
113 if (qFuzzyIsNull(horizontalAxisValue) && qFuzzyIsNull(verticalAxisValue) && !qFuzzyIsNull(totalScale)) {
114 const auto deviceType = QArkUi::getTouchDeviceType(event);
115 const auto gestureType = getQtGestureType(
116 static_cast<InputEvent_AxisAction>(eventAxisAction)).valueOr(Qt::ZoomNativeGesture);
117
118 QOhosNativeGestureEvent newEvent {
119 .timestamp = now,
120 .gestureTimestamp = eventTimestamp,
121 .value = totalScale,
122 .localPosition = localPosition,
123 .displayBasedPosition = screenPosition,
124 .gestureType = gestureType,
125 .deviceType = deviceType,
126 };
127
128 m_nativeGesturesHandler(newEvent);
129 }
130}
131
132}
133
135 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
136 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
137{
138 auto handler = std::make_shared<QOhosAxisEventHandler>(qWindowRef, imEventHandlerRef);
139 return [handler](::ArkUI_UIInputEvent *inputEvent) {
140 handler->handleUiAxisEvent(inputEvent);
141 };
142}
143
144QT_END_NAMESPACE
QOhosAxisEventHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef, QtOhos::QThreadSafeRef< QOhosInputMethodEventHandler > imEventHandlerRef)
Combined button and popup list for selecting options.
QOhosOptional< Qt::NativeGestureType > getQtGestureType(::InputEvent_AxisAction ohAxisActionType)
std::tuple< QPointF, QPointF > getLocalAndGlobalPointsFromUiInputEvent(ArkUI_UIInputEvent *event)
QOhosConsumer<::ArkUI_UIInputEvent * > makeQOhosNativeAxisEventHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef, QtOhos::QThreadSafeRef< QOhosInputMethodEventHandler > imEventHandlerRef)
QOhosOptional< void > makeEmptyQOhosOptional()