1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DXRACTIONMAPPER_H
5#define QQUICK3DXRACTIONMAPPER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QObject>
19#include <QQmlEngine>
20#include <QQuick3DObject>
21#include <QMultiHash>
22
23QT_BEGIN_NAMESPACE
24
25class QQuick3DXrController;
26class QQuick3DXrInputAction;
27class QQuick3DXrActionMapper;
28
29class QQuick3DXrInputAction : public QObject, public QQmlParserStatus
30{
31 Q_OBJECT
32 Q_INTERFACES(QQmlParserStatus)
33 QML_NAMED_ELEMENT(XrInputAction)
34 QML_ADDED_IN_VERSION(6, 8)
35
36 Q_PROPERTY(float value READ value NOTIFY valueChanged FINAL)
37 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged FINAL)
38 Q_PROPERTY(QString actionName READ actionName WRITE setActionName NOTIFY actionNameChanged FINAL)
39 Q_PROPERTY(QList<Action> actionId READ actionId WRITE setActionId NOTIFY actionIdChanged FINAL)
40
41 Q_PROPERTY(Hand hand READ hand WRITE setHand NOTIFY handChanged FINAL)
42
43public:
44
45 // Same values as XrController and XrHandModel enums
46 enum Hand : quint8 {
47 LeftHand = 0,
48 RightHand,
49 Unknown,
50 };
51 Q_ENUM(Hand)
52
53 enum Action : qint16 {
54 CustomAction = -1,
55 Button1Pressed,
56 Button1Touched,
57 Button2Pressed,
58 Button2Touched,
59 ButtonMenuPressed,
60 ButtonMenuTouched,
61 ButtonSystemPressed,
62 ButtonSystemTouched,
63 SqueezeValue,
64 SqueezeForce,
65 SqueezePressed,
66 TriggerValue,
67 TriggerPressed,
68 TriggerTouched,
69 ThumbstickX,
70 ThumbstickY,
71 ThumbstickPressed,
72 ThumbstickTouched,
73 ThumbrestTouched,
74 TrackpadX,
75 TrackpadY,
76 TrackpadForce,
77 TrackpadTouched,
78 TrackpadPressed,
79 IndexFingerPinch,
80 MiddleFingerPinch,
81 RingFingerPinch,
82 LittleFingerPinch,
83 HandTrackingMenuPress,
84 NumHandActions,
85 NumActions
86 };
87 Q_ENUM(Action)
88
89 explicit QQuick3DXrInputAction(QObject *parent = nullptr);
90 ~QQuick3DXrInputAction() override;
91 float value() const;
92 void setValue(float newValue);
93 bool pressed() const;
94 void setPressed(bool newPressed);
95
96 QString actionName() const;
97 void setActionName(const QString &newActionName);
98
99 QList<Action> actionId() const;
100 void setActionId(const QList<Action> &newActionId);
101
102 void classBegin() override;
103 void componentComplete() override;
104
105 Hand hand() const;
106 void setHand(Hand newHand);
107
108signals:
109 void valueChanged();
110 void pressedChanged();
111 void triggered();
112
113 void actionNameChanged();
114 void actionIdChanged();
115
116 void handChanged();
117
118private:
119 QString m_actionName;
120 float m_value = 0;
121 bool m_pressed = false;
122 bool m_componentComplete = false;
123 Hand m_hand;
124
125 QList<Action> m_actionIds;
126};
127
128class QQuick3DXrActionMapper : public QObject
129{
130 Q_OBJECT
131public:
132 static QQuick3DXrActionMapper *instance();
133
134 static void handleInput(QQuick3DXrInputAction::Action id, QQuick3DXrInputAction::Hand hand, const char *shortName, float value);
135 static void registerAction(QQuick3DXrInputAction *action);
136 static void removeAction(QQuick3DXrInputAction *action);
137
138private:
139 explicit QQuick3DXrActionMapper(QObject *parent = nullptr);
140
141 QMultiHash<quint32, QQuick3DXrInputAction *> m_actions;
142 QMultiHash<QString, QQuick3DXrInputAction *> m_customActions;
143};
144
145QT_END_NAMESPACE
146
147#endif // QQUICK3DXRACTIONMAPPER_H
148

source code of qtquick3d/src/xr/quick3dxr/qquick3dxractionmapper_p.h