7#include <QtQuick3D/private/qquick3dnode_p.h>
8#include <QtGui/QMouseEvent>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
41 m_scrollTimer =
new QTimer(
this);
42 m_scrollTimer->setInterval(m_scrollTimerInterval);
43 connect(m_scrollTimer, SIGNAL(timeout()),
this, SLOT(generateWheelEvent()));
47
48
49
50
51
55 return m_rightMouseButton;
59
60
61
62
63
67 return m_leftMouseButton;
71
72
73
74
75
79 return m_middleMouseButton;
83
84
85
86
87
88
89
90
94 return m_scrollWheelX;
98
99
100
101
102
103
104
105
109 return m_scrollWheelY;
113
114
115
116
120 return m_scrollTimerInterval;
124
125
126
127
128
129
130
131
135 return m_scrollPixelDelta;
139
140
141
142
143
144
145
153
154
155
156
164
165
166
167
176 if (m_rightMouseButton == rightMouseButton)
179 m_rightMouseButton = rightMouseButton;
180 emit rightMouseButtonChanged(m_rightMouseButton);
181 if (m_rightMouseButton) {
183 generateEvent(QEvent::MouseButtonPress, Qt::RightButton);
186 generateEvent(QEvent::MouseButtonRelease, Qt::RightButton);
192 if (m_leftMouseButton == leftMouseButton)
195 m_leftMouseButton = leftMouseButton;
196 emit leftMouseButtonChanged(m_leftMouseButton);
197 if (m_leftMouseButton) {
199 generateEvent(QEvent::MouseButtonPress, Qt::LeftButton);
202 generateEvent(QEvent::MouseButtonRelease, Qt::LeftButton);
208 if (m_middleMouseButton == middleMouseButton)
211 m_middleMouseButton = middleMouseButton;
212 emit middleMouseButtonChanged(m_middleMouseButton);
213 if (m_middleMouseButton) {
215 generateEvent(QEvent::MouseButtonPress, Qt::MiddleButton);
218 generateEvent(QEvent::MouseButtonRelease, Qt::MiddleButton);
224 if (m_scrollWheelX == scrollWheelX)
227 m_scrollWheelX = scrollWheelX;
228 emit scrollWheelXChanged(m_scrollWheelX);
229 if ((m_scrollTimer->isActive()) && (m_scrollWheelX == 0)) {
230 m_scrollTimer->stop();
231 }
else if (!m_scrollTimer->isActive()) {
232 m_scrollTimer->start();
238 if (m_scrollWheelY == scrollWheelY)
241 m_scrollWheelY = scrollWheelY;
242 emit scrollWheelYChanged(m_scrollWheelY);
243 if ((m_scrollTimer->isActive()) && (m_scrollWheelY == 0)) {
244 m_scrollTimer->stop();
245 }
else if (!m_scrollTimer->isActive()) {
246 m_scrollTimer->start();
252 if (m_scrollTimerInterval == scrollTimerInterval)
255 m_scrollTimerInterval = scrollTimerInterval;
256 m_scrollTimer->setInterval(m_scrollTimerInterval);
258 emit scrollTimerIntervalChanged(m_scrollTimerInterval);
263 if (m_scrollPixelDelta == scrollPixelDelta)
266 m_scrollPixelDelta = scrollPixelDelta;
268 emit scrollPixelDeltaChanged(m_scrollPixelDelta);
273 if (m_source == source)
277 disconnect(m_source, &QQuick3DNode::sceneTransformChanged,
this, &QQuick3DXrVirtualMouse::moveEvent);
280 emit sourceChanged(m_source);
283 connect(m_source, &QQuick3DNode::sceneTransformChanged,
this, &QQuick3DXrVirtualMouse::moveEvent);
292 emit viewChanged(m_view);
297 if (m_enabled == enabled)
300 emit enabledChanged(m_enabled);
303 if (!m_enabled && (m_leftMouseButton || m_rightMouseButton || m_middleMouseButton)) {
304 Qt::MouseButton button = m_leftMouseButton ? Qt::LeftButton : m_rightMouseButton ? Qt::RightButton : Qt::MiddleButton;
305 m_leftMouseButton = m_rightMouseButton = m_middleMouseButton =
false;
306 generateEvent(QEvent::MouseButtonRelease, button);
312 generateEvent(QEvent::MouseMove, Qt::NoButton);
317 if (!m_view || !m_source || m_view->m_inDestructor || !m_enabled)
321 const QVector3D origin = m_source->scenePosition();
322 const QVector3D direction = m_source->forward();
327 if (m_scrollWheelX > 0) {
328 x = m_scrollPixelDelta * m_scrollWheelX * m_scrollWheelX;
329 }
else if (m_scrollWheelX < 0) {
330 x = -m_scrollPixelDelta * m_scrollWheelX * m_scrollWheelX;
333 if (m_scrollWheelY > 0) {
334 y = m_scrollPixelDelta * m_scrollWheelY * m_scrollWheelY;
335 }
else if (m_scrollWheelY < 0) {
336 y = -m_scrollPixelDelta * m_scrollWheelY * m_scrollWheelY;
339 QPoint pixelDelta = QPoint(x, y);
340 QPoint angleDelta = QPoint(x*8, y*8);
343 QWheelEvent *event =
new QWheelEvent(QPointF(), QPointF(), pixelDelta, angleDelta,
344 Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase,
false);
347 if (m_view->view3d())
348 m_view->view3d()->singlePointPick(event, origin, direction);
356 if (!m_view || !m_source || m_view->m_inDestructor || !m_enabled)
360 const QVector3D origin = m_source->scenePosition();
361 const QVector3D direction = m_source->forward();
364 Qt::MouseButtons buttons = Qt::NoButton;
365 if (m_leftMouseButton)
366 buttons |= Qt::LeftButton;
367 if (m_rightMouseButton)
368 buttons |= Qt::RightButton;
369 if (m_middleMouseButton)
370 buttons |= Qt::MiddleButton;
373 QMouseEvent *event =
new QMouseEvent(type, QPointF(), QPointF(), button, buttons, Qt::NoModifier);
376 if (m_view->view3d())
377 m_view->view3d()->singlePointPick(event, origin, direction);
bool middleMouseButton() const
\qmlproperty bool XrVirtualMouse::middleMouseButton
QQuick3DXrView * view() const
\qmlproperty XrView XrVirtualMouse::view
void setEnabled(bool enabled)
float scrollWheelY() const
\qmlproperty float XrVirtualMouse::scrollWheelY
void setScrollWheelY(float scrollWheelY)
void setScrollWheelX(float scrollWheelX)
void setView(QQuick3DXrView *view)
float scrollWheelX() const
\qmlproperty float XrVirtualMouse::scrollWheelX
int scrollPixelDelta() const
\qmlproperty float XrVirtualMouse::scrollPixelDelta
bool rightMouseButton() const
\qmlproperty bool XrVirtualMouse::rightMouseButton
void setScrollTimerInterval(int scrollTimerInterval)
QQuick3DNode * source() const
\qmlproperty Node XrVirtualMouse::source
void setScrollPixelDelta(int scrollPixelDelta)
bool leftMouseButton() const
\qmlproperty bool XrVirtualMouse::leftMouseButton
void setMiddleMouseButton(bool middleMouseButton)
bool enabled() const
\qmlproperty bool XrVirtualMouse::enabled
int scrollTimerInterval() const
\qmlproperty int XrVirtualMouse::scrollTimerInterval
void setSource(QQuick3DNode *source)
void setLeftMouseButton(bool leftMouseButton)
Combined button and popup list for selecting options.