8#include <QtQuick3D/private/qquick3dnode_p_p.h>
9#include <QtQuick/private/qquickrectangle_p.h>
10#include <QtQuick/private/qquickitem_p.h>
18 Q_DECLARE_PUBLIC(QQuick3DXrItem)
76 if (m_automaticHeightConnection && ((m_contentItem ==
nullptr) || !m_automaticHeight)) {
77 QObject::disconnect(m_automaticHeightConnection);
78 m_automaticHeightConnection = {};
81 m_automaticHeightConnection = QObject::connect(m_contentItem, &QQuickItem::heightChanged, q, [
this, q](){
82 qreal newHeight = m_contentItem->height()/m_pixelsPerUnit;
83 if (m_height != newHeight) {
85 emit q->heightChanged();
95 if (m_automaticWidthConnection && ((m_contentItem ==
nullptr) || !m_automaticHeight)) {
96 QObject::disconnect(m_automaticWidthConnection);
97 m_automaticWidthConnection = {};
101 m_automaticWidthConnection = QObject::connect(m_contentItem, &QQuickItem::widthChanged, q, [
this, q](){
102 qreal newWidth = m_contentItem->width()/m_pixelsPerUnit;
103 if (m_width != newWidth) {
105 emit q->widthChanged();
129 return (diagonal > 0) ? std::sqrt((pxWidth * pxWidth) + (pxHeight * pxHeight)) / diagonal : 1.0;
134 if (!componentComplete)
138 m_containerItem->setColor(m_color);
140 if (Q_UNLIKELY(m_manualPixelsPerUnit && m_pixelsPerUnit < 0)) {
141 qWarning() <<
"XrItem invalid pixelPerUnit" << m_pixelsPerUnit;
146 newScale = 1.0 / m_pixelsPerUnit;
149 qreal diagonal = std::sqrt((m_width * m_width) + (m_height * m_height));
150 qreal ppu = calculatePPU(m_contentItem->width(), m_contentItem->height(), diagonal);
153 q->setPixelsPerUnit(ppu);
154 newScale = 1.0 / ppu;
156 QSizeF newSize(m_width / newScale, m_height / newScale);
157 m_containerItem->setSize(newSize);
158 m_containerItem->setScale(newScale);
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
193 : QQuick3DNode(*(
new QQuick3DXrItemPrivate()), parent)
201 d->m_XrView->unregisterXrItem(
this);
207 QQuick3DNode::componentComplete();
209 auto findView = [
this]() -> QQuick3DXrView * {
210 QQuick3DNode *parent = parentNode();
212 if (
auto *xrView = qobject_cast<QQuick3DXrView*>(parent))
214 parent = parent->parentNode();
218 d->m_XrView = findView();
220 d->m_XrView->registerXrItem(
this);
222 qWarning(
"Could not find XrView for XrItem");
227
228
229
230
231
232
233
236 Q_D(
const QQuick3DXrItem);
237 return d->m_contentItem;
243 if (d->m_contentItem == newContentItem)
246 d->setContentItem(newContentItem);
247 emit contentItemChanged();
251
252
253
254
255
256
257
258
259
260
263 Q_D(
const QQuick3DXrItem);
264 return d->m_pixelsPerUnit;
270 if (qFuzzyCompare(d->m_pixelsPerUnit, newPixelsPerUnit))
273 d->m_pixelsPerUnit = newPixelsPerUnit;
275 if (d->m_manualPixelsPerUnit)
278 emit pixelsPerUnitChanged();
282
283
284
285
286
287
288
289
290
294 Q_D(
const QQuick3DXrItem);
295 return d->m_manualPixelsPerUnit;
301 if (d->m_manualPixelsPerUnit == newManualPixelsPerUnit)
303 d->m_manualPixelsPerUnit = newManualPixelsPerUnit;
305 emit manualPixelsPerUnitChanged();
309
310
311
312
313
317 Q_D(
const QQuick3DXrItem);
324 if ((d->m_width == newWidth) || d->m_automaticWidth)
326 d->m_width = newWidth;
333
334
335
336
337
341 Q_D(
const QQuick3DXrItem);
348 if ((d->m_height == newHeight) || d->m_automaticHeight)
350 d->m_height = newHeight;
351 emit heightChanged();
357
358
359
360
361
362
366 Q_D(
const QQuick3DXrItem);
373 if (d->m_color == newColor)
375 d->m_color = newColor;
381
382
383
384
385
386
387
391 Q_D(
const QQuick3DXrItem);
392 return d->m_automaticHeight;
398 if (d->m_automaticHeight == newAutomaticHeight) {
402 d->m_automaticHeight = newAutomaticHeight;
403 d->setAutomaticHeightConnection();
405 emit automaticHeightChanged();
409
410
411
412
413
414
415
419 Q_D(
const QQuick3DXrItem);
420 return d->m_automaticWidth;
426 if (d->m_automaticWidth == newAutomaticWidth)
429 d->m_automaticWidth = newAutomaticWidth;
430 d->setAutomaticWidthConnection();
432 emit automaticWidthChanged();
QQuickItem * m_contentItem
QPointer< QQuick3DXrView > m_XrView
QQuickRectangle * m_containerItem
QMetaObject::Connection m_automaticHeightConnection
QMetaObject::Connection m_contentItemDestroyedConnection
void setAutomaticHeightConnection()
void setAutomaticWidthConnection()
QMetaObject::Connection m_automaticWidthConnection
bool m_manualPixelsPerUnit
bool manualPixelsPerUnit() const
\qmlproperty bool XrItem::manualPixelsPerUnit
void setAutomaticWidth(bool newAutomaticHeight)
void setWidth(qreal newWidth)
qreal width() const
\qmlproperty real XrItem::width
void setColor(const QColor &newColor)
void setManualPixelsPerUnit(bool newManualPixelsPerUnit)
void setPixelsPerUnit(qreal newPixelsPerUnit)
QColor color() const
\qmlproperty color XrItem::color
qreal height() const
\qmlproperty real XrItem::height
bool automaticHeight() const
\qmlproperty bool XrItem::automaticHeight
bool automaticWidth() const
\qmlproperty bool XrItem::automaticWidth
QQuickItem * contentItem() const
\qmlproperty Item XrItem::contentItem
void setHeight(qreal newHeight)
~QQuick3DXrItem() override
qreal pixelsPerUnit() const
\qmlproperty real XrItem::pixelsPerUnit
void setAutomaticHeight(bool newAutomaticHeight)
void setContentItem(QQuickItem *newContentItem)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Combined button and popup list for selecting options.
static qreal calculatePPU(qreal pxWidth, qreal pxHeight, qreal diagonal)