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
192
193
194
195
196
197
199 : QQuick3DNode(*(
new QQuick3DXrItemPrivate()), parent)
207 d->m_XrView->unregisterXrItem(
this);
213 QQuick3DNode::componentComplete();
215 auto findView = [
this]() -> QQuick3DXrView * {
216 QQuick3DNode *parent = parentNode();
218 if (
auto *xrView = qobject_cast<QQuick3DXrView*>(parent))
220 parent = parent->parentNode();
224 d->m_XrView = findView();
226 d->m_XrView->registerXrItem(
this);
228 qWarning(
"Could not find XrView for XrItem");
233
234
235
236
237
238
239
242 Q_D(
const QQuick3DXrItem);
243 return d->m_contentItem;
249 if (d->m_contentItem == newContentItem)
252 d->setContentItem(newContentItem);
253 emit contentItemChanged();
257
258
259
260
261
262
263
264
265
266
269 Q_D(
const QQuick3DXrItem);
270 return d->m_pixelsPerUnit;
276 if (qFuzzyCompare(d->m_pixelsPerUnit, newPixelsPerUnit))
279 d->m_pixelsPerUnit = newPixelsPerUnit;
281 if (d->m_manualPixelsPerUnit)
284 emit pixelsPerUnitChanged();
288
289
290
291
292
293
294
295
296
300 Q_D(
const QQuick3DXrItem);
301 return d->m_manualPixelsPerUnit;
307 if (d->m_manualPixelsPerUnit == newManualPixelsPerUnit)
309 d->m_manualPixelsPerUnit = newManualPixelsPerUnit;
311 emit manualPixelsPerUnitChanged();
315
316
317
318
319
320
321
322
326 Q_D(
const QQuick3DXrItem);
333 if ((d->m_width == newWidth) || d->m_automaticWidth)
335 d->m_width = newWidth;
342
343
344
345
346
347
348
349
353 Q_D(
const QQuick3DXrItem);
360 if ((d->m_height == newHeight) || d->m_automaticHeight)
362 d->m_height = newHeight;
363 emit heightChanged();
369
370
371
372
373
374
378 Q_D(
const QQuick3DXrItem);
385 if (d->m_color == newColor)
387 d->m_color = newColor;
393
394
395
396
397
398
399
403 Q_D(
const QQuick3DXrItem);
404 return d->m_automaticHeight;
410 if (d->m_automaticHeight == newAutomaticHeight) {
414 d->m_automaticHeight = newAutomaticHeight;
415 d->setAutomaticHeightConnection();
417 emit automaticHeightChanged();
421
422
423
424
425
426
427
431 Q_D(
const QQuick3DXrItem);
432 return d->m_automaticWidth;
438 if (d->m_automaticWidth == newAutomaticWidth)
441 d->m_automaticWidth = newAutomaticWidth;
442 d->setAutomaticWidthConnection();
444 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)