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>
27 ::ArkUI_GestureEventActionType ohEventActionType, Qt::NativeGestureType defaultGestureType)
29 switch (ohEventActionType) {
30 case ::GESTURE_EVENT_ACTION_ACCEPT:
31 return Qt::BeginNativeGesture;
32 case ::GESTURE_EVENT_ACTION_END:
33 return Qt::EndNativeGesture;
34 case ::GESTURE_EVENT_ACTION_CANCEL:
35 return Qt::EndNativeGesture;
36 case ::GESTURE_EVENT_ACTION_UPDATE:
37 return defaultGestureType;
39 return defaultGestureType;
42class QOhosArkUiNativeGesturesHandler
final :
public QEnableSharedFromThis<QOhosArkUiNativeGesturesHandler>
50 void handleRotationGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent);
51 void handlePinchGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent);
53 QOhosConsumer<
const QOhosNativeGestureEvent &> m_baseGesturesHandler;
54 qreal m_lastTotalScale{1.0};
55 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
59 QtOhos::QThreadSafeRef<QWindow> qWindowRef)
68 switch (nativeGestureInfo
.type) {
69 case QArkUi::NativeGestureInfo::GestureType::Pinch:
70 handlePinchGestureEvent(nativeGestureInfo.event);
72 case QArkUi::NativeGestureInfo::GestureType::Rotation:
73 handleRotationGestureEvent(nativeGestureInfo.event);
78void QOhosArkUiNativeGesturesHandler::handleRotationGestureEvent(
79 const ::ArkUI_GestureEvent *gestureEvent)
81 const auto timestamp =
std::chrono::steady_clock::now();
82 const auto actionType = ::OH_ArkUI_GestureEvent_GetActionType(gestureEvent);
83 const auto qtGestureType = getQtGestureType(actionType, Qt::RotateNativeGesture);
84 const auto delta = ::OH_ArkUI_RotationGesture_GetAngle(gestureEvent);
86 const auto *inputEvent = ::OH_ArkUI_GestureEvent_GetRawInputEvent(gestureEvent);
87 const auto toolType = ::OH_ArkUI_UIInputEvent_GetToolType(inputEvent);
88 if (toolType != UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD)
91 const auto gestureTimestamp = ::OH_ArkUI_UIInputEvent_GetEventTime(inputEvent);
92 const auto localPosition = QArkUi::getPointerEventLocalPosition(inputEvent);
93 const auto globalPosition = QArkUi::getPointerEventGlobalPosition(inputEvent);
94 const auto deviceType = QArkUi::getPointingDeviceType(inputEvent);
97 .timestamp = timestamp,
98 .gestureTimestamp = gestureTimestamp,
100 .localPosition = localPosition,
101 .globalPosition = globalPosition,
102 .gestureType = qtGestureType,
103 .deviceType = deviceType,
106 m_baseGesturesHandler(newEvent);
109void QOhosArkUiNativeGesturesHandler::handlePinchGestureEvent(
const ::ArkUI_GestureEvent *gestureEvent)
111 const auto timestamp =
std::chrono::steady_clock::now();
112 const auto actionType = ::OH_ArkUI_GestureEvent_GetActionType(gestureEvent);
113 const auto qtGestureType = getQtGestureType(actionType, Qt::ZoomNativeGesture);
115 const auto totalScale = ::OH_ArkUI_PinchGesture_GetScale(gestureEvent);
116 const auto *inputEvent = ::OH_ArkUI_GestureEvent_GetRawInputEvent(gestureEvent);
118 const QPointF localPosition = QArkUi::getPointerEventLocalPosition(inputEvent);
119 const auto toolType = ::OH_ArkUI_UIInputEvent_GetToolType(inputEvent);
120 if (toolType != UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD)
123 const auto gestureTimestamp = ::OH_ArkUI_UIInputEvent_GetEventTime(inputEvent);
124 const auto globalPosition = QArkUi::getPointerEventGlobalPosition(inputEvent);
125 const auto deviceType = QArkUi::getPointingDeviceType(inputEvent);
127 const auto scaleFactor =
128 qtGestureType == Qt::BeginNativeGesture
130 : totalScale / m_lastTotalScale;
131 m_lastTotalScale = totalScale;
134 .timestamp = timestamp,
135 .gestureTimestamp = gestureTimestamp,
136 .value = scaleFactor,
137 .localPosition = localPosition,
138 .globalPosition = globalPosition,
139 .gestureType = qtGestureType,
140 .deviceType = deviceType,
143 m_baseGesturesHandler(newEvent);
149 QtOhos::QThreadSafeRef<QWindow> qWindowRef)
151 return [gesturesHandler = QSharedPointer<QOhosArkUiNativeGesturesHandler>::create(qWindowRef)](
152 const QArkUi::NativeGestureInfo &nativeGestureInfo) {
153 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)
QOhosConsumer< const QArkUi::NativeGestureInfo & > makeQOhosArkUiNativeGesturesHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef)