6#include <QtQuick3D/private/qquick3dnode_p_p.h>
7#include <QtQuick/private/qquickrectangle_p.h>
36 q->setContentItem(
nullptr);
55 auto dataProp =
data();
75 return (diagonal > 0) ? std::sqrt((pxWidth * pxWidth) + (pxHeight * pxHeight)) / diagonal : 1.0;
99 q->setPixelsPerUnit(ppu);
100 newScale = 1.0 / ppu;
147 d->m_XrView->unregisterXrItem(
this);
158 if (
auto *xrView = qobject_cast<QQuick3DXrView*>(
parent))
164 d->m_XrView = findView();
166 d->m_XrView->registerXrItem(
this);
168 qWarning(
"Could not find XrView for XrItem");
183 return d->m_contentItem;
189 if (
d->m_contentItem == newContentItem)
192 d->setContentItem(newContentItem);
210 return d->m_pixelsPerUnit;
219 d->m_pixelsPerUnit = newPixelsPerUnit;
221 if (
d->m_manualPixelsPerUnit)
241 return d->m_manualPixelsPerUnit;
247 if (
d->m_manualPixelsPerUnit == newManualPixelsPerUnit)
249 d->m_manualPixelsPerUnit = newManualPixelsPerUnit;
270 if (
d->m_width == newWidth)
272 d->m_width = newWidth;
294 if (
d->m_height == newHeight)
296 d->m_height = newHeight;
312 QPointF point = {mappedPos.
x(), -mappedPos.y()};
314 constexpr qreal sideMargin = 20;
315 constexpr qreal cancelDepth = 50;
316 constexpr qreal hoverHeight = 10;
318 constexpr qreal releaseHeight = 2;
319 constexpr qreal smallDistance = 0.5;
320 constexpr qreal longDistance = 5;
321 constexpr int releaseTime = 500;
322 constexpr qreal releaseHeightSquared = releaseHeight * releaseHeight;
323 constexpr qreal smallDistanceSquared = smallDistance * smallDistance;
324 constexpr qreal longDistanceSquared = longDistance * longDistance;
326 const float z = mappedPos.z();
328 const bool wayOutside = point.
x() < -sideMargin || point.
x() >
width() + sideMargin
329 || point.
y() < -sideMargin || point.
y() >
height() + sideMargin ||
z < -cancelDepth;
330 const bool inside = point.
x() >= 0 && point.
x() <=
width() && point.
y() >= 0 && point.
y() <=
height() && !wayOutside;
332 const bool wasGrabbed = touchState->grabbed;
333 const bool wasPressed = touchState->pressed;
335 bool hover =
z > 0 &&
z < hoverHeight;
337 bool pressed =
false;
339 bool resetPrevious =
false;
350 QVector3D distFromPrev = mappedPos - touchState->previous;
351 qint64 msSincePrev =
now - touchState->timestamp;
353 const qreal prevZ = touchState->previous.z();
355 if (prevZ > 0 &&
z <= 0) {
358 resetPrevious =
true;
359 }
else if (msSincePrev > releaseTime ||
z > 0) {
360 resetPrevious =
true;
363 pressed =
z <= 0 && wasPressed;
366 const qreal hDistSquared = distFromPrev.x() * distFromPrev.x() + distFromPrev.y() * distFromPrev.y();
367 const qreal vDistSquared = distFromPrev.z() * distFromPrev.z();
368 const qreal distSquared = hDistSquared + vDistSquared;
370 if (distSquared < smallDistanceSquared) {
372 resetPrevious =
false;
373 pressed = wasPressed;
374 }
else if (hDistSquared > longDistanceSquared) {
376 resetPrevious =
true;
377 pressed = wasPressed;
378 }
else if (vDistSquared > releaseHeightSquared) {
380 resetPrevious =
true;
381 pressed = distFromPrev.z() < 0;
383 resetPrevious =
false;
384 pressed = wasPressed;
388 grab = (
z <= 0 && !wayOutside) || (hover && inside);
391 grab = hover && inside;
392 resetPrevious =
true;
396 float zOffset =
qMin(
z, 0.0);
399 touchState->grabbed =
true;
400 touchState->target =
this;
401 touchState->touchDistance =
z;
402 touchState->pressed = pressed;
403 touchState->cursorPos = point;
405 touchState->previous = mappedPos;
406 touchState->timestamp =
now;
408 view->setTouchpoint(
d->m_containerItem, point, touchState->pointId, pressed && inside);
413 touchState->grabbed =
false;
414 touchState->target =
nullptr;
415 view->setTouchpoint(
d->m_containerItem, point, touchState->pointId,
false);
438 if (
d->m_color == newColor)
440 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...
\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...
QPointer< QQuick3DXrView > m_XrView
QQuickRectangle * m_containerItem
void setContentItem(QQuickItem *newContentItem)
QMetaObject::Connection m_contentItemDestroyedConnection
QQuickItem * m_contentItem
bool m_manualPixelsPerUnit
void pixelsPerUnitChanged()
void setWidth(qreal newWidth)
void manualPixelsPerUnitChanged()
void setColor(const QColor &newColor)
void setManualPixelsPerUnit(bool newManualPixelsPerUnit)
void setPixelsPerUnit(qreal newPixelsPerUnit)
bool handleVirtualTouch(QQuick3DXrView *view, const QVector3D &pos, TouchState *touchState, QVector3D *offset)
void setHeight(qreal newHeight)
void contentItemChanged()
QQuick3DXrItem(QQuick3DNode *parent=nullptr)
\qmltype XrItem \inqmlmodule QtQuick3D.Xr \inherits Node
~QQuick3DXrItem() override
void setContentItem(QQuickItem *newContentItem)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
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
QT_BEGIN_NAMESPACE 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)