1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
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 "qmousedevice.h" |
5 | #include "qmousedevice_p.h" |
6 | |
7 | #include <Qt3DInput/qmouseevent.h> |
8 | #include <Qt3DCore/qentity.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | namespace Qt3DInput { |
13 | |
14 | /*! \internal */ |
15 | QMouseDevicePrivate::QMouseDevicePrivate() |
16 | : QAbstractPhysicalDevicePrivate() |
17 | , m_sensitivity(0.1f) |
18 | , m_updateContinuously(false) |
19 | { |
20 | } |
21 | |
22 | /*! |
23 | \qmltype MouseDevice |
24 | \instantiates Qt3DInput::QMouseDevice |
25 | \inqmlmodule Qt3D.Input |
26 | \since 5.5 |
27 | \brief Delegates mouse events to the attached MouseHandler objects. |
28 | |
29 | A MouseDevice delegates mouse events from physical mouse device to |
30 | MouseHandler objects. The sensitivity of the mouse can be controlled |
31 | with the \l MouseDevice::sensitivity property, which specifies the rate |
32 | in which the logical mouse coordinates change in response to physical |
33 | movement of the mouse. |
34 | |
35 | \sa MouseHandler |
36 | */ |
37 | |
38 | /*! |
39 | \class Qt3DInput::QMouseDevice |
40 | \inmodule Qt3DInput |
41 | \since 5.5 |
42 | \brief Delegates mouse events to the attached MouseHandler objects. |
43 | |
44 | A QMouseDevice delegates mouse events from physical mouse device to |
45 | QMouseHandler objects. The sensitivity of the mouse can be controlled |
46 | with the \l QMouseDevice::sensitivity property, which specifies the rate |
47 | in which the logical mouse coordinates change in response to physical |
48 | movement of the mouse. |
49 | |
50 | \sa QMouseHandler |
51 | */ |
52 | |
53 | /*! |
54 | \enum QMouseDevice::Axis |
55 | |
56 | The mouse axis. |
57 | |
58 | \value X |
59 | \value Y |
60 | \value WheelX |
61 | \value WheelY |
62 | |
63 | \sa Qt3DInput::QAnalogAxisInput::setAxis |
64 | */ |
65 | |
66 | /*! |
67 | \qmlproperty real MouseDevice::sensitivity |
68 | |
69 | Holds the current sensitivity of the mouse device. |
70 | Default is 0.1. |
71 | */ |
72 | |
73 | /*! |
74 | \property Qt3DInput::QMouseDevice::updateAxesContinuously |
75 | |
76 | If \c true, axes will be updated anytime they change regardless of whether |
77 | any mouse button is being pressed. Otherwise, axes are updated only when |
78 | one of the mouse buttons is being pressed. |
79 | |
80 | The default value is \c false. |
81 | \since 5.15 |
82 | */ |
83 | |
84 | /*! |
85 | \qmlproperty bool MouseDevice::updateAxesContinuously |
86 | |
87 | If \c true, axes will be updated anytime they change regardless of whether |
88 | any mouse button is being pressed. Otherwise, axes are updated only when |
89 | one of the mouse buttons is being pressed. |
90 | |
91 | The default value is \c false. |
92 | \since 5.15 |
93 | */ |
94 | |
95 | /*! |
96 | Constructs a new QMouseDevice instance with parent \a parent. |
97 | */ |
98 | QMouseDevice::QMouseDevice(QNode *parent) |
99 | : QAbstractPhysicalDevice(*new QMouseDevicePrivate, parent) |
100 | { |
101 | } |
102 | |
103 | /*! \internal */ |
104 | QMouseDevice::~QMouseDevice() |
105 | { |
106 | } |
107 | |
108 | /*! |
109 | \return the axis count. |
110 | |
111 | \note Currently always returns 4. |
112 | */ |
113 | int QMouseDevice::axisCount() const |
114 | { |
115 | return 4; |
116 | } |
117 | |
118 | /*! |
119 | \return the button count. |
120 | |
121 | \note Currently always returns 3. |
122 | */ |
123 | int QMouseDevice::buttonCount() const |
124 | { |
125 | return 3; |
126 | } |
127 | |
128 | /*! |
129 | \return the names of the axis. |
130 | |
131 | \note Currently always returns StringList["X", "Y"] |
132 | */ |
133 | QStringList QMouseDevice::axisNames() const |
134 | { |
135 | return QStringList() |
136 | << QStringLiteral("X" ) |
137 | << QStringLiteral("Y" ) |
138 | << QStringLiteral("WheelX" ) |
139 | << QStringLiteral("WheelY" ); |
140 | } |
141 | |
142 | /*! |
143 | \return the names of the buttons. |
144 | |
145 | \note Currently always returns StringList["Left", "Right", "Center"] |
146 | */ |
147 | QStringList QMouseDevice::buttonNames() const |
148 | { |
149 | return QStringList() |
150 | << QStringLiteral("Left" ) |
151 | << QStringLiteral("Right" ) |
152 | << QStringLiteral("Center" ); |
153 | } |
154 | |
155 | /*! |
156 | Convert axis \a name to axis identifier. |
157 | */ |
158 | int QMouseDevice::axisIdentifier(const QString &name) const |
159 | { |
160 | if (name == QLatin1String("X" )) |
161 | return X; |
162 | else if (name == QLatin1String("Y" )) |
163 | return Y; |
164 | else if (name == QLatin1String("WheelX" )) |
165 | return WheelX; |
166 | else if (name == QLatin1String("WheelY" )) |
167 | return WheelY; |
168 | return -1; |
169 | } |
170 | |
171 | /*! |
172 | Returns the button identifier that corresponds with |
173 | the specified \a name. The possible return values are |
174 | documented in \l {Qt3DInput::}{QMouseEvent::Buttons}. |
175 | */ |
176 | int QMouseDevice::buttonIdentifier(const QString &name) const |
177 | { |
178 | if (name == QLatin1String("Left" )) |
179 | return Qt3DInput::QMouseEvent::LeftButton; |
180 | if (name == QLatin1String("Right" )) |
181 | return Qt3DInput::QMouseEvent::RightButton; |
182 | if (name == QLatin1String("Center" )) |
183 | return Qt3DInput::QMouseEvent::MiddleButton; |
184 | return -1; |
185 | } |
186 | |
187 | /*! |
188 | \property Qt3DInput::QMouseDevice::sensitivity |
189 | |
190 | Holds the sensitivity of the mouse device. |
191 | The default is 0.1. |
192 | */ |
193 | float QMouseDevice::sensitivity() const |
194 | { |
195 | Q_D(const QMouseDevice); |
196 | return d->m_sensitivity; |
197 | } |
198 | |
199 | bool QMouseDevice::updateAxesContinuously() const |
200 | { |
201 | Q_D(const QMouseDevice); |
202 | return d->m_updateContinuously; |
203 | } |
204 | |
205 | void QMouseDevice::setSensitivity(float value) |
206 | { |
207 | Q_D(QMouseDevice); |
208 | if (qFuzzyCompare(p1: value, p2: d->m_sensitivity)) |
209 | return; |
210 | |
211 | d->m_sensitivity = value; |
212 | emit sensitivityChanged(value); |
213 | } |
214 | |
215 | void QMouseDevice::setUpdateAxesContinuously(bool updateAxesContinuously) |
216 | { |
217 | Q_D(QMouseDevice); |
218 | if (d->m_updateContinuously == updateAxesContinuously) |
219 | return; |
220 | |
221 | d->m_updateContinuously = updateAxesContinuously; |
222 | emit updateAxesContinuouslyChanged(updateAxesContinuously); |
223 | } |
224 | |
225 | } // namespace Qt3DInput |
226 | |
227 | QT_END_NAMESPACE |
228 | |
229 | #include "moc_qmousedevice.cpp" |
230 | |