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
qohosdragaction.cpp
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#include <QtCore/private/qohoscommon_p.h>
5#include <QtCore/private/qohoslogger_p.h>
6#include <qarkui/qarkuiutils.h>
7#include <qarkui/qohosdragaction.h>
8#include <qohospixelmapconversions.h>
9#include <qohosutils.h>
10#include <utility>
11
13
14namespace QArkUi {
15
24
25void DragAction::setPointerId(std::int32_t pointerId)
26{
27 QArkUi::callArkUiOrFailOnErrorResult(
28 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetPointerId),
29 m_dragAction.get(), pointerId);
30}
31
32void DragAction::setTouchPoint(float touchX, float touchY)
33{
34 QArkUi::callArkUiOrFailOnErrorResult(
35 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetTouchPointX),
36 m_dragAction.get(), touchX);
37 QArkUi::callArkUiOrFailOnErrorResult(
38 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetTouchPointY),
39 m_dragAction.get(), touchY);
40}
41
42void DragAction::setPixelMaps(std::vector<std::shared_ptr<::OH_PixelmapNative>> pixelMaps)
43{
44 m_pixelMaps = std::move(pixelMaps);
45 m_pixelMapsPointers.resize(m_pixelMaps.size() + 1);
46
47 for (std::size_t i = 0; i < m_pixelMaps.size(); ++i)
48 m_pixelMapsPointers[i] = m_pixelMaps[i].get();
49 m_pixelMapsPointers[m_pixelMaps.size()] = nullptr;
50
51 QArkUi::callArkUiOrFailOnErrorResult(
52 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetPixelMaps),
53 m_dragAction.get(), m_pixelMapsPointers.data(), m_pixelMaps.size());
54}
55
57{
58 m_udmfData = QtOhos::moveToSharedPtr(std::move(udmfData));
59
60 QArkUi::callArkUiOrFailOnErrorResult(
61 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetData),
62 m_dragAction.get(), m_udmfData->nativePtr());
63}
64
66 std::function<void(::ArkUI_DragAndDropInfo *)> statusListener)
67{
69
70 auto sharedStatusListener = QtOhos::moveToSharedPtr(std::move(statusListener));
71
72 m_statusListenerRegistrationHandle = QtOhos::makeDestroyNotifier(
73 [sharedStatusListener, weakDragAction = QtOhos::makeWeakPtr(m_dragAction)]() {
74 auto dragAction = weakDragAction.lock();
75 if (dragAction) {
76 QArkUi::callArkUi(
77 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_UnregisterStatusListener),
78 dragAction.get());
79 }
80 });
81
82 QArkUi::callArkUiOrFailOnErrorResult(
83 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_RegisterStatusListener),
84 m_dragAction.get(), sharedStatusListener.get(),
85 [](::ArkUI_DragAndDropInfo *dragAndDropInfo, void *statusListenerVoidPtr) {
86 auto *statusListener = static_cast<std::function<void(::ArkUI_DragAndDropInfo *)> *>(statusListenerVoidPtr);
87 (*statusListener)(dragAndDropInfo);
88 });
89}
90
92{
93 m_statusListenerRegistrationHandle.reset();
94}
95
96void DragAction::setDragPreviewOption(ArkUI_DragPreviewOption &option)
97{
98 QArkUi::callArkUiOrFailOnErrorResult(
99 Q_OHOS_NAMED_FUNC(::OH_ArkUI_DragAction_SetDragPreviewOption),
100 m_dragAction.get(), &option);
101}
102
104{
105 return m_dragAction.get();
106}
107
108}
109
110QT_END_NAMESPACE
void setTouchPoint(float x, float y)
void setPixelMaps(std::vector< std::shared_ptr<::OH_PixelmapNative > > pixelMaps)
::ArkUI_DragAction * nativePtr()
void setData(QOhosUdmfData udmfData)
void setStatusListener(std::function< void(::ArkUI_DragAndDropInfo *)> statusListener)
void setDragPreviewOption(ArkUI_DragPreviewOption &option)
void setPointerId(std::int32_t pointerId)
DragAction(::ArkUI_NodeHandle node)
Combined button and popup list for selecting options.