6#include <QtQuick3D/private/qquick3dnode_p_p.h>
7#include <QtQuick/private/qquickrectangle_p.h>
36 q->setContentItem(
nullptr);
51 auto dataProp =
data();
71 return (diagonal > 0) ? std::sqrt((pxWidth * pxWidth) + (pxHeight * pxHeight)) / diagonal : 1.0;
95 q->setPixelsPerUnit(ppu);
143 d->m_XrView->unregisterXrItem(
this);
154 if (
auto *xrView = qobject_cast<QOpenXRView*>(
parent))
160 d->m_XrView = findView();
162 d->m_XrView->registerXrItem(
this);
164 qWarning(
"Could not find XrView for XrItem");
179 return d->m_contentItem;
185 if (
d->m_contentItem == newContentItem)
188 d->setContentItem(newContentItem);
206 return d->m_pixelsPerUnit;
215 d->m_pixelsPerUnit = newPixelsPerUnit;
217 if (
d->m_manualPixelsPerUnit)
237 return d->m_manualPixelsPerUnit;
243 if (
d->m_manualPixelsPerUnit == newManualPixelsPerUnit)
245 d->m_manualPixelsPerUnit = newManualPixelsPerUnit;
266 if (
d->m_width == newWidth)
268 d->m_width = newWidth;
290 if (
d->m_height == newHeight)
292 d->m_height = newHeight;
308 QPointF point = {mappedPos.
x(), -mappedPos.y()};
310 constexpr qreal sideMargin = 20;
311 constexpr qreal cancelDepth = 50;
312 constexpr qreal hoverHeight = 10;
314 constexpr qreal releaseHeight = 2;
315 constexpr qreal smallDistance = 0.5;
316 constexpr qreal longDistance = 5;
317 constexpr int releaseTime = 500;
318 constexpr qreal releaseHeightSquared = releaseHeight * releaseHeight;
319 constexpr qreal smallDistanceSquared = smallDistance * smallDistance;
320 constexpr qreal longDistanceSquared = longDistance * longDistance;
322 const float z = mappedPos.z();
324 const bool wayOutside = point.
x() < -sideMargin || point.
x() >
width() + sideMargin
325 || point.
y() < -sideMargin || point.
y() >
height() + sideMargin ||
z < -cancelDepth;
326 const bool inside = point.
x() >= 0 && point.
x() <=
width() && point.
y() >= 0 && point.
y() <=
height() && !wayOutside;
328 const bool wasGrabbed = touchState->grabbed;
329 const bool wasPressed = touchState->pressed;
331 bool hover =
z > 0 &&
z < hoverHeight;
333 bool pressed =
false;
335 bool resetPrevious =
false;
346 QVector3D distFromPrev = mappedPos - touchState->previous;
347 qint64 msSincePrev =
now - touchState->timestamp;
349 const qreal prevZ = touchState->previous.z();
351 if (prevZ > 0 &&
z <= 0) {
354 resetPrevious =
true;
355 }
else if (msSincePrev > releaseTime ||
z > 0) {
356 resetPrevious =
true;
359 pressed =
z <= 0 && wasPressed;
362 const qreal hDistSquared = distFromPrev.x() * distFromPrev.x() + distFromPrev.y() * distFromPrev.y();
363 const qreal vDistSquared = distFromPrev.z() * distFromPrev.z();
364 const qreal distSquared = hDistSquared + vDistSquared;
366 if (distSquared < smallDistanceSquared) {
368 resetPrevious =
false;
369 pressed = wasPressed;
370 }
else if (hDistSquared > longDistanceSquared) {
372 resetPrevious =
true;
373 pressed = wasPressed;
374 }
else if (vDistSquared > releaseHeightSquared) {
376 resetPrevious =
true;
377 pressed = distFromPrev.z() < 0;
379 resetPrevious =
false;
380 pressed = wasPressed;
384 grab = (
z <= 0 && !wayOutside) || (hover && inside);
387 grab = hover && inside;
388 resetPrevious =
true;
392 float zOffset =
qMin(
z, 0.0);
395 touchState->grabbed =
true;
396 touchState->target =
this;
397 touchState->touchDistance =
z;
398 touchState->pressed = pressed;
399 touchState->cursorPos = point;
401 touchState->previous = mappedPos;
402 touchState->timestamp =
now;
404 view->setTouchpoint(
d->m_containerItem, point, touchState->pointId, pressed && inside);
409 touchState->grabbed =
false;
410 touchState->target =
nullptr;
411 view->setTouchpoint(
d->m_containerItem, point, touchState->pointId,
false);
434 if (
d->m_color == newColor)
436 d->m_color = newColor;
The QColor class provides colors based on RGB, HSV or CMYK values.
static qint64 currentMSecsSinceEpoch() noexcept
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void setParent(QObject *parent)
Makes the object a child of parent.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
QPointer< QOpenXRView > m_XrView
QMetaObject::Connection m_contentItemDestroyedConnection
bool m_manualPixelsPerUnit
void setContentItem(QQuickItem *newContentItem)
QQuickRectangle * m_containerItem
QQuickItem * m_contentItem
void manualPixelsPerUnitChanged()
void setContentItem(QQuickItem *newContentItem)
void setWidth(qreal newWidth)
void pixelsPerUnitChanged()
void setManualPixelsPerUnit(bool newManualPixelsPerUnit)
QOpenXRItem(QQuick3DNode *parent=nullptr)
\qmltype XrItem \inqmlmodule QtQuick3D.Xr \inherits Node
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void contentItemChanged()
void setColor(const QColor &newColor)
bool handleVirtualTouch(QOpenXRView *view, const QVector3D &pos, TouchState *touchState, QVector3D *offset)
void setHeight(qreal newHeight)
void setPixelsPerUnit(qreal newPixelsPerUnit)
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Q_INVOKABLE QVector3D mapPositionFromScene(const QVector3D &scenePosition) const
\qmlmethod vector3d QtQuick3D::Node::mapPositionFromScene(vector3d scenePosition)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQuick3DNode * parentNode() const
QQuaternion sceneRotation
QQmlListProperty< QObject > data()
QQuick3DObject * parent
\qmlproperty Object3D QtQuick3D::Object3D::parent This property holds the parent of the Object3D in a...
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setSize(const QSizeF &size)
void setParentItem(QQuickItem *parent)
qreal width
This property holds the width of this item.
qreal height
This property holds the height of this item.
void setTransformOrigin(TransformOrigin)
void setColor(const QColor &)
The QVector3D class represents a vector or vertex in 3D space.
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
constexpr const T & qMin(const T &a, const T &b)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLenum GLuint GLintptr offset
GLdouble GLdouble GLdouble GLdouble q
static qreal calculatePPU(qreal pxWidth, qreal pxHeight, qreal diagonal)