6#include <QtCore/private/qohoslogger_p.h>
7#include <QtCore/qglobal.h>
8#include <QtCore/qpoint.h>
9#include <QtGui/qwindow.h>
10#include <arkui/native_gesture.h>
11#include <arkui/native_interface.h>
12#include <arkui/native_type.h>
13#include <arkui/ui_input_event.h>
15#include <qarkui/qembeddedwindownode.h>
16#include <qarkui/input.h>
17#include <qohosplatformintegration.h>
18#include <qohosutils.h>
19#include <qpa/qwindowsysteminterface.h>
20#include <render/qohosnativegestureshandler.h>
28 const auto localX = ::OH_ArkUI_PointerEvent_GetX(inputEvent);
29 const auto localY = ::OH_ArkUI_PointerEvent_GetY(inputEvent);
30 return { localX, localY };
36 ::OH_ArkUI_PointerEvent_GetDisplayX(inputEvent),
37 ::OH_ArkUI_PointerEvent_GetDisplayY(inputEvent));
41 ::ArkUI_GestureEventActionType ohEventActionType, Qt::NativeGestureType defaultGestureType)
43 switch (ohEventActionType) {
44 case ::GESTURE_EVENT_ACTION_ACCEPT:
45 return Qt::BeginNativeGesture;
46 case ::GESTURE_EVENT_ACTION_END:
47 return Qt::EndNativeGesture;
48 case ::GESTURE_EVENT_ACTION_CANCEL:
49 return Qt::EndNativeGesture;
50 case ::GESTURE_EVENT_ACTION_UPDATE:
51 return defaultGestureType;
53 return defaultGestureType;
56class QOhosArkUiNativeGesturesHandler
final :
public QEnableSharedFromThis<QOhosArkUiNativeGesturesHandler>
64 void handleRotationGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent);
65 void handlePinchGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent);
67 QOhosConsumer<
const QOhosNativeGestureEvent &> m_baseGesturesHandler;
68 qreal m_lastTotalScale{1.0};
69 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
73 QtOhos::QThreadSafeRef<QWindow> qWindowRef)
82 switch (nativeGestureInfo
.type) {
83 case QArkUi::NativeGestureInfo::GestureType::Pinch:
84 handlePinchGestureEvent(nativeGestureInfo.event);
86 case QArkUi::NativeGestureInfo::GestureType::Rotation:
87 handleRotationGestureEvent(nativeGestureInfo.event);
92void QOhosArkUiNativeGesturesHandler::handleRotationGestureEvent(
93 const ::ArkUI_GestureEvent *gestureEvent)
95 const auto timestamp =
std::chrono::steady_clock::now();
96 const auto actionType = ::OH_ArkUI_GestureEvent_GetActionType(gestureEvent);
97 const auto qtGestureType = getQtGestureType(actionType, Qt::RotateNativeGesture);
98 const auto delta = ::OH_ArkUI_RotationGesture_GetAngle(gestureEvent);
100 const auto *inputEvent = ::OH_ArkUI_GestureEvent_GetRawInputEvent(gestureEvent);
101 const auto gestureTimestamp = ::OH_ArkUI_UIInputEvent_GetEventTime(inputEvent);
102 const auto localPosition = getLocalPosition(inputEvent);
103 const auto displayBasedPosition = getDisplayBasedPosition(inputEvent);
104 const auto deviceType = QArkUi::getTouchDeviceType(inputEvent);
107 .timestamp = timestamp,
108 .gestureTimestamp = gestureTimestamp,
110 .localPosition = localPosition,
111 .displayBasedPosition = displayBasedPosition,
112 .gestureType = qtGestureType,
113 .deviceType = deviceType,
116 m_baseGesturesHandler(newEvent);
119void QOhosArkUiNativeGesturesHandler::handlePinchGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent)
121 const auto timestamp =
std::chrono::steady_clock::now();
122 const auto actionType = ::OH_ArkUI_GestureEvent_GetActionType(gestureEvent);
123 const auto qtGestureType = getQtGestureType(actionType, Qt::ZoomNativeGesture);
125 const auto totalScale = ::OH_ArkUI_PinchGesture_GetScale(gestureEvent);
126 const auto localX = ::OH_ArkUI_PinchGesture_GetCenterX(gestureEvent);
127 const auto localY = ::OH_ArkUI_PinchGesture_GetCenterY(gestureEvent);
128 const QPointF localPosition { localX, localY };
130 const auto *inputEvent = ::OH_ArkUI_GestureEvent_GetRawInputEvent(gestureEvent);
132 const auto toolType = ::OH_ArkUI_UIInputEvent_GetToolType(inputEvent);
133 if (toolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE || toolType == UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD)
136 const auto gestureTimestamp = ::OH_ArkUI_UIInputEvent_GetEventTime(inputEvent);
137 const auto displayBasedPosition = getDisplayBasedPosition(inputEvent);
138 const auto deviceType = QArkUi::getTouchDeviceType(inputEvent);
140 const auto scaleFactor =
141 qtGestureType == Qt::BeginNativeGesture
143 : totalScale / m_lastTotalScale;
144 m_lastTotalScale = totalScale;
147 .timestamp = timestamp,
148 .gestureTimestamp = gestureTimestamp,
149 .value = scaleFactor,
150 .localPosition = localPosition,
151 .displayBasedPosition = displayBasedPosition,
152 .gestureType = qtGestureType,
153 .deviceType = deviceType,
156 m_baseGesturesHandler(newEvent);
162 QtOhos::QThreadSafeRef<QWindow> qWindowRef)
164 return [gesturesHandler = QSharedPointer<QOhosArkUiNativeGesturesHandler>::create(qWindowRef)](
165 const QArkUi::NativeGestureInfo &nativeGestureInfo) {
166 gesturesHandler->handleNativeGestureEvent(nativeGestureInfo);
QOhosArkUiNativeGesturesHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef)
void handleNativeGestureEvent(const QArkUi::NativeGestureInfo &nativeGestureInfo)
Combined button and popup list for selecting options.
Qt::NativeGestureType getQtGestureType(::ArkUI_GestureEventActionType ohEventActionType, Qt::NativeGestureType defaultGestureType)
QPointF getLocalPosition(const ::ArkUI_UIInputEvent *inputEvent)
QPointF getDisplayBasedPosition(const ::ArkUI_UIInputEvent *inputEvent)
QOhosConsumer< const QArkUi::NativeGestureInfo & > makeQOhosArkUiNativeGesturesHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef)